我们有时候须要查看mysql的运行历史,比方我们做sql优化的时候,起码要知道运行的sql是什么。框架通常会帮我们拼装sql,所以在程序中不一定能够打印出sql,这个时候就须要mysql的general

log了。


查看设置mysql genneral log

show VARIABLES like '%general_log%';

set GLOBAL general_log = off;// on-打开; off-关闭

general_log ON
general_log_file /var/log/mysql/query.log

使用mysql general log

tail -f /path/to/log/query.log | grep yourtable
13518 Prepare SELECT count(*) AS `count` FROM `babysitter_tips` WHERE (tip_type = '1') AND (is_enable = 1) AND (is_tip = 2)
13518 Query DESCRIBE `babysitter_tips`
13518 Close stmt
13518 Prepare SELECT `babysitter_tips`.* FROM `babysitter_tips` WHERE (tip_type = '1') AND (is_enable = 1) AND (is_tip = 2) ORDER BY `created_time` desc LIMIT 5
13518 Reset stmt
13518 Close stmt
13518 Prepare SELECT count(*) AS `count` FROM `babysitter_tips` WHERE (tip_type = '1') AND (is_enable = 1) AND (is_tip = 2) AND (tip_id > 15440)
13518 Close stmt
13518 Prepare SELECT count(*) AS `count` FROM `babysitter_tips` WHERE (tip_type = '3') AND (is_enable = 1) AND (is_tip = 2)
13518 Query DESCRIBE `babysitter_tips`
13518 Close stmt
13518 Prepare SELECT `babysitter_tips`.* FROM `babysitter_tips` WHERE (tip_type = '3') AND (is_enable = 1) AND (is_tip = 2) ORDER BY `created_time` desc LIMIT 5
13518 Reset stmt
13518 Close stmt
13518 Prepare SELECT count(*) AS `count` FROM `babysitter_tips` WHERE (tip_type = '3') AND (is_enable = 1) AND (is_tip = 2) AND (tip_id > '')
13518 Close stmt
13518 Prepare SELECT count(*) AS `count` FROM `babysitter_tips` WHERE (tip_type = '2') AND (is_enable = 1) AND (is_tip = 2)
13518 Query DESCRIBE `babysitter_tips`
13518 Close stmt
13518 Prepare SELECT `babysitter_tips`.* FROM `babysitter_tips` WHERE (tip_type = '2') AND (is_enable = 1) AND (is_tip = 2) ORDER BY `created_time` desc LIMIT 5
13518 Reset stmt
13518 Close stmt

清理mysql general log

general log会比較大,所以默认市关闭的,所以最好须要的时候打开,随手关闭。假设发现query.log过大。能够手动删除。在general log打开的情况下,query.log文件相似于mysql表的lock情况,不同意改动和删除。关闭general log就能够操作了。

mysql general log 查看mysql 运行历史的更多相关文章

  1. mysql general log日志

    注:应一直出现http://www.cnblogs.com/hwaggLee/p/6030765.html文章中的问题 故mysql general log日志.查看具体是什么命令导致的. 打开 ge ...

  2. MySQL general log

    1:查看版本 SELECT VERSION(); 2:查看当前的日志保存方式 mysql> SHOW VARIABLES LIKE '%log_output%'; +-------------- ...

  3. git log 查看版本演变历史

    1.查看git操作历史 $ git log  #git 查看git操作历史 $ git log  --oneline #git 简洁的查看git变更记录 $ git log -n4  --onelin ...

  4. mysql general log开启

    #先查看当前状态 mysql> show variables like 'general%'; +------------------+----------------------------- ...

  5. How can I view currently running MySQL queries?( 查看正在运行的MySQL语句/脚本命令)

    show processlist;show processlist\G;SHOW FULL PROCESSLIST;SHOW FULL PROCESSLIST\G; REF:http://dev.my ...

  6. [转]【mysql监控】查看mysql库大小,表大小,索引大小

    本文转自:http://blog.sina.com.cn/s/blog_4c197d420101fbl9.html 查看所有库的大小 mysql> use information_schema; ...

  7. 【mysql】linux查看mysql配置文件my.conf

    mysql --help|grep 'my.cnf' /etc/my.cnf, /etc/mysql/my.cnf, /usr/local/etc/my.cnf, ~/.my.cnf 这些就是mysq ...

  8. CentOS 7下启动、关闭、重启、查看MySQL服务

    1.启动命令 [root@xufeng Desktop]# service mysqld startRedirecting to /bin/systemctl start mysqld.service ...

  9. Linux下查看Mysql数据库端口的方法

    mysql 默认的端口是 3306,但是如果在安装的时候,修改了mysql的默认端口的话,可以采用以下方式查看 第一种方法: 直接查看数据库的配置文件 在/etc/mysql/my.cnf(Linux ...

随机推荐

  1. GCC 内联汇编(GCC内嵌ARM汇编规则)

    转:http://smileleeboo.howbbs.com/posts/list/3127/81062.html 更多文档参见:http://pan.baidu.com/s/1eQ7nd8Q 有时 ...

  2. jquery缩写,显示隐藏

    $(".a").css("display")=="none" ?$(".a").css("display&qu ...

  3. metal的gpu query

    https://developer.apple.com/documentation/metal/mtlcommandbuffer/1639924-gpustarttime gpuStartTime 看 ...

  4. 一些数据 bandwidth之类

    33ms  2436x1125 full resolution write bandwidth  300MB/s memory bandwidth snapdragon 630 10GB/3   // ...

  5. screen space shadowmap unity

    unity用到了screen space shadow map 1.camera 在light pos 生成depth1 2.screen space depth2 3.根据depth1 depth2 ...

  6. 项目部署问题:xftp无法连接服务器、Nginx403 Forbidden解决、nginx反向代理解决前端跨域问题

    一.xftp无法连接服务器 在xftp中配置正确的ip,用户名和密码后,居然无法连接 解决方案:将协议里面的FTP换成SFTP,注意换成SFTP后端口就默认换成22,要还是原来的21就还是连不上的哈 ...

  7. http://www.ruanyifeng.com/blog/2013/07/gpg.html

    http://www.ruanyifeng.com/blog/2013/07/gpg.html

  8. C# http Post 方法

    摘自: http://geekswithblogs.net/rakker/archive/2006/04/21/76044.aspx Http Post in C# Searched out on t ...

  9. 使用 session_destroy() 销毁session文件时 报 Trying to destroy uninitialized session 错误解决办法

    在使用  sessio_destroy() 销毁session文件的时候,必须要先使用session_start()   来开启session 后才能删除session文件

  10. 如何在 CentOS 7 上安装 Percona Server

    在这篇文章中我们将了解关于 Percona 服务器,一个开源的MySQL,MariaDB的替代品.InnoDB的数据库引擎使得Percona 服务器非常有吸引力,如果你需要的高性能,高可靠性和高性价比 ...