mysql> show variables like '%version%';
+-------------------------+------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------+
| innodb_version | 5.7.25 || protocol_version | 10 || slave_type_conversions ||| tls_version | TLSv1,TLSv1.1 || version | 5.7.25-log || version_comment | MySQL Community Server (GPL)|| version_compile_machine | x86_64 || version_compile_os | Linux |
+-------------------------+------------------------------+
8 rows inset(0.00 sec)
查看当前的通用日志是否开启
mysql> show variables like '%general%';
+------------------+--------------------------------------------------+
| Variable_name | Value |
+------------------+--------------------------------------------------+
| general_log | OFF || general_log_file | /home/autoInstall_1.2.1/mysql/data/hessian03.log |
+------------------+--------------------------------------------------+
2 rows inset(0.00 sec)
通用日志开启 && 关闭
开启通用日志查询:
mysql>set global general_log = on;
Query OK, 0 rows affected (0.00 sec)
关闭通用日志查询:
set global general_log = off;
查看当前日志文件的格式
mysql> show variables like 'log_output';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_output | FILE |
+---------------+-------+
1 row inset(0.00 sec)
当前慢文件格式为file ,存储在数据库的数据文件中的hostname.log
可以是table格式,存储在数据库的数据文件中的mysql.general_log
设置通用日志输出为表方式:
set global log_output ='file';
设置通用日志输出为表和文件方式:
set global log_output ='file,table';
慢查询日志
mysql> show variables like '%quer%';
+----------------------------------------+-------------------------------------------------------+
| Variable_name | Value |
+----------------------------------------+-------------------------------------------------------+
| binlog_rows_query_log_events | OFF || ft_query_expansion_limit | 20 || have_query_cache | YES || log_queries_not_using_indexes | OFF || log_throttle_queries_not_using_indexes | 0 || long_query_time | 10.000000 || query_alloc_block_size | 8192 || query_cache_limit | 1048576 || query_cache_min_res_unit | 4096 || query_cache_size | 1048576 || query_cache_type | OFF || query_cache_wlock_invalidate | OFF || query_prealloc_size | 8192 || slow_query_log | OFF || slow_query_log_file | /home/autoInstall_1.2.1/mysql/data/hessian03-slow.log |
+----------------------------------------+-------------------------------------------------------+
15 rows inset(0.00 sec)
1)slow_query_log 的值为ON 为开启慢查询日志,off表示关闭慢查询日志
2) slow_query_log_file 的值是记录的慢查询日志到文件中(默认为主机 名.log)
3)long_query_time 指定了慢查询的阈值,即执行语句的时间若超过这个值则为慢查询语句
4)log_queries_not_using_indexes 如果该值是ON,则会记录所有没有利用索引来进行查询的语句,前提是slow_query_log 的值也是ON,否则,不会奏效
查询当前慢查询的语句个数:
show global status like '%slow%';
可以通过查询语句查看慢查询的语句:
select * from mysql.slow_log;
错误日志
mysql> show variables like '%log_error%';
+---------------------+---------------------+
| Variable_name | Value |
+---------------------+---------------------+
| binlog_error_action | ABORT_SERVER || log_error | /var/log/mysqld.log || log_error_verbosity | 3 |
+---------------------+---------------------+
3 rows inset(0.00 sec)
文章目录通用查询日志慢查询日志错误日志二进制日志参考通用查询日志查看通用日志信息mysql> show variables like '%version%';+-------------------------+------------------------------+| Variable_name | Value |+-------------------------+-----------------------