Linux - Mysql - 事务日志

09:15:24(root@localhost) [(none)]> show variables like "%innodb%";

#1> 事务日志性能优化
09:17:44(root@localhost) [(none)]> set global innodb_flush_log_at_trx_commit=2;
Query OK, 0 rows affected (0.00 sec)

#2>错误日志
09:18:34(root@localhost) [(none)]> show variables like "%log_error%";
+---------------------+-----------------------+
| Variable_name       | Value                 |
+---------------------+-----------------------+
| binlog_error_action | ABORT_SERVER          |
| log_error           | /data/mysql/mysql.log |
| log_error_verbosity | 3                     |
+---------------------+-----------------------+

#3>通用日志
09:21:39(root@localhost) [(none)]> show variables like "%general_log%";
+------------------+-------------------------+
| Variable_name    | Value                   |
+------------------+-------------------------+
| general_log      | OFF                     |
| general_log_file | /data/mysql/centos7.log |
+------------------+-------------------------+
2 rows in set (0.00 sec)

09:22:19(root@localhost) [(none)]> set global general_log=on;
Query OK, 0 rows affected (0.03 sec)

09:22:35(root@localhost) [(none)]> show variables like "%general_log%";
+------------------+-------------------------+
| Variable_name    | Value                   |
+------------------+-------------------------+
| general_log      | ON                      |
| general_log_file | /data/mysql/centos7.log |
+------------------+-------------------------+
2 rows in set (0.01 sec)
09:22:37(root@localhost) [(none)]> show variables like "%log_out%";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_output    | FILE  |
+---------------+-------+
1 row in set (0.01 sec)

3> 慢查询日志
slow_query_log=ON|OFF #开启或关闭慢查询,支持全局和会话,只有全局设置才会生成慢查询文件 
long_query_time=N #慢查询的阀值,单位秒 

slow_query_log_file=HOSTNAME-slow.log  #慢查询日志文件 

log_slow_filter =admin,filesort,filesort_on_disk,full_join,full_scan, query_cache,query_cache_miss,tmp_table,tmp_table_on_disk  #上述查询类型且查询时长超过long_query_time,则记录日志 

log_queries_not_using_indexes=ON  #不使用索引或使用全索引扫描,不论是否达到慢查询阀值的语 句是否记录日志,默认OFF,即不记录 

log_slow_rate_limit = 1 #多少次查询才记录,mariadb特有 

log_slow_verbosity= Query_plan,explain #记录内容 

log_slow_queries = OFF    #同slow_query_log,MariaDB 10.0/MySQL 5.6.1 版后已删除

4> 二进制日志

09:27:37(root@localhost) [(none)]> show variables like "%binlog%";
+--------------------------------------------+----------------------+
| Variable_name                              | Value                |
+--------------------------------------------+----------------------+
| binlog_cache_size                          | 32768                |
| binlog_checksum                            | CRC32                |
| binlog_direct_non_transactional_updates    | OFF                  |
| binlog_error_action                        | ABORT_SERVER         |
| binlog_format                              | ROW                  |
| 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         |
| innodb_api_enable_binlog                   | OFF                  |
| innodb_locks_unsafe_for_binlog             | OFF                  |
| log_statements_unsafe_for_binlog           | ON                   |
| max_binlog_cache_size                      | 18446744073709547520 |
| max_binlog_size                            | 1073741824           |
| max_binlog_stmt_cache_size                 | 18446744073709547520 |
| sync_binlog                                | 1                    |
+--------------------------------------------+----------------------+
22 rows in set (0.00 sec)

#mixed让系统自己判断采取行还是语句判断
09:27:45(root@localhost) [(none)]> set global binlog_format=mixed;
Query OK, 0 rows affected (0.00 sec)

01:13:47(root@localhost) [(none)]> show variables like "%log_bin%"
-> ;
+---------------------------------+---------------------------------------+
| Variable_name | Value |
+---------------------------------+---------------------------------------+
| log_bin | ON |
| log_bin_basename | /data/mysql/logbin/mysql-binlog |
| log_bin_index | /data/mysql/logbin/mysql-binlog.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
| sql_log_bin | ON |
+---------------------------------+---------------------------------------+
6 rows in set (0.00 sec)



 

Linux - Mysql - 事务日志

上一篇:重新整理 mysql 基础篇————— 事务隔离级别[四]


下一篇:在Windows Docker中安装MySQL