mysql 慢查询日志记录
环境:
操作系统: CentOS 6.5
数据库: mysql-5.1.73
1、查看当前慢查询配置
mysql> show variables like 'slow%'; +---------------------+---------------------------------+ | Variable_name | Value | +---------------------+---------------------------------+ | slow_launch_time | 2 | | slow_query_log | OFF | | slow_query_log_file | /var/run/mysqld/mysqld-slow.log | +---------------------+---------------------------------+ 3 rows in set (0.00 sec)
2、通过修改 my.cnf 开启监听慢查询
vi /etc/my.cnf 添加配置 [mysqld] log-slow-queries = /var/lib/mysql/sql_slow.log #单位秒 long_query_time = 1 log-queries-not-using-indexes
3、重新启动 mysql
service mysqld restart
4、查看配置是否生效
mysql> show variables like 'slow%'; +---------------------+-----------------------------+ | Variable_name | Value | +---------------------+-----------------------------+ | slow_launch_time | 2 | | slow_query_log | ON | | slow_query_log_file | /var/lib/mysql/sql_slow.log | +---------------------+-----------------------------+ 3 rows in set (0.00 sec)
5、测试日志是否记录
执行SQL:
select sleep(3);
查看记录日志 tail -300f sql_slow.log
Query_time :查询使用时间
Lock_time:锁时间
Rows_sent:返回记录条数
Rows_examined:总共记录条数
Tcp port: 3306 Unix socket: /var/lib/mysql/mysql.sock Time Id Command Argument # Time: 151019 15:39:04 # User@Host: [root] @ localhost [] # Query_time: 3.001364 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0 SET timestamp=1445240344; select sleep(3);
一只站在树上的鸟儿,从来不会害怕树枝会断裂,因为它相信的不是树枝,而是它自己的翅膀。与其每天担心未来,不如努力做好现在。