1 、出现错误提示  

Slave I/O: error connecting to master 'backup@192.168.0.x:3306' -retry-time: 60  retries: 86400,Error_code: 1045
解决方法:
从服务器上删除掉所有的二进制日志文件,包括一个数据目录下的master.info文件和hostname -relay-bin 开头的文件 。
master.info: 记录了Mysql主服务器上的日志文件和记录位置、连接的密码 。
#rm -rf *.*
----------------------------------------------------------------------------------------------
2 、出现错误提示
Error reading packet from server: File '/home/mysql/mysqlLog/log.000001' not found (Errcode: 2) (server_errno=29)
解决方法:
由于主服务器运行了一段时间,产生了二进制文件,而slave是从log.000001开始读取的,删除主机二进制文件,包括log.index文件。
----------------------------------------------------------------------------------------------
3 、错误提示如下
Slave SQL: Error 'Table 'xxxx' doesn't exist' on query. Default database: 't591'. Query: 'INSERT INTO `xxxx`(type,post_id,browsenum) SELECT type,post_id,browsenum FROM xxxx WHERE hitdate='20090209'', Error_code: 1146
解决方法:
由于slave没有此table表,添加这个表使用slave start就可以继续同步。
-----------------------------------------------------------------------------------------------
4 、错误提示如下  
Error 'Duplicate entry '1' for key 1' on query. Default database: 'movivi1'. Query: 'INSERT INTO `v1vid0_user_samename` VALUES(null,1,'123','11','4545','123')'
Error 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1' on query. Default database: 'club'. Query: 'INSERT INTO club.point_process (GIVEID, GETID, POINT, CREATETIME, DEMO) VALUES (0, 4971112, 5, '2010-12-19 16:29:28','
1 row in set (0.00 sec)
Mysql> Slave status\G;
显示:Slave_SQL_Running为NO
解决方法:
Mysql> stop slave;
Mysql> set global sql_slave_skip_counter =1 ;
Mysql> start slave;
-----------------------------------------------------------------------------------------------
5 、错误提示如下
# show slave status\G;
Master_Log_File: mysql-bin.000029
Read_Master_Log_Pos: 3154083
Relay_Log_File: c7-relay-bin.000178
Relay_Log_Pos: 633
Relay_Master_Log_File: mysql-bin.000025
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB: club
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1594
Last_Error: Relay log read failure: Could not parse relay log event entry. The possible reasons are: the master's binary log is corrupted (you can check this by running 'mysqlbinlog' on the binary log), the slave's relay log is corrupted (you can check this by running 'mysqlbinlog' on the relay log), a network problem, or a bug in the master's or slave's MySQL code. If you want to check the master's binary log or slave's relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' on this slave.
Skip_Counter: 0
Exec_Master_Log_Pos: 1010663436
这个问题原因是,主数据库突然停止或问题终止,更改了mysql-bin.xxx日志,slave服务器找不到这个文件,需要找到同步的点和日志文件,然后chage master即可。
解决方法:
 change master to
 master_host='192.168.0.1',
 master_user='同步帐号',
 master_password='同步密码',
 master_port=3306,
 master_log_file='mysql-bin.000002',
 master_log_pos=106;
-----------------------------------------------------------------------------------------------
6 、错误提示如下
Error 'Unknown column 'qdir' in 'field list'' on query. Default database: 'club'. Query: 'insert into club. question_del  (id, pid, ques_name, givepoint, title, subject, subject_pid, createtime, approve, did, status, intime, order_d, endtime,banzhu_uid,banzhu_uname,del_cause,qdir) select id, pid, ques_name, givepoint, title, subject, subject_pid, createtime, approve, did, status, intime, order_d, endtime,'1521859','admin0523',' 无意义回复 ',qdir from club.question where id=7330212'
1 row in set (0.00 sec)
这个错误就说 club.question_del  表里面没有 qdir 这个字段 造成的加上就可以了 ~ !
在主的mysql:里面查询  Desc club. question_del ;
在错误的从服务器上执行:alter table question_del add qdir varchar(30) not null;
-----------------------------------------------------------------------------------------------
7 、错误提示如下
Slave_IO_Running: NO
这个错误就是IO进程没连接上,想办法连接上把与主的POS号和文件一定要对,然后重新加载下数据。
具体步骤:
slave stop;
change master to
master_host='IP地址',
master_user='backup',
master_password='123456',master_log_file='mysqld-bin.000008',MASTER_LOG_POS=396;
注:master_log_file='mysqld-bin.000008',MASTER_LOG_POS=396;是从主的上面查出来的:show master status\G;
LOAD DATA FROM MASTER;
load data from master;
slave start;
-----------------------------------------------------------------------------------------------
8、错误提示如下
使用mysqlbinlog进行分析日志 包以下错误:
# mysqlbinlog --no-defaults mysql-bin.000488 > 488.sql
ERROR: Error in Log_event::read_log_event(): 'Found invalid event in binary log', data_len: 66, event_type: 19
这个错误是使用的mysqlbinlog的版本不正确
# whereis mysqlbinlog
mysqlbinlog: /usr/bin/mysqlbinlog
# /usr/bin/mysqlbinlog --no-defaults -V
/usr/bin/mysqlbinlog Ver 3.2 for redhat-linux-gnu at x86_64
# /usr/local/mysql/bin/mysqlbinlog --no-defaults -V
/usr/local/mysql/bin/mysqlbinlog Ver 3.3 for unknown-linux-gnu at x86_64
通过查询果然发现在默认情况下调用的是系统默认安装的mysql中的mysqlbinlog,因为这个mysqlbinlog的版本和当前的bin_log的版本不能对应起来,所以不能处理,使用对应的mysqlbinlog工作正常
# /usr/local/mysql/bin/mysqlbinlog --no-defaults mysql-bin.000488 |more
   /*!40019 SET @@session.max_insert_delayed_threads=0*/;
   /*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
   DELIMITER /*!*/;
   # at 4
   #120228 23:05:14 server id 1 end_log_pos 106 Start: binlog v 4, server v 5.1.41-log created 120228 23:05:14
   BINLOG '
   Ku1MTw8BAAAAZgAAAGoAAAAAAAQANS4xLjQxLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
   AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC
   '/*!*/;
   # at 106
   #120228 23:05:14 server id 1 end_log_pos 181 Query thread_id=175240 exec_time=0 error_code=0
使用以下命令查看二进制文件后,可以正确查看到内容:
/usr/local/mysql_dir/bin/mysqlbinlog /tmp/1.000001或者将/usr/bin/上的mysqlbinlog替换成/usr/local/mysql_dir/bin/下的也可以,如cp /usr/local/mysql_dir/bin/mysqlbinlog /usr/bin/mysqlbinlog,替换成功后,再执行命令mysqlbinlog /tmp/1.000001
------------------------------------------------------------------------------------------------
9、解决ERROR 1146 (42S02): Table 'mysql.servers' doesn't exist问题
(1)使用mysqld_safe --skip-grant-tables 启动数据库
(2)使用mysql进入数据库
(3)use mysql
(4)创建表 mysql.servers
CREATE TABLE mysql.servers (
Server_name char(64) NOT NULL,
Host char(64) NOT NULL,
Db char(64) NOT NULL,
Username char(64) NOT NULL,
Password char(64) NOT NULL,
Port int(4) DEFAULT NULL,
Socket char(64) DEFAULT NULL,
Wrapper char(64) NOT NULL,
Owner char(64) NOT NULL,
PRIMARY KEY (Server_name)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='MySQL Foreign Servers table';
(5)flush privileges; 成功
-------------------------------------------------------------------------------------------------
10、由于主服务器异外重启, 导致从报错, 错误如下:
show slave status错误:
mysql> show slave status\G
Master_Log_File: mysql-bin.000288
Read_Master_Log_Pos: 627806304
Relay_Log_File: mysql-relay-bin.000990
Relay_Log_Pos: 627806457
Relay_Master_Log_File: mysql-bin.000288
Slave_IO_Running: No
Slave_SQL_Running: Yes
Exec_Master_Log_Pos: 627806304
Relay_Log_Space: 627806663
......
Last_IO_Error:
Got fatal error 1236 from master when  reading
data from binary log:
'Client requested master to start  
replication from impossible position'
mysql错误日志:
tail /data/mysql/mysql-error.log
111010 17:35:49 [ERROR] Error reading packet from server: Client requested master
to start replication from impossible position ( server_errno=1236)
111010 17:35:49 [ERROR]
Slave I/O: Got fatal error 1236 from master when reading data
from
binary log: 'Client requested master to start replication from impossible
position', Error_code: 1236
111010 17:35:49 [Note] Slave I/O thread exiting, read up to log 'mysql-bin.000288',
position 627806304
按照习惯, 先尝试必改position位置.
mysql> stop slave;mysql> change master to master_log_file='mysql-bin.000288',master_log_pos=627625751;mysql> start slave;
错误依旧, 接下来登陆到主服务器查看binlog日志.
先按照错误点的标记去主服务器日志中查找:
[root@db1 ~]# mysqlbinlog --start-position=627655136 /data/mysql/binlog/mysql-bin.000288
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#111010 13:31:19 server id 4 end_log_pos 106 Start: binlog v 4, server v 5.1.45-log
created 111010 13:31:19
# Warning: this binlog is either in use or was not closed properly.
BINLOG '
F1aTTg8EAAAAZgAAAGoAAAABAAQANS4xLjQ1LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC
'/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
没有看到这个位置.
[root@db1 ~]# mysqlbinlog /data/mysql/binlog/mysql-bin.000288 > test.txt
less text.txt
看最后一部分
# at 627625495
#111010 16:35:46 server id 1 end_log_pos 627625631 Query thread_id=45613333
exec_time=32758 error_code=0
SET TIMESTAMP=1318289746/*!*/;
delete from freeshipping_bef_update where part='AR-4006WLM' and code=''
/*!*/;
# at
627625631#111010 16:35:46 server id 1 end_log_pos 627625751
Query thread_id=45613333
exec_time=32758 error_code=0
SET TIMESTAMP=1318289746/*!*/;
delete from shippingFee_special where part='AR-4006WLM'
/*!*/;
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
找到最接近错误标记627655136的一个position是627625631.
再回到slave机器上change master, 将postion指向这个位置.
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)
mysql>
change master to master_log_file='mysql-bin.000288',master_log_pos=627625631;
Query OK, 0 rows affected (0.06 sec)
mysql>
start slave;Query OK, 0 rows affected (0.00 sec)
再次查看
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Queueing master event to the relay log
Master_Host: 192.168.21.105
Master_User: rep
Master_Port: 3306
Connect_Retry: 10
Master_Log_File: mysql-bin.000289
Read_Master_Log_Pos: 25433767
Relay_Log_File: mysql-relay-bin.000003
Relay_Log_Pos: 630
Relay_Master_Log_File: mysql-bin.000289
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
主从同步正常了, 同样的方法修复其它slave机器.
-----------------------------------------------------------------------------------------------
11、在做MySQL主从复制时遇到个ERROR 1201 (HY000): Could not initialize master info structure .
出现这个问题的原因是之前曾做过主从复制!
解决方案是:运行命令 stop slave;
成功执行后继续运行 reset slave;
然后进行运行GRANT命令重新设置主从复制。
具体过程如下:
mysql> change master to master_host='192.168.0.1', master_user='backup', master_pass  
word='123456', master_log_file='mysql-bin-000002', master_log_pos=553;  
ERROR 1201 (HY000): Could not initialize master info structure; more error messages can be found in the MySQL error log  
mysql> stop slave;  
Query OK, 0 rows affected, 1 warning (0.00 sec)  
mysql> reset slave;  
Query OK, 0 rows affected (0.00 sec)  
mysql> change master to master_host='192.168.0.1', master_user='backup', master_pass  
word='123456', master_log_file='mysql-bin-000002', master_log_pos=553;  
Query OK, 0 rows affected (0.11 sec)  
------------------------------------------------------------------------------------------------
12、在没有解锁的情况下停止slave进程:
    > stop slave;
ERROR 1192 (HY000): Can't execute the given command because you have active locked tables or an active transaction
13、change master语法错误,落下逗号
mysql> change master to
   -> master_host='IP'
   -> master_user='USER',
   -> master_password='PASSWD',
   -> master_log_file='mysql-bin.000002',
   -> master_log_pos=106;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'master_user='USER',
master_password='PASSWD',
master_log_file='mysql-bin.000002' at line 3
14、在没有停止slave进程的情况下change master
mysql> change master to master_host=‘IP', master_user='USER', master_password='PASSWD', master_log_file='mysql-bin.000001',master_log_pos=106;
ERROR 1198 (HY000): This operation cannot be performed with a running slave; run STOP SLAVE first
15、A B的server-id相同:
Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server ids;
these ids must be different for replication to work (or the --replicate-same-server-id option must be used on
slave but this does not always make sense; please check the manual before using it).
查看server-id
mysql> show variables like 'server_id';
手动修改server-id
mysql> set global server_id=2; #此处的数值和my.cnf里设置的一样就行
mysql> slave start;
6)change master之后,查看slave的状态,发现slave_IO_running 为NO
需要注意的是,做完上述操作之后最后重启mysql进程