标签:十分 维护 gtid 日志文件 乱码 auto 系统设置 time 执行时间
MySQL 日志管理[root@localhost data] vim /etc/my.cnf #在mysqld里面添加
[mysqld]
log-error=/usr/local/mysql/data/mysql_error.log
[root@localhost ~]# systemctl restart mysqld.service #重启之后会生成这个文件
[root@localhost ~]# cd /usr/local/mysql/data/
[root@localhost data]# ls
mysql_error.log
mysql> show variables like ‘general%‘;
+------------------+-------------------------------------+
| Variable_name | Value |
+------------------+-------------------------------------+
| general_log | OFF |
| general_log_file | /usr/local/mysql/data/localhost.log |
+------------------+-------------------------------------+
2 rows in set (0.01 sec)
[root@localhost data] vim /etc/my.cnf
[mysqld]
general_log=ON
general_log_file=/usr/local/mysql/data/mysql_general.log
[root@localhost data] systemctl restart mysqld.service
mysql_general.log
mysql> show variables like ‘general%‘; #状态开启
+------------------+-----------------------------------------+
| Variable_name | Value |
+------------------+-----------------------------------------+
| general_log | ON |
| general_log_file | /usr/local/mysql/data/mysql_general.log |
+------------------+-----------------------------------------+
2 rows in set (0.01 sec)
mysql> show variables like ‘log_bin%‘; #默认是关闭状态
+---------------------------------+-------+
| Variable_name | Value |
+---------------------------------+-------+
| log_bin | OFF |
| log_bin_basename | |
| log_bin_index | |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
+---------------------------------+-------+
5 rows in set (0.00 sec)
[root@localhost data] vim /etc/my.cnf
[mysqld]
log_bin=mysql-bin
[root@localhost data] systemctl restart mysqld.service
[root@localhost data] ls
mysql-bin.000001
mysql-bin.index
[root@localhost data]# mysql -u root -p
mysql> show variables like ‘log_bin%‘;
+---------------------------------+---------------------------------------+
| Variable_name | Value |
+---------------------------------+---------------------------------------+
| log_bin | ON |
| log_bin_basename | /usr/local/mysql/data/mysql-bin |
| log_bin_index | /usr/local/mysql/data/mysql-bin.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
+---------------------------------+---------------------------------------+
5 rows in set (0.01 sec)
[root@localhost data] mysqlbinlog --no-defaults mysql-bin.000001 #关闭默认的utf8字符集
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#180628 16:56:21 server id 1 end_log_pos 123 CRC32 0x4ecddb44 Start: binlog v 4, server v 5.7.17-log created 180628 16:56:21 at startup
# Warning: this binlog is either in use or was not closed properly.
ROLLBACK/*!*/;
BINLOG ‘
taI0Ww8BAAAAdwAAAHsAAAABAAQANS43LjE3LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAC1ojRbEzgNAAgAEgAEBAQEEgAAXwAEGggAAAAICAgCAAAACgoKKioAEjQA
AUTbzU4=
‘/*!*/;
# at 123
#180628 16:56:21 server id 1 end_log_pos 154 CRC32 0x0b6126ac Previous-GTIDs
# [empty]
SET @@SESSION.GTID_NEXT= ‘AUTOMATIC‘ /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
mysql> show variables like ‘%slow%‘; #默认是关闭的
+---------------------------+------------------------------------------+
| Variable_name | Value |
+---------------------------+------------------------------------------+
| log_slow_admin_statements | OFF |
| log_slow_slave_statements | OFF |
| slow_launch_time | 2 |
| slow_query_log | OFF |
| slow_query_log_file | /usr/local/mysql/data/localhost-slow.log |
+---------------------------+------------------------------------------+
5 rows in set (0.00 sec)
mysql> set global slow_query_log=ON;
Query OK, 0 rows affected (0.01 sec)
mysql> show variables like ‘%slow%‘;
+---------------------------+------------------------------------------+
| Variable_name | Value |
+---------------------------+------------------------------------------+
| log_slow_admin_statements | OFF |
| log_slow_slave_statements | OFF |
| slow_launch_time | 2 |
| slow_query_log | ON #开启 |
| slow_query_log_file | /usr/local/mysql/data/localhost-slow.log |
+---------------------------+------------------------------------------+
5 rows in set (0.00 sec)
[root@localhost data] vim /etc/my.cnf
slow_query_log=ON #开启慢日志
slow_query_log_file=mysql_slow_query.log
long_query_time=5 #时间为5秒
mysql> show variables like ‘long_query_time‘;
+-----------------+----------+
| Variable_name | Value |
+-----------------+----------+
| long_query_time | 5.000000 |
+-----------------+----------+
1 row in set (0.00 sec)
mysql> set names utf8; #开启重启后失效
[root@localhost data] vim /etc/my.cnf
[client]
default-character-set=utf8
[mysql]
default-char[mysqld]
[mysqld]
character_set_server=utf8
标签:十分 维护 gtid 日志文件 乱码 auto 系统设置 time 执行时间
原文地址:http://blog.51cto.com/13645280/2134710