背景
MySQL在从服务器执行start slave
命令,启动主从复制功能时报错:
2019-10-30T11:36:56.412700+08:00 2 [ERROR] Slave I/O for channel '': Master command COM_REGISTER_SLAVE failed: Access denied for user 'repl'@'%' (using password: YES) (Errno: 1045), Error_code: 1597
2019-10-30T11:36:56.412723+08:00 2 [ERROR] Slave I/O thread couldn't register on master
解决方法
登陆主服务器,查询复制用户的权限:
mysql> show grants for 'repl'@'%';
+----------------------------------------------+
| Grants for repl@% |
+----------------------------------------------+
| GRANT USAGE SLAVE ON *.* TO 'repl'@'%' |
+----------------------------------------------+
明显权限不对,修改权限如下:
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' identified by '自己用户的密码';
mysql> show grants for 'repl'@'%';
+----------------------------------------------+
| Grants for repl@% |
+----------------------------------------------+
| GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' |
+----------------------------------------------+
当权限显示为REPLICATION
是方才正确。此时,登陆从服务器再次执行start slave
命令即可。