我们有时候须要查看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. 5 Best Gantt Chart JIRA Plugins

    Andrew Stepanov/June 23, 2017/6 minutes Software developers enjoy using JIRA software for their proj ...

  2. win32 打印机api

    ? 4. API之打印函数 AbortDoc 取消一份文档的打印 AbortPrinter 删除与一台打印机关联在一起的缓冲文件 AddForm 为打印机的表单列表添加一个新表单 AddJob 用于获 ...

  3. android基础知识复习——RelativeLayout布局属性、背景、半透明设置(XML设置)

    转自:http://blog.csdn.net/fansongy/article/details/6817968 复习布局与XML,写了一个空的登录界面.XML的注释我写在当行的后面了.程序运行图: ...

  4. select标签中的选项分组

    select标签中的选项分组 <select name="showtimes"> <optgroup label="下午一点"> < ...

  5. dedecms入侵拿webshell之方法总结

    1.注入漏洞 存在注入地址:在域名下输入plus/digg_frame.php?action=good&id=1024%651024&mid=*/eval($_POST[x]);var ...

  6. DevExpress 小计 GridControl 隔行换行

    摘自: http://www.cnblogs.com/yuerdongni/archive/2012/09/08/2676753.html 1. 如何解决单击记录整行选中的问题 View->Op ...

  7. django中根据模型生成页面的脚手架app-groundwork

    相信做过Asp.net MVC的朋友对在此框架下,根据模型自动生成浏览,编辑,查看,删除的四个页面的脚手架功能记忆尤新,那么我们在用python中的django框架时,有没有此脚手架功能呢,很显然,默 ...

  8. C++ Primer笔记2_四种类型转换_异常机制

    1.类型转换 命名的强制类型转换: 有static_cast.dynamic_cast.const_cast.reinterpret_cast static_cast: 编译器隐式运行的不论什么类型转 ...

  9. nginx+lua+redis 处理APK包替换

    nginx + lua +redis 安装与使用入门: http://huoding.com/2012/08/31/156 nginx httpEchoModule : http://wiki.ngi ...

  10. iOS 判断NSString是否包含某个字符串

    主要是使用3个方法 rangeOfString    是否包含 hasPrefix      是否在前缀包含 hasSuffix           是否在末尾包含 如代码: //判断字符是否包含某字 ...