mysql -uroot -h 127.0.0.1 -P 3308 -p
mysql> show slave status \G
Slave_IO_Running: Connecting
Slave_SQL_Running: Yes
[root@bogon data]# tail -f /opt/mysql-8.0.20/data/mysqld.log
2022-05-12T14:34:32.048865Z 14 [ERROR] [MY-010584] [Repl] Slave I/O for channel '': error connecting to master 'replicator@10.10.10.194:3308' - retry-time: 60 retries: 4 message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection. Error_code: MY-002061
mysql 5.7 默认身份验证插件default_authentication_plugin是:mysql_native_password
mysql 8.0 默认身份验证插件default_authentication_plugin是:caching_sha2_password
CREATE USER 'replicator'@'%' IDENTIFIED WITH caching_sha2_password BY 'myPassword21';
CREATE USER 'replicator'@'%' IDENTIFIED WITH mysql_native_password BY 'myPassword21';
在从库上建立复制关系
mysql> change master to master_host='10.10.10.194', master_port=3308, master_user='replicator', master_password='myPassword21', master_log_file='mysql-bin.000005', master_log_pos= 771, master_connect_retry=60, GET_MASTER_PUBLIC_KEY=1;
说明:
master_host 主服务器地址
master_port 主服务器端口号
master_user 主服务器用于复制的用户
master_password 主服务器用于复制的用户的密码
master_log_file 就是主服务器show master status; 中的 File
master_log_pos 就是主服务器show master status; 中的 Postion
master_connect_retry:如果连接失败,重试的时间间隔,单位是秒,默认是60秒
GET_MASTER_PUBLIC_KEY = {0|1}
此选项适用于使用GET_MASTER_PUBLIC_KEY身份验证插件进行身份验证的副本。对于使用此插件进行身份验证的帐户连接,除非请求,否则源不会发送公钥,因此必须在客户端请求或指定公钥。如果给出了MASTER_PUBLIC_KEY_PATH并指定了有效的公钥文件,则它优先于GET_MASTER_PUBLIC_KEY。如果您使用的复制用户帐户使用caching_sha2_password插件(MySQL 8.0中的默认插件)进行身份验证,并且您没有使用安全连接,则必须指定此选项或MASTER_PUBLIC_KEY_PATH选项,以向复制副本提供RSA公钥。
如果复制用户的身份验证插件是:caching_sha2_password,则需要指定GET_MASTER_PUBLIC_KEY=1;
否则报错:
[root@bogon data]# tail -f /opt/mysql-8.0.20/data/mysqld.log
2022-05-12T14:34:32.048865Z 14 [ERROR] [MY-010584] [Repl] Slave I/O for channel '': error connecting to master 'replicator@10.10.10.194:3308' - retry-time: 60 retries: 4 message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection. Error_code: MY-002061
如果复制用户的身份验证插件是:mysql_native_password,则不需要指定GET_MASTER_PUBLIC_KEY=1;
可选择修改用户的密码(使用的身份验证插件)
ALTER USER 'replicator'@'%' IDENTIFIED WITH mysql_native_password BY 'myPassword21';
ALTER USER 'replicator'@'%' IDENTIFIED WITH caching_sha2_password BY 'myPassword21';
6.4.1.2 Caching SHA-2 Pluggable Authentication,页面搜索GET_MASTER_PUBLIC_KEY
13.4.2.1 CHANGE MASTER TO Statement,页面搜索GET_MASTER_PUBLIC_KEY
如果是组复制
18.6.3.1 Secure User Credentials for Distributed Recovery
18.6.3.1.1 Replication User With The Caching SHA-2 Authentication Plugin
页面搜索:group_replication_recovery_get_public_key
6.4.1.2 Caching SHA-2 Pluggable Authentication
页面搜索:group_replication_recovery_get_public_key
18.9 Group Replication System Variables,
页面搜索:group_replication_recovery_get_public_key