mysql 同步检查错误常用sql
Database 2025/9/26 15:28:55 点击:不统计
%77w%77%2Ef%6F%72p%73%70%2Ec%6E
mysql 同步检查错误常用sql
# 查询正在执行的sql
SELECT ID, USER, HOST, DB, COMMAND, TIME, STATE, INFO
FROM information_schema.PROCESSLIST
WHERE COMMAND != 'Sleep'
AND INFO IS NOT NULL
ORDER BY TIME DESC;
USER:连接用户(system user 说明是复制线程或后台线程)。
DB:使用的数据库。
COMMAND:正在做的操作,比如 Query、Sleep、Binlog Dump 等。
TIME:当前状态持续的秒数。
STATE:当前 SQL 所处的阶段(如 Sending data、Waiting for table metadata lock)。
INFO:完整 SQL 文本(如果有的话,就是正在执行的 SQL)。
# 查询具体异常执行错误
SELECT * FROM performance_schema.replication_applier_status_by_worker\G
# 查看,非僵尸进城
SELECT * FROM information_schema.processlist WHERE COMMAND != 'Daemon';
# 跳过错误
stop SLAVE;
SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
start SLAVE;
SHOW SLAVE STATUS\G;
# 重置 同步位置
stop SLAVE;
CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.022083', MASTER_LOG_POS=4;
start SLAVE;
# mysql.conf 配置 跳过错误, 重启后 有效
slave-skip-errors = 1062,1032
1062 是配置跳过插入key 重复
1032 = Could not find record (delete 时没找到行)
# 重置从库同步账号,或者位置:
RESET SLAVE ALL; -- MySQL 8+ 必用 ALL
重置代码
CHANGE MASTER TO
MASTER_HOST='master-1 or ip',
MASTER_PORT=3308,
MASTER_USER='username',
MASTER_PASSWORD='password',
MASTER_LOG_FILE='mysql-bin.043336',
MASTER_LOG_POS=4,
MASTER_SSL=1;
# 查看主库 有哪些可以同步的账号:
SELECT user, host, Repl_slave_priv
FROM mysql.user
WHERE Repl_slave_priv='Y';
mysql 查询具体执行sql 指定 执行pid
SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE ID =[PID]\G; 可以根据具体的字段查询
SELECT ID, USER, HOST, DB, COMMAND, TIME, STATE, INFO FROM INFORMATION_SCHEMA.PROCESSLIST WHERE USER='system user'; http://%77%77%77%2E%66%6F%72%61%73%70%2E%63%6E
