mysql主从设置报错

mysql执行完这句命令后报了下面的错误

change master to master_host='192.168.32.129',master_port=3307,master_user='xiaoming',master_password='Root@123456',master_log_file='mysql-bin.000001',master_log_pos=702;



mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Connecting to source
                  Master_Host: 192.168.32.129
                  Master_User: xiaoming
                  Master_Port: 3307
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 702
               Relay_Log_File: localhost-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Connecting
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 702
              Relay_Log_Space: 157
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 2061
                Last_IO_Error: Error connecting to source 'xiaoming@192.168.32.129:3307'. This was attempt 3/86400, with a delay of 60 seconds between attempts. Message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 0
                  Master_UUID: 
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Replica has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 230725 18:05:09
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
       Master_public_key_path: 
        Get_master_public_key: 0
            Network_Namespace: 
1 row in set, 1 warning (0.00 sec)

ERROR: 
No query specified

请问这是什么问题

这个错误提示说明在连接到主服务器时遇到了身份验证问题。具体来说,这是因为在MySQL 8.0版本及以上,使用了新的默认身份验证插件"caching_sha2_password",而该插件要求使用安全连接(Secure Connection)才能进行身份验证。

为了解决这个问题,你需要在从服务器上使用SSL/TLS等安全连接方式连接到主服务器,或者修改主服务器上的MySQL配置文件,将默认的身份验证插件改为旧版的插件,例如"mysql_native_password"。具体步骤如下:

  1. 在从服务器上使用SSL/TLS等安全连接方式连接到主服务器。例如,可以在"change master"命令中添加"require ssl"参数,表示需要使用SSL/TLS连接:
change master to master_host='192.168.32.129',master_port=3307,master_user='xiaoming',master_password='Root@123456',master_log_file='mysql-bin.000001',master_log_pos=702,require ssl;
  1. 修改主服务器上的MySQL配置文件,将默认的身份验证插件改为旧版的插件。具体来说,可以在MySQL配置文件中添加以下配置:
[mysqld]
default_authentication_plugin=mysql_native_password

修改完成后,重启MySQL服务使配置生效。

需要注意的是,修改主服务器上的MySQL配置文件可能会影响其他应用程序的正常使用,因此需要谨慎操作。如果不确定如何修改,请咨询数据库管理员或MySQL官方文档。

MySQL 主从同步是一种数据库架构的设计,通过复制主库的数据和DDL操作,从库可以保持与主库数据一致的状态。但是,在使用 MySQL 主从同步时,有时会遇到报错的情况,这会影响到数据库的正常运行。

其中一个常见的报错是“Error 1062: Duplicate entry”,这通常是由于从库上已经存在主库上已经存在的记录,从而导致主从同步失败。如下所示:

mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.100
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 245
Relay_Log_File: mysql-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000001
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.%
Last_Errno: 1062
Last_Error: Error 'Duplicate entry '1001' for key 'PRIMARY'' on query. Default database: 'test'. Query: 'INSERT INTO user (id,name) VALUES (1001,'test')'
Skip_Counter: 0
Exec_Master_Log_Pos: 245
Relay_Log_Space: 154
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1062
Last_SQL_Error: Error 'Duplicate entry '1001' for key 'PRIMARY'' on query. Default database: 'test'. Query: 'INSERT INTO user (id,name) VALUES (1001,'test')''
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_SSL_Path:
Seconds_Behind_Master_2: NULL