MySQL replicación · 3 min read · Nov 02, 2025
Cómo Reparar la Replicación de MySQL

Si has configurado la replicación de MySQL, probablemente conozcas este problema: a veces hay consultas de MySQL inválidas que hacen que la replicación deje de funcionar. En esta breve guía, explico cómo puedes reparar la replicación en el esclavo de MySQL sin necesidad de configurarlo desde cero nuevamente. Esta guía es para MySQL y MariaDB.
1 Identificando el Problema
Para averiguar si la replicación está/no está funcionando y qué la ha causado detenerse, puedes echar un vistazo a los registros. En Debian, por ejemplo, MySQL registra en /var/log/syslog:
grep mysql /var/log/syslogserver1:/home/admin# grep mysql /var/log/syslog
MAR 19 09:56:08 http2 mysqld[1380]: 080529 9:56:08 [ERROR] Slave: Error 'Table 'mydb.taggregate_temp_1212047760' doesn't exist' on query. Default database: 'mydb'. Query: 'UPDATE thread AS thread,taggregate_temp_1212047760 AS aggregate
MAR 19 09:56:08 http2 mysqld[1380]: ^ISET thread.views = thread.views + aggregate.views
MAR 19 09:56:08 http2 mysqld[1380]: ^IWHERE thread.threadid = aggregate.threadid', Error_code: 1146
MAR 19 09:56:08 http2 mysqld[1380]: 080529 9:56:08 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.001079' position 203015142
server1:/home/admin#Puedes ver qué consulta causó el error y en qué posición del registro se detuvo la replicación.
Para verificar que la replicación realmente no está funcionando, inicia sesión en MySQL:
mysql -u root -pEn el shell de MySQL, ejecuta:
mysql> SHOW SLAVE STATUS \GSi uno de Slave_IO_Running o Slave_SQL_Running está configurado en No, entonces la replicación está rota:
mysql> SHOW SLAVE STATUS \G
************************* 1. row ***********************
Slave_IO_State: Waiting for master to send event
Master_Host: 1.2.3.4
Master_User: slave_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.001079
Read_Master_Log_Pos: 269214454
Relay_Log_File: slave-relay.000130
Relay_Log_Pos: 100125935
Relay_Master_Log_File: mysql-bin.001079
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB: mydb
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1146
Last_Error: Error 'Table 'mydb.taggregate_temp_1212047760' doesn't exist' on query. Default database: 'mydb'.
Query: 'UPDATE thread AS thread,taggregate_temp_1212047760 AS aggregate
SET thread.views = thread.views + aggregate.views
WHERE thread.threadid = aggregate.threadid'
Skip_Counter: 0
Exec_Master_Log_Pos: 203015142
Relay_Log_Space: 166325247
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
1 row in set (0.00 sec)
mysql>2 Reparar la Replicación de MySQL
Solo para asegurarnos, detenemos el esclavo:
mysql> STOP SLAVE;Arreglar el problema es en realidad bastante fácil. Le decimos al esclavo que simplemente omita la consulta SQL inválida:
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;Esto le dice al esclavo que omita una consulta (que es la inválida que causó que la replicación se detuviera). Si deseas omitir dos consultas, usarías SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 2; en su lugar y así sucesivamente.
Eso es todo. Ahora podemos iniciar el esclavo nuevamente…
mysql> START SLAVE;… y verificar si la replicación está funcionando nuevamente:
mysql> SHOW SLAVE STATUS \Gmysql> SHOW SLAVE STATUS \G*********************** 1. row ************************* Slave_IO_State: Waiting for master to send event Master_Host: 1.2.3.4 Master_User: slave_user Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.001079 Read_Master_Log_Pos: 447560366 Relay_Log_File: slave-relay.000130 Relay_Log_Pos: 225644062 Relay_Master_Log_File: mysql-bin.001079 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: mydb Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 447560366 Relay_Log_Space: 225644062 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: 0 1 row in set (0.00 sec) mysql>
Como ves, tanto Slave_IO_Running como Slave_SQL_Running están configurados en Sí ahora.
Ahora sal del shell de MySQL…
mysql> quit;… y verifica el registro nuevamente:
grep mysql /var/log/syslogserver1:/home/admin# grep mysql /var/log/syslog
MAR 19 09:56:08 http2 mysqld[1380]: 080529 9:56:08 [ERROR] Slave: Error 'Table 'mydb.taggregate_temp_1212047760' doesn't exist' on query. Default database: 'mydb'. Query: 'UPDATE thread AS thread,taggregate_temp_1212047760 AS aggregate
MAR 19 09:56:08 http2 mysqld[1380]: ^ISET thread.views = thread.views + aggregate.views
MAR 19 09:56:08 http2 mysqld[1380]: ^IWHERE thread.threadid = aggregate.threadid', Error_code: 1146
MAR 19 09:56:08 http2 mysqld[1380]: 080529 9:56:08 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.001079' position 203015142
MAR 19 11:42:13 http2 mysqld[1380]: 080529 11:42:13 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.001079' at position 203015142, relay log '/var/lib/mysql/slave-relay.000130' position: 100125935
server1:/home/admin#La última línea dice que la replicación ha comenzado nuevamente, y si no ves errores después de esa línea, todo está bien.
3 Enlaces
- MySQL: http://www.mysql.com
Recibe nuevas publicaciones en tu bandeja de entrada.
No spam. Cancela la suscripción en cualquier momento.