MySQL報錯 Error_code: 1045

甲骨文技術支援發表於2017-04-21

今天把兩臺機器恢復主從關係後,在slave上執行show slave status,結果中顯示

  1. 2017-04-21T13:46:15.133435Z 8806 [ERROR] Slave I/O for channel '': error connecting to master 'repl@192.168.2.40:3306' - retry-time: 60 retries: 1, Error_code: 1045


首先檢視slave的錯誤日誌檔案,和上面的錯誤一樣

接著用perror檢視上一部獲得的錯誤程式碼:


  1. [root@iZ2ze5ifr62amhrpcnpn9yZ mysql]# perror 1045
  2. MySQL error code 1045 (ER_ACCESS_DENIED_ERROR): Access denied for user '%-.48s'@'%-.64s' (using password: %s)


有可能是複製用的賬戶存在問題,先在MASTER上確認複製使用者賬戶是否存在且是否賦了正確的許可權


  1. mysql> show grants for repl@192.168.2.41;
  2. +---------------------------------------------------------+
  3. | Grants for repl@192.168.2.41 |
  4. +---------------------------------------------------------+
  5. | GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.2.41' |
  6. +---------------------------------------------------------+
  7. 1 row in set (0.00 sec)
發現沒有問題,試著從master使用該賬戶連線至slave,果然沒連上



  1. [root@iZ2ze5ifr62amhrpcnpn9yZ ~]# mysql -urepl -h 192.168.2.40 -p -P3306
  2. Enter password:
  3. ERROR 1045 (28000): Access denied for user 'repl'@'192.168.2.40' (using password: YES)
之前的密碼可能不對,修改一個新的密碼

  1. mysql> update mysql.user set authentication_string=PASSWORD('REPLsafe!@#$41') where User='repl' and host='192.168.2.41';
  2. Query OK, 1 row affected, 1 warning (0.00 sec)
  3. Rows matched: 1 Changed: 1 Warnings: 1

  4. mysql> commit;
  5. Query OK, 0 rows affected (0.00 sec)

  6. mysql> flush privileges;
  7. Query OK, 0 rows affected (0.00 sec)
試著用新的密碼重建複製關係,問題解決。



  1. mysql> stop slave;
  2. Query OK, 0 rows affected (0.01 sec)

  3. mysql> change master to
  4.     -> master_host='192.168.2.40',
  5.     -> master_port=3306,
  6.     -> master_user='repl',
  7.     -> master_password='REPLsafe!@#$41',
  8.     -> master_log_file='bin.000043',
  9.     -> master_log_pos=799072709;
  10. Query OK, 0 rows affected, 2 warnings (0.05 sec)

  11. mysql> start slave;
  12. Query OK, 0 rows affected (0.01 sec)

  13. mysql> show slave status \G;
  14. *************************** 1. row ***************************
  15.                Slave_IO_State: Waiting for master to send event
  16.                   Master_Host: 192.168.2.40
  17.                   Master_User: repl
  18.                   Master_Port: 3306
  19.                 Connect_Retry: 60
  20.               Master_Log_File: bin.000043
  21.           Read_Master_Log_Pos: 854716379
  22.                Relay_Log_File: relay.000002
  23.                 Relay_Log_Pos: 1135224
  24.         Relay_Master_Log_File: bin.000043
  25.              Slave_IO_Running: Yes
  26.             Slave_SQL_Running: Yes
  27.               Replicate_Do_DB:
  28.           Replicate_Ignore_DB: cus_DEMO,cus_DEMO_0413,cus_DEMO_0414,cus_DEMO_0418
  29.            Replicate_Do_Table:
  30.        Replicate_Ignore_Table:
  31.       Replicate_Wild_Do_Table:
  32.   Replicate_Wild_Ignore_Table:
  33.                    Last_Errno: 0
  34.                    Last_Error:
  35.                  Skip_Counter: 0
  36.           Exec_Master_Log_Pos: 800207619
  37.               Relay_Log_Space: 55644221
  38.               Until_Condition: None
  39.                Until_Log_File:
  40.                 Until_Log_Pos: 0
  41.            Master_SSL_Allowed: No
  42.            Master_SSL_CA_File:
  43.            Master_SSL_CA_Path:
  44.               Master_SSL_Cert:
  45.             Master_SSL_Cipher:
  46.                Master_SSL_Key:
  47.         Seconds_Behind_Master: 18559
  48. Master_SSL_Verify_Server_Cert: No
  49.                 Last_IO_Errno: 0
  50.                 Last_IO_Error:
  51.                Last_SQL_Errno: 0
  52.                Last_SQL_Error:
  53.   Replicate_Ignore_Server_Ids:
  54.              Master_Server_Id: 40
  55.                   Master_UUID: 1b00b716-cf6a-11e6-b66e-00163e320583
  56.              Master_Info_File: mysql.slave_master_info
  57.                     SQL_Delay: 0
  58.           SQL_Remaining_Delay: NULL
  59.       Slave_SQL_Running_State: System lock
  60.            Master_Retry_Count: 86400
  61.                   Master_Bind:
  62.       Last_IO_Error_Timestamp:
  63.      Last_SQL_Error_Timestamp:
  64.                Master_SSL_Crl:
  65.            Master_SSL_Crlpath:
  66.            Retrieved_Gtid_Set: 1b00b716-cf6a-11e6-b66e-00163e320583:34573831-34680957
  67.             Executed_Gtid_Set: 1b00b716-cf6a-11e6-b66e-00163e320583:1-33612321:34573831-34620341
  68.                 Auto_Position: 0
  69.          Replicate_Rewrite_DB:
  70.                  Channel_Name:
  71.            Master_TLS_Version:
  72. 1 row in set (0.00 sec)


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/20893244/viewspace-2137789/,如需轉載,請註明出處,否則將追究法律責任。

相關文章