时间:2021-07-01 10:21:17 帮助过:2人阅读
mysql> show global variables like "log_error"; +---------------+--------------------------+ | Variable_name | Value | +---------------+--------------------------+ | log_error | /var/log/mysql/error.log | +---------------+--------------------------+ 1 row in set (0.00 sec) ##tail -f error.log 实时监控这个文件中的;tail -f error.log 实时监控这个文件中的; 慢查询日志
mysql> show global variables like ‘%slow%‘; +---------------------+----------------------------------+ | Variable_name | Value | +---------------------+----------------------------------+ | log_slow_queries | OFF | | slow_launch_time | 2 | | slow_query_log | OFF | | slow_query_log_file | /var/lib/mysql/itcast01-slow.log | +---------------------+----------------------------------+ 4 rows in set (0.00 sec)#打开慢查询日志
mysql> set global slow_query_log =1; Query OK, 0 rows affected (0.00 sec) mysql> show global variables like ‘%slow%‘; +---------------------+----------------------------------+ | Variable_name | Value | +---------------------+----------------------------------+ | log_slow_queries | ON | | slow_launch_time | 2 | | slow_query_log | ON | | slow_query_log_file | /var/lib/mysql/itcast01-slow.log | +---------------------+----------------------------------+ 4 rows in set (0.00 sec)
#查看慢查询日志的阈值
mysql> show global variables like ‘long_query_time‘; +-----------------+-----------+ | Variable_name | Value | +-----------------+-----------+ | long_query_time | 10.000000 | +-----------------+-----------+
设置阈值,通常5秒;
mysql> set global long_query_time = 1; Query OK, 0 rows affected (0.00 sec) mysql> show global variables like ‘long_query_time‘; +-----------------+----------+ | Variable_name | Value | +-----------------+----------+ | long_query_time | 1.000000 | +-----------------+----------+ 1 row in set (0.00 sec)
综合查询日志
mysql> show global variables like ‘%general%‘; +------------------+-----------------------------+ | Variable_name | Value | +------------------+-----------------------------+ | general_log | OFF | | general_log_file | /var/lib/mysql/itcast01.log | +------------------+-----------------------------+ 2 rows in set (0.00 sec)查询日志的输出与文件切换
mysql> show global variables like ‘%log_output%‘; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_output | FILE | +---------------+-------+ 1 row in set (0.00 sec)
存储引擎事务日志---只记录数据变化;
情况二:
所以在写入频繁的线上业务中,建议将ib_logfile的大小调大;这样有利于并发; 二进制日志binlog
mysql> show global variables like ‘log_bin‘; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_bin | OFF | +---------------+-------+ 1 row in set (0.00 sec)
binlog管理
show binary logs; show binlog events in ‘mysql-bin.000001‘
binlog 只记录对数据产生变化的 语句; 但是有局限: 如果使用uuid(),每次产生不一样的值;来插入数据, binlog,记录的是 insert into tab values (uuid()); 此时通过回放,binlog不能得到原数据; 因为每次uuid()产生不一样的值。 所以mysql允许使用另一种格式记录binlog,只记录数据变化值; 可以将binlog_format 设置成row; 而binlog_format 设置成satement,记录具体操作语句; 而binlog_format 设置成mixed,mysql自动判断使用row,还是satement; 总结
mysql日志系统
标签: