mysql5.7 慢查询配置 查看sql语句执行时间
2016-08-15 11:48
736 查看
windows 下mysql5.7 慢查询配置
查看慢配置查询的show variables like '%query%' ;
show variables like 'long_query_time' ; //可以显示当前慢查询时间 set long_query_time=1 ; //慢查询的时间默认为10秒 可以修改慢查询时间也可
mysql5.7 可以直接在配置文件my.ini 中写配置
log_slow_admin_statements = ON log_slow_slave_statements = ON slow_query_log = ON //开启慢查询 slow_query_log_file = E:\mysql-5.7.13-winx64\data\pc-PC-slow.log //设置路径 long_query_time =1 //设置慢查询时间 超过一秒的记录 /**end***/
重启
mysql service mysql restart
/etc/init.d/mysql restart
systemctl restart mysqld
以在my.ini种配置
慢查询日志文件的信息格式:
Time: 130905 14:15:59 时间是2013年9月5日 14:15:59(前面部分容易看错哦,乍看以为是时间戳)
User@Host: root[root] @ [183.239.28.174] 请求mysql服务器的客户端ip
Query_time: 0.735883 Lock_time: 0.000078 Rows_sent: 262 Rows_examined: 262 这里表示执行用时多少秒,0.735883秒,1秒等于1000毫秒 Lock_time 锁的时间
SET timestamp=1378361759; 执行sql的准确时间 时间戳
show tables from
test_db; 指明了当时执行的是这条语句
慢查询命令
set global slow_query_log=ON; 打开慢查询
set global slow_query_log=OFF; 关闭慢查询
set global slow_launch_time=5; 设置慢查询时间
show variables like “%slow%”; 查看配置
mysql 5.1.6版本起,slow_query_log 和 slow_launch_time 支持写文件或写数据库表两种方式,并且日志的开启,输出方式的修改,都可以在global级别动态修改。
只需简单通过set global slow_query_log=ON;即可开启慢查询,而不需要重启数据库!
/[b]********************************************************[/b]/
查看sql语句执行时间
Show variables like ‘profiling’; 查看sql语句 性能分析看profile是否开启 5.7的
mysql> show variables like ‘%profiling%’;
+————————+——-+
| Variable_name | Value |
+————————+——-+
| have_profiling | YES |
| profiling | ON |
| profiling_history_size | 15 |
+————————+——-+
set profiling=on; 开启profile
查看执行过的sql 的执行时间
show profiles;
mysql> show profiles;
+———-+————+——————————————————————————-+
| Query_ID | Duration | Query |
+———-+————+——————————————————————————-+
| 1 | 0.00081975 | explain select * from t_log_login where id=’46702e55f23911e49d5cac162d8aadd4’ |
| 2 | 0.00436950 | select * from t_log_login where id=’46702e55f23911e49d5cac162d8aadd4’ |
+———-+————+——————————————————————————-+
查询所花费的时间 query_id=1 的语句执行时间
select sum(duration) from information_schema.profiling where query_id=1; # Query ID = 1
查看 # Query ID = 1的执行时间
mysql> show profile for query 1;
相关文章推荐
- mysql sql语句执行时间查询
- PHP获取MySQL执行sql语句的查询时间
- PHP获取MySQL执行sql语句的查询时间方法
- 查看mysql sql 语句执行时间的两种方法
- MYSQL 配置查询日志[包含所有执行的SQL语句]
- PHP获取MySQL执行sql语句的查询时间
- mysql 如何查看sql语句执行时间和效率
- mysql查看sql语句执行时间
- mysql 如何查看sql语句执行时间和效率
- 执行sql查询,并查看语句执行花费时间
- 查看mysql连接数 sql语句执行时间
- mysql sql语句执行时间查询
- (转载)PHP怎么获取MySQL执行sql语句的查询时间
- MSSQL Server中通过查看SQL语句执行所用的时间
- [MSSQL]通过查看SQL语句执行所用的时间,来衡量SQL语句的性能
- MySQL 查看正在执行的sql语句的方法
- 查看SQL语句在SQL Server上的执行时间
- [转]如何在sql2005里简单查看sql语句的执行时间和IO读写
- oracle 中--怎么查看当前表空间在作什么操作?--查锁,死锁,当前执行时间长的Sql语句,没提交的事务,对象为哪些进程所用
- 查看SQL语句在SQL Server上的执行时间