mysql查看sql语句执行历史记录的例子
2019/10/10/17:32:35 阅读:2265 来源:谷歌SEO算法 标签:
SEO博客
下面来为各位介绍一个mysql查看sql语句执行历史记录的例子,如果你希望跟踪你程序的执行性能我们就可以使用下面方法,有需要了解的朋友可进入看看.
mysql查看sql语句执行历史记录:
cat ~/.mysql_history
对于mysql版本5.1以后的版本,可以通过以下方式启动日志记录,能够记录下包括应用程序执行的sql语句.
- MariaDB[(none)]>SETGLOBALlog_output='TABLE';
- QueryOK,0rowsaffected(0.02sec)
- MariaDB[(none)]>SETGLOBALgeneral_log='ON';
- QueryOK,0rowsaffected(0.00sec)
- MariaDB[(none)]>showdatabases;
- +--------------------+
- |Database|
- +--------------------+
- |information_schema|
- |gfan_log|
- |gfan_pay|
- |gfanpg|
- |gfanrc|
- |mysql|
- |performance_schema|
- |ucenter|
- +--------------------+
- 8rowsinset(0.02sec)
- MariaDB[(none)]>usemysql
- Readingtableinformationforcompletionoftableandcolumnnames
- Youcanturnoffthisfeaturetogetaquickerstartupwith-A
- Databasechanged
- MariaDB[mysql]>showtables;
- +---------------------------+
- |Tables_in_mysql|
- +---------------------------+
- |columns_priv|
- |db|
- |event|
- |func|
- |general_log|
- |help_category|
- |help_keyword|
- |help_relation|
- |help_topic|
- |host|
- |ndb_binlog_index|
- |plugin|
- |proc|
- |procs_priv|
- |proxies_priv|
- |servers|
- |slow_log|
- |tables_priv|
- |time_zone|
- |time_zone_leap_second|
- |time_zone_name|
- |time_zone_transition|
- |time_zone_transition_type|
- |user|
- +---------------------------+
- 24rowsinset(0.00sec)
- MariaDB[mysql]>select*fromgeneral_loglimit10;
- +----------------------------+---------------------------+-----------+-----------+--------------+-------------------+
- |event_time|user_host|thread_id|server_id|command_type|argument|
- +----------------------------+---------------------------+-----------+-----------+--------------+-------------------+
- |2014-11-1214:29:49.810999|root[root]@localhost[]|1304|0|Query|showdatabases|
- |2014-11-1214:29:51.951747|root[root]@localhost[]|1304|0|Query|SELECTDATABASE()|
- |2014-11-1214:29:51.973180|root[root]@localhost[]|1304|0|InitDB|mysql|
- |2014-11-1214:29:51.975048|root[root]@localhost[]|1304|0|Query|showdatabases|
- |2014-11-1214:29:51.975689|root[root]@localhost[]|1304|0|Query|showtables|
- |2014-11-1214:29:51.976347|root[root]@localhost[]|1304|0|FieldList|columns_priv|--phpfensi.com
- |2014-11-1214:29:51.976800|root[root]@localhost[]|1304|0|FieldList|db|
- |2014-11-1214:29:51.977431|root[root]@localhost[]|1304|0|FieldList|event|
- |2014-11-1214:29:51.978052|root[root]@localhost[]|1304|0|FieldList|func|
- |2014-11-1214:29:51.978224|root[root]@localhost[]|1304|0|FieldList|general_log|
- +----------------------------+---------------------------+-----------+-----------+--------------+-------------------+
- 10rowsinset(0.01sec)
- MariaDB[mysql]>
- Ifyouwanttooutputtothelogfile:
- SETGLOBALlog_output=“FILE”;
- SETGLOBALgeneral_log_file=“/path/to/your/logfile.log”
- SETGLOBALgeneral_log=‘ON’;
- RestartMySQLtoapplythechangesifyouedittheconfig,e.g./etc/mysql/my.cnf
- Now,ifyou’dlikeyoucantail-f/var/log/mysql/mysql.log
热门评论