開啟查詢慢查詢日誌引數
Step 1: Set your log file in /etc/my.cnf
vi /etc/my.cnf
In the [mysqld] section specify the general log file name:
log=/var/log/mysqld.general.log
Step 2: Create the file and make sure it is owned by the system user mysql
touch /var/log/mysqld.general.log chown mysql.mysql /var/log/mysqld.general.lo
Step 3: Enable the general log in the MySQL client. Connect to the MySQL server using the MySQL client and execute this query.
SET GLOBAL general_log = 'ON';
Step 4: Restart mysqld and watch the logs
/etc/init.d/mysqld restart
To watch the logs use the tail command.
tail -f /var/log/mysqld.general.log
A sample entry in my general query log looks like:
[root@localhost ~]# [root@localhost ~]# tail -f /var/log/mysqld.general.log 091012 13:52:53 2 Query SELECT `profile`.* FROM `profile` WHERE (user_id = 1) LIMIT 1 2 Query SELECT `u`.`user_id`, `u`.`email`, `u`.`status`, `u`.`mode`, `u`.`hash`, `u`.`created`, `u`.`alt_email`, `u`.`host_created`, `u`.`ip_created`, `u`.`user_timezone`, `p`.*, `r`.`name` AS `primaryRoleName`, `urp`.`email` AS `reportsToEmail`, `b`.`branch_name` FROM `user` AS `u` LEFT JOIN `profile` AS `p` ON p.user_id = u.user_id LEFT JOIN `role` AS `r` ON r.role_id = p.primary_role LEFT JOIN `user` AS `urp` ON urp.user_id = p.reports_to LEFT JOIN `branch` AS `b` ON b.branch_id = p.branch_id WHERE (u.user_id = '1') 2 Query SELECT `profile`.* FROM `profile` WHERE (user_id = 1) LIMIT 1 2 Query SELECT `privilege`.* FROM `privilege` WHERE ( name = 'view service invoices\"') LIMIT 1 2 Query SELECT * FROM organization_details 2 Quit
Enabling the slow query log
Similarly, you can enable the slow log queries. MySQL reports how much time it took to execute a query.
Step 1: Enable slow log query, set a slow log query log file, and set the log_query_time in my.cnf.
Edit the MySQL configuration file.
vi /etc/my.cnf
In the [mysqld] section add/edit the following variables
long_query_time = 0 slow_query_log = 1 slow_query_log_file=/var/log/mysqld.slow.query.log
We are setting the log_query_time variable to 0. Any MySQL query taking more than 0 seconds will be logged.
Step 2: Create the file /var/log/mysqld.slow.query.log and set the system user mysql as the owner.
touch /var/log/mysqld.slow.query.log chown mysql.mysql /var/log/mysqld.slow.query.log
Step 3: Restart MySQL server
/etc/init.d/mysqld restart
Step 4: Watch the slow query log using the tail command.
tail -f /var/log/mysqld.slow.query.log
A sample entry on my server looks like this:
[root@localhost ~]# tail -f /var/log/mysqld.slow.query.log SET timestamp=1255345490; SELECT `privilege`.* FROM `privilege` WHERE ( name = 'view service invoices\"') LIMIT 1; # User@Host: biz_1[biz_1] @ localhost [] # Query_time: 0.000273 Lock_time: 0.000104 Rows_sent: 1 Rows_examined: 1 SET timestamp=1255345490; SELECT * FROM organization_details; # User@Host: biz_1[biz_1] @ localhost [] # Query_time: 0.000048 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 1 SET timestamp=1255345490; # administrator command: Quit;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/23490154/viewspace-1063770/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 慢查詢日誌開啟分析
- MYSQL開啟慢查詢日誌實施MySql
- mysql開啟檢視慢查詢日誌MySql
- 如何在MySQL中開啟慢查詢日誌?MySql
- MySQL:慢查詢日誌MySql
- 使用慢查詢日誌
- mysql慢查詢日誌MySql
- 關於MySQL 通用查詢日誌和慢查詢日誌分析MySql
- Mysql 啟動慢查詢日誌 (不用重啟)MySql
- 慢查詢日誌的管理
- MySQL 5.1.6以上版本動態開啟慢查詢日誌MySql
- 【MySQL】慢查詢日誌不列印MySql
- mysqlsla 分析mysql慢查詢日誌MySql
- MySQL開啟慢查詢MySql
- MySQL 5.1.6以上版本動態開啟慢查詢日誌薦MySql
- PHP慢指令碼日誌和Mysql的慢查詢日誌PHP指令碼MySql
- Redis慢查詢日誌學習功能Redis
- mysql之 slow log 慢查詢日誌MySql
- MySQL Slow Query log(慢查詢日誌)MySql
- mysql慢查詢日誌分析工具使用MySql
- Mysql慢查詢日誌分析工具mysqlslaMySql
- 【MySql】 慢日誌查詢工具之mysqlslaMySql
- MySQL 慢查詢日誌——讓“慢”無所遁形MySql
- 如何啟用Hibernate慢查詢日誌? -Vlad Mihalcea
- 筆記 mongo查詢慢日誌,建立索引筆記Go索引
- MySQL慢查詢日誌相關設定MySql
- 【轉載】MySQL慢查詢日誌總結MySql
- mysql慢查詢和錯誤日誌分析MySql
- 線上安全清空慢查詢日誌slowlog
- 用命令過濾MySQL慢查詢日誌MySql
- Mysql慢查詢日誌檔案轉ExcelMySqlExcel
- MySQL優化 - 開啟MySQL慢查詢日誌及分析工具mysqldumpslowMySql優化
- Linux下mysql配置慢日誌查詢,把查詢慢的sql記錄下來LinuxMySql
- linux下開啟mysql慢查詢,分析查詢語句LinuxMySql
- mysql 查詢日誌MySql
- mysql查詢日誌MySql
- 對 MySQL 慢查詢日誌的簡單分析MySql
- mysql分析慢查詢日誌工具mysqlsla安裝MySql