查询所有的日志开启、关闭、输出位置等状态的SQL
mysql> SHOW GLOBAL VARIABLES LIKE '%log%';
1.查询日志:记录查询操作;(一般不开启)
红色加粗的项与查询日志有关的三个选项:
mysql> show global variables like "%log%"; +--------------------------------------------+----------------------------------------------+ | Variable_name | Value | +--------------------------------------------+----------------------------------------------+ | back_log | 150 | | binlog_cache_size | 32768 | | binlog_checksum | CRC32 | | binlog_direct_non_transactional_updates | OFF | | binlog_error_action | ABORT_SERVER | | binlog_format | MIXED | | binlog_group_commit_sync_delay | 0 | | binlog_group_commit_sync_no_delay_count | 0 | | binlog_gtid_simple_recovery | ON | | binlog_max_flush_queue_time | 0 | | binlog_order_commits | ON | | binlog_row_image | FULL | | binlog_rows_query_log_events | OFF | | binlog_stmt_cache_size | 32768 | | binlog_transaction_dependency_history_size | 25000 | | binlog_transaction_dependency_tracking | COMMIT_ORDER | | expire_logs_days | 99 | | general_log | OFF | | general_log_file | /home/www/mysqldata/personal.log | | innodb_api_enable_binlog | OFF | | innodb_flush_log_at_timeout | 1 | | innodb_flush_log_at_trx_commit | 1 | | innodb_locks_unsafe_for_binlog | OFF | | innodb_log_buffer_size | 8388608 | | innodb_log_checksums | ON | | innodb_log_compressed_pages | ON | | innodb_log_file_size | 33554432 | | innodb_log_files_in_group | 2 | | innodb_log_group_home_dir | /home/www/mysqldata | | innodb_log_write_ahead_size | 8192 | | innodb_max_undo_log_size | 1073741824 | | innodb_online_alter_log_max_size | 134217728 | | innodb_undo_log_truncate | OFF | | innodb_undo_logs | 128 | | log_bin | ON | | log_bin_basename | /home/www/mysqldata/mysql-bin | | log_bin_index | /home/www/mysqldata/mysql-bin.index | | log_bin_trust_function_creators | OFF | | log_bin_use_v1_row_events | OFF | | log_builtin_as_identified_by_password | OFF | | log_error | ./personal.err | | log_error_verbosity | 3 | | log_output | FILE | | log_queries_not_using_indexes | OFF | | log_slave_updates | OFF | | log_slow_admin_statements | OFF | | log_slow_slave_statements | OFF | | log_statements_unsafe_for_binlog | ON | | log_syslog | OFF | | log_syslog_facility | daemon | | log_syslog_include_pid | ON | | log_syslog_tag | | | log_throttle_queries_not_using_indexes | 0 | | log_timestamps | UTC | | log_warnings | 2 | | max_binlog_cache_size | 18446744073709547520 | | max_binlog_size | 1073741824 | | max_binlog_stmt_cache_size | 18446744073709547520 | | max_relay_log_size | 0 | | relay_log | | | relay_log_basename | /home/www/mysqldata/personal-relay-bin | | relay_log_index | /home/www/mysqldata/personal-relay-bin.index | | relay_log_info_file | relay-log.info | | relay_log_info_repository | FILE | | relay_log_purge | ON | | relay_log_recovery | OFF | | relay_log_space_limit | 0 | | slow_query_log | ON | | slow_query_log_file | /home/www/mysqldata/mysql_slow.log | | sql_log_off | OFF | | sync_binlog | 1 | | sync_relay_log | 10000 | | sync_relay_log_info | 10000 | +--------------------------------------------+----------------------------------------------+
保存方式:文件(file)或 表(table)
general_log=ON|OFF
general_log_file=$HOSTNAME.log
log_output=TABLE|FILE|NONE
2.慢查询日志: 执行时长超出指定时长的查询操作;
mysql> show global variables like 'long_query_time'; (查看当前SQL语句时长,默认10秒) mysql> set global long_query_time=“时长” slow_query_log=ON|OFF (关于是否开启慢查询日志)
3.错误日志:(注意,不全是错误的信息)
mysqld 启动和关闭过程中输出的事件信息;
mysqld运行中产生的错误信息;
event scheduler运行一个enent时产生的日志信息;
在主从复制架构中的从服务器上启动从服务器线程时产生的信息;
log_error=/PATH/TO/LOG_ERROR_FILE
log_warnings=1|0:是否记录警告信息至错误日志中
4.二进制日志:记录导致数据改变或潜在导致数据改变的SQL语句
mysql> show binary logs; (记录所有当前的二进制日志文件列表)
mysql>show master status; (当前正在使用哪个二进制日志,以及下一个操作从哪个Position开始)
mysql> show binlog events in 'mysql-bin.000003'; (可以看到操作过的SQL语句)
日志文件名 起始位置 时间类型 唯一标识 结束位置 事件本身是什么
服务器变量:
sql_log_bin=ON|OFF 定义是否记录二进制日志;
log_bin=/PATH/TO/BIN_LOG_FILE 记录的文件位置,通常为OFF;
binlog_format=STATEMENT|ROW|MIXED 二进制日志记录的格式
max_binlog_size=1073741824 单个二进制日志文件的最大体积(默认为1G);到达最大值以后会自动滚动;文件达到上限的大小未必一定到精确值