Copy # 以下操作管理员才有权限
mysql> set global slow_query_log = ON;
Query OK, 0 rows affected (0.04 sec)
# 设置查询“超时”时间(这里为了方便日志打印,将超过0.001s的都作为慢查询)
mysql> set GLOBAL long_query_time = 0.001;
Query OK, 0 rows affected (0.00 sec)
Copy # 慢日志相关配置
slow_query_log = ON
long_query_time = 0.001
slow_query_log_file = /usr/local/mysql/data/slow.log
# 记录没有使用索引的sql,默认为OFF
log_queries_not_using_indexes = ON
# mysql5.6.5版本开始新增一个参数用来表示每分钟允许记录到慢查询日志的没有使用索引的sql语句次数,防止过多语句被记录,导致日志文件不断增大
log_throttle_queries_not_using_indexes
Copy # Time: 200303 14:54:38
# User@Host: wangjun[wangjun] @ localhost []
# Thread_id: 47 Schema: scujoo QC_hit: No
# Query_time: 0.024923 Lock_time: 0.000130 Rows_sent: 3488 Rows_examined: 3488
# Rows_affected: 0 Bytes_sent: 354872
SET timestamp=1583218478;
select * from account;
/usr/sbin/mysqld, Version: 10.3.15-MariaDB-1-log (Raspbian testing-staging). started with:
Tcp port: 0 Unix socket: /run/mysqld/mysqld.sock
Time Id Command Argument
# Time: 200303 15:05:30
# User@Host: [root] @ localhost []
# Thread_id: 8 Schema: mysql QC_hit: No
# Query_time: 0.001743 Lock_time: 0.000168 Rows_sent: 1 Rows_examined: 1
# Rows_affected: 0 Bytes_sent: 252
use mysql;
SET timestamp=1583219130;
show variables like 'datadir';
# User@Host: [root] @ localhost []
# Thread_id: 10 Schema: QC_hit: No
# Query_time: 0.007002 Lock_time: 0.000238 Rows_sent: 36 Rows_examined: 69
# Rows_affected: 0 Bytes_sent: 2391
SET timestamp=1583219130;
select concat('select count(*) into @discard from `',
TABLE_SCHEMA, '`.`', TABLE_NAME, '`')
from information_schema.TABLES where TABLE_SCHEMA<>'INFORMATION_SCHEMA' and TABLE_SCHEMA<>'PERFORMANCE_SCHEMA' and ( ENGINE='MyISAM' or ENGINE='Aria' );
# Time: 200303 15:06:41
Copy # mysqldumpslow -s al -n 10 raspberrypi-slow.log
Reading mysql slow query log from raspberrypi-slow.log
Count: 2 Time=0.01s (0s) Lock=2.33s (4s) Rows_sent=0.0 (0), Rows_examined=1.0 (2), Rows_affected=1.0 (2), wangjun[wangjun]@localhost
update tes set fromN=N where d=N
Count: 4 Time=0.08s (0s) Lock=0.07s (0s) Rows_sent=1.0 (4), Rows_examined=4.0 (16), Rows_affected=0.0 (0), root[root]@localhost
SELECT count(*) FROM mysql.user WHERE user='S' and password='S' and plugin='S'
Count: 25 Time=0.02s (0s) Lock=0.01s (0s) Rows_sent=5.3 (133), Rows_examined=5.3 (133), Rows_affected=0.0 (0), 3users@localhost
show variables like 'S'
......
Copy > show create table mysql.slow_log;
+----------+--------------------------------------------------------------------------------------------------------+
| Table | Create Table
+----------+--------------------------------------------------------------------------------------------------------+
| slow_log | CREATE TABLE `slow_log` (
`start_time` timestamp(6) NOT NULL DEFAULT current_timestamp(6) ON UPDATE current_timestamp(6),
`user_host` mediumtext NOT NULL,
`query_time` time(6) NOT NULL,
`lock_time` time(6) NOT NULL,
`rows_sent` int(11) NOT NULL,
`rows_examined` int(11) NOT NULL,
`db` varchar(512) NOT NULL,
`last_insert_id` int(11) NOT NULL,
`insert_id` int(11) NOT NULL,
`server_id` int(10) unsigned NOT NULL,
`sql_text` mediumtext NOT NULL,
`thread_id` bigint(21) unsigned NOT NULL,
`rows_affected` int(11) NOT NULL
) ENGINE=CSV DEFAULT CHARSET=utf8 COMMENT='Slow log' |
Copy > show variables like '%log_output%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_output | FILE |
+---------------+-------+
1 row in set (0.004 sec)