博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
开启MySQL慢查询日志
阅读量:4985 次
发布时间:2019-06-12

本文共 2823 字,大约阅读时间需要 9 分钟。

1、修改my.cnf或my.ini

1)、linux-----------------------------------

/etc/my.cnf  文件

[mysqld]

long_query_time = 1

log-slow-queries XXXXXXXXX

 

2)、window--------------------------------

my.ini    文件      

[mysqld]

long_query_time = 1
log-slow-queries=C:\mysql_slow.log;
log-queries-not-using-indexes

 

2、service mysql restart

 

3、

方法二:用 mysql 客户端命令行修改,但重启之后会失效

mysql> show variables like 'lo%';
+---------------------------------+---------------------+
| Variable_name                   | Value               |
+---------------------------------+---------------------+
| local_infile                    | ON                  |
| lock_wait_timeout               | 31536000            |
| locked_in_memory                | OFF                 |
| log                             | OFF                 |
| log_bin                         | ON                  |
| log_bin_trust_function_creators | OFF                 |
| log_error                       | /disk/mysql/ |
| log_output                      | FILE                |
| log_queries_not_using_indexes   | OFF                 |
| log_slave_updates               | OFF                 |
| log_slow_queries                | OFF                 |
| log_warnings                    | 1                   |
| long_query_time                 | 10.000000           |
| low_priority_updates            | OFF                 |
| lower_case_file_system          | OFF                 |
| lower_case_table_names          | 0                   |
+---------------------------------+---------------------+
16 rows in set (0.00 sec)
mysql> set global long_query_time = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> set global log_slow_queries = on;
Query OK, 0 rows affected, 1 warning (0.31 sec)
mysql> set global log_queries_not_using_indexes = on;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'lo%';                    
+---------------------------------+---------------------+
| Variable_name                   | Value               |
+---------------------------------+---------------------+
| local_infile                    | ON                  |
| lock_wait_timeout               | 31536000            |
| locked_in_memory                | OFF                 |
| log                             | OFF                 |
| log_bin                         | ON                  |
| log_bin_trust_function_creators | OFF                 |
| log_error                       | /disk/mysql/ |
| log_output                      | FILE                |
| log_queries_not_using_indexes   | ON                  |
| log_slave_updates               | OFF                 |
| log_slow_queries                | ON                  |
| log_warnings                    | 1                   |
| long_query_time                 | 10.000000           |
| low_priority_updates            | OFF                 |
| lower_case_file_system          | OFF                 |
| lower_case_table_names          | 0                   |
+---------------------------------+---------------------+
16 rows in set (0.00 sec)
此处发现一个很奇怪的问题,long_query_time的更改似乎没有生效。
过了几分钟,再看,发现已经改过来了。
mysql> show variables like 'lo%';
+---------------------------------+---------------------+
| Variable_name                   | Value               |
+---------------------------------+---------------------+
| local_infile                    | ON                  |
| lock_wait_timeout               | 31536000            |
| locked_in_memory                | OFF                 |
| log                             | OFF                 |
| log_bin                         | ON                  |
| log_bin_trust_function_creators | OFF                 |
| log_error                       | /disk/mysql/ |
| log_output                      | FILE                |
| log_queries_not_using_indexes   | ON                  |
| log_slave_updates               | OFF                 |
| log_slow_queries                | ON                  |
| log_warnings                    | 1                   |
| long_query_time                 | 1.000000            |
| low_priority_updates            | OFF                 |
| lower_case_file_system          | OFF                 |
| lower_case_table_names          | 0                   |
+---------------------------------+---------------------+
16 rows in set (0.00 sec)

 

 

转载于:https://www.cnblogs.com/smallfa/p/4210040.html

你可能感兴趣的文章
传递参数ref与输出参数out
查看>>
java1.8对集合中对象的特有属性进行排序
查看>>
mysql搭建主从
查看>>
闲着就把这个翻译了。。。基本没什么水平- -
查看>>
自定义滚动条——控制文字的滚动
查看>>
Android 手工测试代码覆盖率增强版
查看>>
延伸正则表达式
查看>>
Spark报错:Failed to locate the winutils binary in the hadoop binary path
查看>>
结构体学习笔记9——结构体大小计算规则
查看>>
git删除远程仓库文件
查看>>
quartz定时任务时间设置
查看>>
PB与SQL SERVER连接
查看>>
使用Nexus搭建Maven私服
查看>>
css之display:inline-block与float区别(可以尝试用一下)
查看>>
ShopNc商城修改详情
查看>>
AngularJS 拦截器和应用例子(转)
查看>>
20180628
查看>>
CISCO 1841 升级ios
查看>>
iOS绘制虚线
查看>>
[CLR via C#]14. 字符、字符串和文本处理
查看>>