mysql优化之全局查询日志

全局查询日志

1,配置启用全局查询日志

注意:测试环境检测sql操作情况,切忌在生产环境中开启此功能

1,命令设置:(当前session有效)
    //开启
    set global general_log = 1
    //定位table
    set global log_output = 'TABLE';

2,配置文件设置:(全局有效)
    mysql的配置文件my.cnf中
    #开启
    general_log = 1
    #记录日志文件路径
    general_log_file = /path/logfile
    #输出格式
    log_output = FILE

定位以及配置成功,当前session下操作的sql语句,将会记录在mysql库中general_log表,
可以用如下命令查看
select * from mysql.general_log;

mysql> select * from mysql.general_log;
+---------------------+---------------------------------+-----------+-----------+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| event_time          | user_host                       | thread_id | server_id | command_type | argument                                                                                                                                                                                                                                                                                                                                                                                                  |
+---------------------+---------------------------------+-----------+-----------+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 2018-01-16 21:27:49 | niushao[niushao] @ localhost [] |       358 |         1 | Query        | SELECT bloginfo_id,bloginfo_title,bloginfo_describe,bloginfo_img,from_unixtime(bloginfo_createtime,'%Y') AS year,from_unixtime(bloginfo_createtime,'%m-%d') AS date,from_unixtime(bloginfo_createtime,'%Y-%m-%d') AS bloginfo_createtime,bloginfo_like,bloginfo_hate,bloginfo_click FROM ns_bloginfo WHERE bloginfo_status = 1 AND class_id=10 ORDER BY bloginfo_oid,bloginfo_id DESC                     |
| 2018-01-16 21:27:55 | niushao[niushao] @ localhost [] |       358 |         1 | Query        | SELECT bloginfo_id,bloginfo_title,bloginfo_describe,bloginfo_img,from_unixtime(bloginfo_createtime,'%Y') AS year,from_unixtime(bloginfo_createtime,'%m-%d') AS date,from_unixtime(bloginfo_createtime,'%Y-%m-%d') AS bloginfo_createtime,bloginfo_like,bloginfo_hate,bloginfo_click FROM ns_bloginfo WHERE bloginfo_status = 1 and class_id in (10,11,12,13,14,15) ORDER BY bloginfo_oid,bloginfo_id DESC |
| 2018-01-16 21:27:58 | niushao[niushao] @ localhost [] |       358 |         1 | Query        | SHOW TABLES                                                                                                                                                                                                                                                                                                                                                                                               |
| 2018-01-16 21:28:03 | niushao[niushao] @ localhost [] |       358 |         1 | Query        | select * from ns_link                                                                                                                                                                                                                                                                                                                                                                                     |
| 2018-01-16 21:28:05 | niushao[niushao] @ localhost [] |       358 |         1 | Query        | SHOW TABLES                                                                                                                                                                                                                                                                                                                                                                                               |
| 2018-01-16 21:28:16 | niushao[niushao] @ localhost [] |       358 |         1 | Query        | select * from ns_homepage                                                                                                                                                                                                                                                                                                                                                                                 |
| 2018-01-16 21:28:23 | niushao[niushao] @ localhost [] |       358 |         1 | Query        | select * from ns_class                                                                                                                                                                                                                                                                                                                                                                                    |
| 2018-01-16 21:28:27 | niushao[niushao] @ localhost [] |       358 |         1 | Query        | select * from ns_class                                                                                                                                                                                                                                                                                                                                                                                    |
| 2018-01-16 21:28:34 | niushao[niushao] @ localhost [] |       358 |         1 | Query        | select * from ns_class                                                                                                                                                                                                                                                                                                                                                                                    |
| 2018-01-16 21:28:45 | niushao[niushao] @ localhost [] |       358 |         1 | Query        | select * from mysql.general_log                                                                                                                                                                                                                                                                                                                                                                           |
| 2018-01-16 21:28:48 | niushao[niushao] @ localhost [] |       358 |         1 | Query        | select * from mysql.general_log                                                                                                                                                                                                                                                                                                                                                                           |
| 2018-01-16 21:29:01 | niushao[niushao] @ localhost [] |       358 |         1 | Query        | select * from mysql.general_log                                                                                                                                                                                                                                                                                                                                                                           |
+---------------------+---------------------------------+-----------+-----------+--------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
12 rows in set (0.00 sec)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值