Mysql的主从数据库没有同步先上Master库:mysql>show processlist; 查看下进程是否Sleep太多。发现很正常。show master status; 也正常。mysql> show master status;+——————-+———-+————–+——————————-+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+——————-+———-+————–+——————————-+| mysqld-bin.000001 | 3260 | | mysql,test,information_schema |+——————-+———-+————–+——————————-+1 row in set (0.00 sec)再到Slave上查看mysql> show slave status\GSlave_IO_Running: YesSlave_SQL_Running: No可见是Slave不同步下面介绍两种解决方法:方法一:忽略错误后,继续同步该方法适用于主从库数据相差不大,或者要求数据可以不完全统一的情况,数据要求不严格的情况解决:stop slave;#表示跳过一步错误,后面的数字可变set global sql_slave_skip_counter =1;start slave;之后再用mysql> show slave status\G 查看:Slave_IO_Running: YesSlave_SQL_Running: Yesok,现在主从同步状态正常了。。。注:如果错误过多,可以在my.cnf中添加slave-skip-errors=all方式二:重新做主从,完全同步该方法适用于主从库数据相差较大,或者要求数据完全统一的情况解决步骤如下:1.先进入主库,进行锁表,防止数据写入使用命令:mysql> flush tables with read lock;注意:该处是锁定为只读状态,语句不区分大小写2.进行数据备份#把数据备份到mysql.bak.sql文件[root@server01 mysql]#mysqldump -uroot -p -hlocalhost > mysql.bak.sql这里注意一点:数据库备份一定要定期进行,可以用shell脚本或者 python 脚本,都比较方便,确保数据万无一失3.查看master 状态mysql> show master status;+——————-+———-+————–+——————————-+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |+——————-+———-+————–+——————————-+| mysqld-bin.000001 | 3260 | | mysql,test,information_schema |+——————-+———-+————–+——————————-+1 row in set (0.00 sec)4.把mysql备份文件传到从库机器,进行数据恢复#使用scp命令[root@server01 mysql]# scp mysql.bak.sql root@192.168.128.101:/tmp/5.停止从库的状态mysql> stop slave;6.然后到从库执行mysql命令,导入数据备份mysql> source /tmp/mysql.bak.sql7.设置从库同步,注意该处的同步点,就是主库show master status信息里的| File| Position两项change master to master_host = ‘192.168.128.100’, master_user = ‘rsync’, master_port=3306, master_password=”, master_log_file = ‘mysqld-bin.000001’, master_log_pos=3260;8.重新开启从同步mysql> start slave;9.查看同步状态mysql> show slave status\G 查看:Slave_IO_Running: YesSlave_SQL_Running: Yes好了,同步完成啦。根据mysqlbin恢复丛库数据1、查看错误日志,找出异常点cat /db/mysql/mysql.log140814 11:01:52 [ERROR] /usr/local/mysql/libexec/mysqld: Sort aborted150121 11:30:38 [ERROR] /usr/local/mysql/libexec/mysqld: Sort aborted150625 17:09:03 [ERROR] Slave SQL: Error ‘Table ‘IMDB.NEWSINGERWITHDRAWRECORD’ doesn’t exist’ on query. Default database: ‘IMDB’. Query: ‘insert into NEWSINGERWITHDRAWRECORD select SERIALNUM,2,USERID, UNIX_TIMESTAMP(NOW()),CHANNELID,CASH,NAME,IDENTITYCARD,PROVINCE,CITY, REGION,BANKBRANCH,BANKTYPE,BANKCARD,CONSUMEGOLD,REMAINGOLD,TRANFERSTATE, COMPLAINSTATE,COMPLAINREASON,COMPLAINTIME,GMNAME,GMID,OPTIME,RECORD, REPLY,PHONE,SINGERLEVEL,0 FROM SINGERWITHDRAWRECORD WHERE TIME>1433439938 AND WITHDRAWTYPE=0 GROUP BY USERID’, Error_code: 1146150625 17:09:03 [Warning] Slave: Table ‘IMDB.NEWSINGERWITHDRAWRECORD’ doesn’t exist Error_code: 1146150625 17:09:03 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with “SLAVESTART”. We stopped at log ‘mysql-bin.000966’ position717149534150625 18:13:00 [Note] Slave I/O thread killed while reading event150625 18:13:00 [Note] Slave I/O thread exiting, read up to log ‘mysql-bin.000966’, position818000316150625 18:15:38 [Note] Slave SQL thread initialized, starting replication in log ‘mysql-bin.000966’ at position 820812134, relay log‘./IM-SJ01-DBServer04-relay-bin.000001’ position: 4150625 18:15:38 [Note] Slave I/O thread: connected to master ‘repl@192.168.1.102:3306’,replication started in log ‘mysql-bin.000966’at position 8208121342、导出没有同步的的sql语句/usr/local/mysql/bin/mysqlbinlog –start-position=717149534 –stop-position=818000316 mysql-bin.000966 > export.sql注:mysqlbinlog系统的继续可能会报错,请用mysql相同路径下的mysqlbinlogmysqlbinlog --start-datetime='2013-09-10 00:00:00' --stop-datetime='2013-09-10 01:01:01' -d 库名 二进制文件3、把export.sql拷贝到丛库4、执行mysql -uroot CHANNELDB < export.sql –force注:–force可以强行忽略错误继续执行