标签:mysql 日志
一、用mysqlbinlog查看row格式的事件
[root@192 3306]# mysqlbinlog -v -v mysql3306-bin.000009
[root@192 3306]# mysqlbinlog -v -v --base64-output=DECODE-ROWS mysql3306-bin.000009
二、日志的删除:
mysql> reset master; # 日志全部被清空
mysql> purge master logs to "mysql3306-bin.000007"; # 指定日志前的全部删除
mysql> purge master logs before "2016-05-05 13:49:00"; # 指定时间前的全部删除
mysql> show variables like "%expire_logs_days%";
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| expire_logs_days | 0 |
+------------------+-------+
1 row in set (0.00 sec)
mysql>
mysql> set sql_log_bin = 0; #禁止语句写入二进制日志
三、打开查询日志:
mysql> show variables like "%general%";
+------------------+-------------------------+
| Variable_name | Value |
+------------------+-------------------------+
| general_log | OFF |
| general_log_file | /data/3306/data/192.log |
+------------------+-------------------------+
2 rows in set (0.00 sec)
mysql>
mysql> set global general_log = on;
四、慢查询日志,这些都需要开启下,慢查询不记录,不使用索引的语句和管理语句:
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 | /data/3306/data/192-slow.log |
+---------------------------+------------------------------+
5 rows in set (0.00 sec)
mysql>
mysql> show variables like "%indexes%";
+----------------------------------------+-------+
| Variable_name | Value |
+----------------------------------------+-------+
| log_queries_not_using_indexes | OFF |
| log_throttle_queries_not_using_indexes | 0 |
+----------------------------------------+-------+
2 rows in set (0.00 sec)
mysql>
mysql> set global slow_query_log = 1 ;
mysql> set global slow_launch_time = 1 ;
mysql> set global long_query_time = 0.01 ;
mysql> show variables like "long%";
+-----------------+-----------+
| Variable_name | Value |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
1 row in set (0.00 sec)
mysql> show variables like "%output%";
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| innodb_status_output | OFF |
| innodb_status_output_locks | OFF |
| log_output | FILE |
+----------------------------+-------+
3 rows in set (0.00 sec)
mysql>
慢查询日志分析工具:
[root@192 data]# mysqldumpslow 192-slow.log
五、mysqlsla 这个工具很好,很有用
[root@192 3306]# mysqlsla /data/3306/data/192.log
错误日志 二进制日志 查询日志 慢查询日志
标签:mysql 日志
原文地址:http://wangqh.blog.51cto.com/5367393/1770524