[root@gzmtest_25 ~]# su - mysql [mysql@gzmtest_25 ~]$ mysql.local Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 126000553 Server version: 5.5.27-log Sourcedistribution Copyright (c) 2000, 2011, Oracle and/or itsaffiliates. All rights reserved. Oracle is a registered trademark of OracleCorporation and/or its affiliates. Other names may be trademarksof their respective owners. Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
可以看到监控日志是否开启的选项(off是关闭)on是开启
root@localhost:(none)>show global variables like 'general_log%'; +------------------+---------------------------+ | Variable_name | Value | +------------------+---------------------------+ | general_log | OFF | | general_log_file |/data/mysql/log/mysql.log | +------------------+---------------------------+ 2 rows in set (0.01 sec) root@localhost:(none)> root@localhost:(none)>set global general_log=on; Query OK, 0 rows affected (0.02 sec)
查看当前系统日志大小
root@localhost:(none)>system du -h /data/mysql/log/mysql.log 1.7M /data/mysql/log/mysql.log
开启日志成功
接下来就可以直接进入shell中根据sql特征来查看我们sql会话信息
[root@gzmtest_25 ~]# grep "forupdate" /data/mysql/log/mysql.log
126002192 Query select pk fromT_GANTT_CHART where pk =47 for update
//忽略其他的数据了。
执行看当前会话的信息
[root@gzmtest_25~]# grep 126002192 /data/mysql/log/mysql.log
126002192Connect test@11.104.32.115 on test
126002192Query /* mysql-connector-java-5.1.6 (Revision: ${svn.Revision} ) */SHOW VARIABLES WHERE Variable_name ='language' ORVariable_name = 'net_write_timeout' OR Variable_name = 'interactive_timeout' ORVariable_name = 'wait_timeout' OR Variable_name = 'character_set_client' ORVariable_name = 'character_set_connection' OR Variable_name = 'character_set'OR Variable_name = 'character_set_server' OR Variable_name = 'tx_isolation' ORVariable_name = 'transaction_isolation' OR Variable_name ='character_set_results' OR Variable_name = 'timezone' OR Variable_name ='time_zone' OR Variable_name = 'system_time_zone' OR Variable_name ='lower_case_table_names' OR Variable_name = 'max_allowed_packet' ORVariable_name = 'net_buffer_length' OR Variable_name = 'sql_mode' ORVariable_name = 'query_cache_type' OR Variable_name = 'query_cache_size' ORVariable_name = 'init_connect'
126002192Query SHOW COLLATION
126002192Query SET character_set_results = NULL
126002192Query SET autocommit=1
126002192Query SETsql_mode='STRICT_TRANS_TABLES'
141017 11:20:49 126002192 Query SETautocommit=0
126002192Query commit
126002192Query SET autocommit=1
126002192Query select *....sql 太长忽略
126002192Query SELECTCOUNT(last_password_change) FROM T_PF_USER
126002192Query SELECT COUNT(password_salt) FROMT_PF_USER
126002192Query SELECT COUNT(comment_of_attendee)FROM T_PLUGIN_CALENDAR_EVENT_ATTENDEE
126002192Query SELECT COUNT(ext_subscription)FROM T_PLUGIN_CALENDAR
126002192Query SELECTCOUNT(ext_subscription_calendar_binary) FROM T_PLUGIN_CALENDAR
126002192Query SELECTCOUNT(ext_subscription_hash) FROM T_PLUGIN_CALENDAR
126002192Query SELECTCOUNT(ext_subscription_url) FROM T_PLUGIN_CALENDAR
126002192Query SELECTCOUNT(ext_subscription_up