在正常安装完了主从后,在主上操作db1库时,删除了他的一个表,然后在从上查看时,发现找不到这个db1库了,而主上db1库没问题。
主库:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| db1 |
| mysql |
| test |
+--------------------+
4 rows in set (0.00 sec)
从库:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| test |
+--------------------+
3 rows in set (0.01 sec)
于是查看了一下从库状态:
show slave status\G;
Slave_IO_State: Waiting for master to send event
Master_Host: 127.0.0.1
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: wzq.000003
Read_Master_Log_Pos: 106
Relay_Log_File: centos-6-relay-bin.000002
Relay_Log_Pos: 245
Relay_Master_Log_File: wzq.000002
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: 1051
Last_Error: Error 'Unknown table 'func'' on query. Default database: 'db1'. Query: 'drop table func'
Skip_Counter: 0
Exec_Master_Log_Pos: 331
Relay_Log_Space: 525652
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: 1051
Last_SQL_Error: Error 'Unknown table 'func'' on query. Default database: 'db1'. Query: 'drop table func'
1 row in set (0.00 sec)
ERROR:
No query specified
发现Slave_SQL_Running: No 显示的是NO,从库没有在运行,停掉slav stop ;然后slave start ;也不行,因为db1的库没了,无法再主库上同步过来。
然后查看主库的状态:show master status;
发现file和position的内容不对了
mysql> show master status;
+------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------+----------+--------------+------------------+
| wzq.000003 | 106 | db1 | |
+------------+----------+--------------+------------------+
1 row in set (0.00 sec)
之前使用的是wzq.000002,现在是wzq.000003了,position也变了。这样就导致主从不能复制了。
需要在从上重新配置:
slave stop;
change master to master_host='127.0.0.1',master_port=3306,master_user='repl',master_password='123456',master_log_file='wzq.000003',master_log_pos=106;
slave start;