分析问题时,为了区别不同语句的执行效果,可以为每个语句添加注释,发送给MySQL服务器端执行。只要设置long_query_time=0, 就可以将稍微复杂或输出记录大于100行的语句记录到slow log,方便查看分析。
为sql语句添加注释的方法是:
/*Q1*/select * from tdb.Twords order by rand();
其中/*Q1*/就是注释内容,可以把Q1替换为你想要的内容。navicat默认就会发送注释内容到服务器端。如果使用mysql命令行客户端,默认是不发送注释的,需要加参数-c才行。
mysql -c -uroot -p'123456'
查看slow log内容:
# Time: 2019-04-01T22:32:02.232121-05:00
# User@Host: root[root] @ localhost [] Id: 49
# Query_time: 0.008009 Lock_time: 0.000133 Rows_sent: 10000 Rows_examined: 30000
SET timestamp=1554172322;
/*Q1*/ select * from tdb.Twords order by rand();
当然,也可以这样写:
SET TIMESTAMP=1553775619/*!*/;
把注释放在最后面。