本文整理自网络,侵删。
目录
- 1. 清理二进制日志
- 2. mysqldump不锁表
- 3. mysql跳过空事务
- 4. 番外
- 5. mysql8.0使用mysqldump导出数据
1. 清理二进制日志
purge master logs to 'log-bin.004193'; ? #表示直接清理到4193位置
2. mysqldump不锁表
在使用mysqldump
备份mysql
数据时,要尽量去从库拿,如果有需求去主库,可以加 --single-transaction
参数不锁表,不加此参数有可能会把主库的表全锁了!!导致业务出现故障
mysqldump --single-transaction ?--compact -uroot -p(password) -h(dbip) -d (databasesname) > /tmp/test.sql?
3. mysql跳过空事务
问题出现:
? ? ? ? ? ? ? ?Slave_IO_State: Waiting for master to send event ? ? ? ? ? ? ? ? ? Master_Host: 10.187.97.219 ? ? ? ? ? ? ? ? ? Master_User: repl ? ? ? ? ? ? ? ? ? Master_Port: 3306 ? ? ? ? ? ? ? ? Connect_Retry: 60 ? ? ? ? ? ? ? Master_Log_File: log-bin.000047 ? ? ? ? ? Read_Master_Log_Pos: 61907358 ? ? ? ? ? ? ? ?Relay_Log_File: relay.000114 ? ? ? ? ? ? ? ? Relay_Log_Pos: 61906291 ? ? ? ? Relay_Master_Log_File: log-bin.000047 ? ? ? ? ? ? ?Slave_IO_Running: Yes ? ? ? ? ? ? Slave_SQL_Running: No ? ? ? ? ? ? ? Replicate_Do_DB: ? ? ? ? ? Replicate_Ignore_DB: ? ? ? ? ? ?Replicate_Do_Table: ? ? ? ?Replicate_Ignore_Table: ? ? ? Replicate_Wild_Do_Table: ? Replicate_Wild_Ignore_Table: ? ? ? ? ? ? ? ? ? ?Last_Errno: 1062 ? ? ? ? ? ? ? ? ? ?Last_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction '81a58913-993d-11eb-94c7-00e0ed7ae706:37497' at master log log-bin.000047, end_log_pos 61906370. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any. ? ? ? ? ? ? ? ? ?Skip_Counter: 0 ? ? ? ? ? Exec_Master_Log_Pos: 61906082 ? ? ? ? ? ? ? Relay_Log_Space: 61907849 ? ? ? ? ? ? ? Until_Condition: None ? ? ? ? ? ? ? ?Until_Log_File: ? ? ? ? ? ? ? ? Until_Log_Pos: 0 ? ? ? ? ? ?Master_SSL_Allowed: No ? ? ? ? ? ?Master_SSL_CA_File: ? ? ? ? ? ?Master_SSL_CA_Path: ? ? ? ? ? ? ? Master_SSL_Cert: ? ? ? ? ? ? Master_SSL_Cipher: ? ? ? ? ? ? ? ?Master_SSL_Key: ? ? ? ? Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No ? ? ? ? ? ? ? ? Last_IO_Errno: 0 ? ? ? ? ? ? ? ? Last_IO_Error: ? ? ? ? ? ? ? ?Last_SQL_Errno: 1062 ? ? ? ? ? ? ? ?Last_SQL_Error: Coordinator stopped because there were error(s) in the worker(s). The most recent failure being: Worker 1 failed executing transaction '81a58913-993d-11eb-94c7-00e0ed7ae706:37497' at master log log-bin.000047, end_log_pos 61906370. See error log and/or performance_schema.replication_applier_status_by_worker table for more details about this failure or others, if any. ? Replicate_Ignore_Server_Ids: ? ? ? ? ? ? ?Master_Server_Id: 5345323 ? ? ? ? ? ? ? ? ? Master_UUID: 81a58913-993d-11eb-94c7-00e0ed7ae706 ? ? ? ? ? ? ?Master_Info_File: mysql.slave_master_info ? ? ? ? ? ? ? ? ? ? SQL_Delay: 0 ? ? ? ? ? SQL_Remaining_Delay: NULL ? ? ? Slave_SQL_Running_State: ? ? ? ? ? ?Master_Retry_Count: 86400 ? ? ? ? ? ? ? ? ? Master_Bind: ? ? ? Last_IO_Error_Timestamp: ? ? ?Last_SQL_Error_Timestamp: 210413 05:25:50 ? ? ? ? ? ? ? ?Master_SSL_Crl: ? ? ? ? ? ?Master_SSL_Crlpath: #master# Retrieved_Gtid_Set: 81a58913-993d-11eb-94c7-00e0ed7ae706:2-37500 #slave# ? ?Executed_Gtid_Set: 119cf71e-993c-11eb-94bd-00e0ed93753c:1-3, #81a58913-993d-11eb-94c7-00e0ed7ae706:1-37496 ? ? ? ? ? ? ? ? Auto_Position: 1 ? ? ? ? ?Replicate_Rewrite_DB: ? ? ? ? ? ? ? ? ?Channel_Name: ? ? ? ? ? ?Master_TLS_Version: 1 row in set (0.00 sec)
开始处理:首先我们知道
Executed_Gtid_Set: 119cf71e-993c-11eb-94bd-00e0ed93753c:1-3,
81a58913-993d-11eb-94c7-00e0ed7ae706:1-37496
是slave 已经执行过的事务。
其中:
81a58913-993d-11eb-94c7-00e0ed7ae706:1-37496
是已经回放了的从master 同步的事务, 119cf71e-993c-11eb-94bd-00e0ed93753c:1-3
, 是在 slave 上 执行的事务
而下面这个是从master
同步的事务,等待slave
Retrieved_Gtid_Set: 81a58913-993d-11eb-94c7-00e0ed7ae706:2-37500 ?
执行停止slave
mysql> stop slave; Query OK, 0 rows affected (0.00 sec)
检查当前 gtid 相关信息
mysql> show variables like '%gtid%'; +----------------------------------+----------------------------------------+ | Variable_name ? ? ? ? ? ? ? ? ? ?| Value ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| +----------------------------------+----------------------------------------+ | binlog_gtid_simple_recovery ? ? ?| ON ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | | enforce_gtid_consistency ? ? ? ? | ON ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | | gtid_executed ? ? ? ? ? ? ? ? ? ?| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| | gtid_executed_compression_period | 1000 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | | gtid_mode ? ? ? ? ? ? ? ? ? ? ? ?| ON ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | | gtid_next ? ? ? ? ? ? ? ? ? ? ? ?| AUTOMATIC ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| | gtid_owned ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| | gtid_purged ? ? ? ? ? ? ? ? ? ? ?| 81a58913-993d-11eb-94c7-00e0ed7ae706:1 | | session_track_gtids ? ? ? ? ? ? ?| OFF ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| +----------------------------------+----------------------------------------+ 9 rows in set (0.00 sec)
将事务指向37496 的下一个事务,即 37497,注意规范,把 :1-37396 的 1 去掉
mysql> set gtid_next='81a58913-993d-11eb-94c7-00e0ed7ae706:37497'; Query OK, 0 rows affected (0.00 sec) mysql> show variables like '%gtid%'; +----------------------------------+--------------------------------------------+ | Variable_name ? ? ? ? ? ? ? ? ? ?| Value ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| +----------------------------------+--------------------------------------------+ | binlog_gtid_simple_recovery ? ? ?| ON ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | | enforce_gtid_consistency ? ? ? ? | ON ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | | gtid_executed ? ? ? ? ? ? ? ? ? ?| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| | gtid_executed_compression_period | 1000 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | | gtid_mode ? ? ? ? ? ? ? ? ? ? ? ?| ON ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | | gtid_next ? ? ? ? ? ? ? ? ? ? ? ?| 81a58913-993d-11eb-94c7-00e0ed7ae706:37497 | | gtid_owned ? ? ? ? ? ? ? ? ? ? ? | 81a58913-993d-11eb-94c7-00e0ed7ae706:37497 | | gtid_purged ? ? ? ? ? ? ? ? ? ? ?| 81a58913-993d-11eb-94c7-00e0ed7ae706:1 ? ? | | session_track_gtids ? ? ? ? ? ? ?| OFF ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| +----------------------------------+--------------------------------------------+ 9 rows in set (0.01 sec)
跳过空事务:
mysql> begin; Query OK, 0 rows affected (0.00 sec) mysql> commit; Query OK, 0 rows affected (0.00 sec)
查询gtid 信息:
mysql> show variables like '%gtid%'; +----------------------------------+--------------------------------------------+ | Variable_name ? ? ? ? ? ? ? ? ? ?| Value ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| +----------------------------------+--------------------------------------------+ | binlog_gtid_simple_recovery ? ? ?| ON ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | | enforce_gtid_consistency ? ? ? ? | ON ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | | gtid_executed ? ? ? ? ? ? ? ? ? ?| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| | gtid_executed_compression_period | 1000 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | | gtid_mode ? ? ? ? ? ? ? ? ? ? ? ?| ON ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? | | gtid_next ? ? ? ? ? ? ? ? ? ? ? ?| 81a58913-993d-11eb-94c7-00e0ed7ae706:37497 | | gtid_owned ? ? ? ? ? ? ? ? ? ? ? | ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| | gtid_purged ? ? ? ? ? ? ? ? ? ? ?| 81a58913-993d-11eb-94c7-00e0ed7ae706:1 ? ? | | session_track_gtids ? ? ? ? ? ? ?| OFF ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?| +----------------------------------+--------------------------------------------+ 9 rows in set (0.00 sec)
设置自动分配 GTID:
ysql> set gtid_next='AUTOMATIC'; Query OK, 0 rows affected (0.00 sec)
4. 番外
我们知道一个新的事务在提交后会被分配一个新的GTID,当该事务在从库上被应用时会保留主库上的GTID
我们可以通过设定gtid_next
的值来改变这种行为
相关阅读 >>
oracle出现错误ora-00904: invalid identifier
更多相关阅读请进入《sql》频道 >>
数据库系统概念 第6版
机械工业出版社
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。
转载请注明出处:木庄网络博客 » mysql常用命令以及小技巧
相关推荐
评论
管理员已关闭评论功能...