在window环境下配置MySQL5.7主从复制同步遇到错误及解决方法
在MySQL5.7环境下 主从复制模式,从服务器重启后发现备份停止
手动输入
mysql> start slave; #开启复制
结果为:
Query OK, 0 rows affected (0.00 sec)
然而输入
mysql>SHOW SLAVE STATUS\G #查看主从复制是否配置成功
出现一些错误:Slave_SQL_Running: No
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.8.201
Master_User: xiaokai
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 5383
Relay_Log_File: xiaokai-PC-relay-bin.000002
Relay_Log_Pos: 1028
Relay_Master_Log_File: mysql-bin.000003
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:
解决办法:
mysql>stop slave;#先停止复制线程
mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=1;
mysql> slave start;#再开启复制
问题解决。
. 常见错误及解决方法总结
1)
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
遇到这个问题,可能是因为客户端mysql和服务端版本不一致,比如mysql-5.5.41连接5.7.12。
2.
TIMESTAMP with implicit DEFAULT value is deprecated
执行MySQL的“bin/mysqld --initialize --user=mysql”时报的错误。
原因是从MySQL 5.6版本开始,timestamp的默认值已被标为deprecated,即如果类型为timestamp的字段,如果没有明确声明默认值为NULL,则默认为NOT NULL。如果设置timestamp字段为NULL,则自动存储当前的timestamp。
3.
Can't find error-message file '/usr/local/mysql/share/errmsg.sys'
执行MySQL的“bin/mysqld –initialize –user=mysql –explicit_defaults_for_timestamp”时报的错误。
这可能是因为之前有执行过,导致data目录不为空,通过“bin/mysqld –verbose –help|grep datadir”可以查看到默认的数据目录为/var/lib/mysql/。需要保证/var/lib/mysql/目录为空。或者通过指定参数–datadir改变数据目录,如“bin/mysqld –initialize –user=mysql –explicit_defaults_for_timestamp –datadir=/data/mysql/data”。
4)
Can't find error-message file '/usr/local/mysql/share/errmsg.sys'
对于错误:
Can't find error-message file '/usr/local/mysql/share/errmsg.sys'. Check error-message file location and 'lc-messages-dir' configuration directive.
从官网下载的MySQL默认安装目录为/usr/local/mysql,如果实际为其它目录,则建议通过参数–basedir指定,否则会遇到不少安装问题。通过执行“bin/mysqld –verbose –help|grep basedir”即可看到“–basedir”的默认值为/usr/local/mysql/。
5)
Can't connect to local MySQL server through socket
使用mysql试图进入MySQL Cli时,遇到错误:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
可能是因为客户端的版本和服务端的版本不一致,如果是这样,通常不存在/var/lib/mysql/mysql.sock。可以修改环境变量PATH来解决,让新安装的MySQL的bin目录位于PATH前头,如:
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
export MANPATH=$MYSQL_HOME/man:$MANPATH
6)
ERROR 3021 (HY000): This operation cannot be performed with a running slave io thread;run STOP SLAVE IO_THREAD FOR CHANNEL '' first.
在设置同步关系时,没有先停止slaves线程。解决办法为在设置同步关系之前,先执行下“stop slave”,以停止slave线程。
7)
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
执行mysql时报的错,是由于服务端mysqld和客户端mysql两者的mysql.sock文件位置不同。
解决办法:
使用“ps aux|grep mysqld”或“cat “/proc/pidof mysqld
/cmdline””查看mysqld参数“–socket”的值,比如可能是“/var/lib/mysql/mysql.sock”。
显然不是mysql要找的“/tmp/mysql.sock”,指定下mysql的参数“-S”即可解决问题,如:mysql -S/var/lib/mysql/mysql.sock -uroot -p(坑爹的MySQL-5.7.12,默认参数各种不一致)。
8)
mysqld: Table 'mysql.plugin' doesn't exist
2016-05-18T03:33:56.235882Z 0 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
可以使用“bin/mysqld –initialize –user=mysql –explicit_defaults_for_timestamp”重做下初始化,即可解决。
9)
2016-05-18T03:41:02.970764Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
办法同上。
10)
2016-05-18T03:44:42.731483Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
执行“bin/mysqld –initialize –user=mysql –explicit_defaults_for_timestamp”时报的错误,解决办法是清空data目录后再执行。