通过mysqldumpslow来分析日志
时间:2022-03-15 08:34
通过mysqldumpslow来分析日志。
将mysql加入到全局变量中!!!
sudo vim /etc/profile
# 添加Mysql
export PATH=$PATH:/usr/local/mysql/bin
source /etc/profile
前提是这个日志文件需要设置可访问权限。
最好还是弄一个软连接到/usr/bin
下面。
sudo ln -s /usr/local/mysql/bin/mysqldumpslow /usr/bin/mysqldumpslow
列出了最慢的三条日志信息。
sudo mysqldumpslow -t 3 /tmp/mysql-slow.log
Reading mysql slow query log from /tmp/mysql-slow.log
Count: 1 Time=0.33s (0s) Lock=0.00s (0s) Rows=23.0 (23), root[root]@localhost
SELECT *,
`TABLE_SCHEMA` AS `Db`,
`TABLE_NAME` AS `Name`,
`TABLE_TYPE` AS `TABLE_TYPE`,
`ENGINE` AS `Engine`,
`ENGINE` AS `Type`,
`VERSION` AS `Version`,
`ROW_FORMAT` AS `Row_format`,
`TABLE_ROWS` AS `Rows`,
`AVG_ROW_LENGTH` AS `Avg_row_length`,
`DATA_LENGTH` AS `Data_length`,
`MAX_DATA_LENGTH` AS `Max_data_length`,
`INDEX_LENGTH` AS `Index_length`,
`DATA_FREE` AS `Data_free`,
`AUTO_INCREMENT` AS `Auto_increment`,
`CREATE_TIME` AS `Create_time`,
`UPDATE_TIME` AS `Update_time`,
`CHECK_TIME` AS `Check_time`,
`TABLE_COLLATION` AS `Collation`,
`CHECKSUM` AS `Checksum`,
`CREATE_OPTIONS` AS `Create_options`,
`TABLE_COMMENT` AS `Comment`
FROM `information_schema`.`TABLES` t
WHERE `TABLE_SCHEMA` COLLATE utf8_bin
IN ('S')
ORDER BY Name ASC LIMIT N OFFSET N
Count: 1 Time=0.05s (0s) Lock=0.00s (0s) Rows=1.0 (1), root[root]@localhost
SELECT COUNT(*) FROM `sakila`.`film_actor`
Count: 1 Time=0.04s (0s) Lock=0.00s (0s) Rows=1.0 (1), root[root]@localhost
SELECT COUNT(*) FROM `sakila`.`rental`