3

mysql 5.7.18 (both master and slave)

error in slave status

Last_IO_Error: Master command COM_REGISTER_SLAVE failed: Access denied for user 'repl'@'xxx.xxx.xxx.xxx' (using password: YES) (Errno: 1045)

error on master (error.log)

2017-05-29T16:40:39.718290Z 213 [Note] Aborted connection 213 to db: 'unconnected' user: 'repl' host: 'xxx.xxx.xxx.xxx' (Got an error reading communication packets)

connecting from slave to master via mysql client

But if I login from the slave servers command line like this there is no error and the slave connects to the master perfectly. So there must be something in the master-slave configuration thats not right

mysql -h xxx.xxx.xxx.xxx -u repl -pxxxxxxxxxxxx
mysql> show grants;
+--------------------------------------------+
| Grants for repl@xxx.xxx.xxx.xxx            |
+--------------------------------------------+
| GRANT USAGE ON *.* TO 'repl'@'xxx.xxx.xxx.xxx' |
+--------------------------------------------+
1 row in set (0.00 sec)

create replication user on master

CREATE USER 'repl'@'xxx.xxx.xxx.xxx' IDENTIFIED BY 'xxxxx';
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'xxx.xxx.xxx.xxx';
FLUSH PRIVILEGES;

master my.cnf

[mysqld]

# GENERAL #
user                           = mysql
port                           = 3306
default_storage_engine         = InnoDB
pid-file                       = /var/run/mysqld/mysqld.pid
socket                         = /var/run/mysqld/mysqld.sock

# SAFETY #
max_allowed_packet             = 16M
max_connect_errors             = 1000000
skip_name_resolve
sql_mode                       = STRICT_ALL_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO
sysdate_is_now                 = 1
symbolic_links                 = 0

# DATA STORAGE #
datadir                        = /var/lib/mysql/

# BINARY LOGGING #
server_id                      = 1
log_bin                        = /var/lib/mysql/mysql-bin
log_slave_updates
expire_logs_days               = 14
sync_binlog                    = 1
log_bin_trust_function_creators= 1
binlog_format                  = ROW

# REPLICATION #
gtid_mode                      = ON
enforce_gtid_consistency

# CACHES AND LIMITS #
tmp_table_size                 = 64M
max_heap_table_size            = 64M
query_cache_type               = 0
query_cache_size               = 0
max_connections                = 500
thread_cache_size              = 50
open_files_limit               = 65535
table_definition_cache         = 4096
table_open_cache               = 4096
wait_timeout                   = 60

# INNODB #
innodb_flush_method                 = O_DIRECT
innodb_log_files_in_group           = 2
innodb_log_file_size                = 512M
innodb_log_buffer_size              = 64M
innodb_flush_log_at_trx_commit      = 1
innodb_file_per_table               = 1
innodb_buffer_pool_size             = 40G
innodb_buffer_pool_instances        = 12
innodb_autoinc_lock_mode            = 2
innodb_adaptive_hash_index          = 0
innodb_change_buffering             = none

# LOGGING #
log_error                      = /var/lib/mysql/mysql-error.log
log_queries_not_using_indexes  = 1
slow_query_log                 = 1
slow_query_log_file            = /var/lib/mysql/mysql-slow.log
long_query_time                = 1

basedir                        = /usr
tmpdir                         = /tmp
lc_messages_dir                = /usr/share/mysql
explicit_defaults_for_timestamp

slave my.cnf

[mysqld]

# GENERAL #
user                           = mysql
port                           = 3306
default_storage_engine         = InnoDB
pid-file                       = /var/run/mysqld/mysqld.pid
socket                         = /var/run/mysqld/mysqld.sock

# SAFETY #
max_allowed_packet             = 16M
max_connect_errors             = 1000000
skip_name_resolve
sql_mode                       = STRICT_ALL_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO
sysdate_is_now                 = 1
symbolic_links                 = 0

# DATA STORAGE #
datadir                        = /var/lib/mysql/

# BINARY LOGGING #
server_id                      = 2
log_bin                        = /var/lib/mysql/mysql-bin
log_slave_updates
expire_logs_days               = 14
sync_binlog                    = 1
log_bin_trust_function_creators= 1
binlog_format                  = ROW

# REPLICATION #
gtid_mode                      = ON
enforce_gtid_consistency

# CACHES AND LIMITS #
tmp_table_size                 = 64M
max_heap_table_size            = 64M
query_cache_type               = 0
query_cache_size               = 0
max_connections                = 500
thread_cache_size              = 50
open_files_limit               = 65535
table_definition_cache         = 4096
table_open_cache               = 4096
wait_timeout                   = 60

# INNODB #
innodb_flush_method                 = O_DIRECT
innodb_log_files_in_group           = 2
innodb_log_file_size                = 512M
innodb_log_buffer_size              = 64M
innodb_flush_log_at_trx_commit      = 1
innodb_file_per_table               = 1
innodb_buffer_pool_size             = 12G
innodb_buffer_pool_instances        = 8
innodb_autoinc_lock_mode            = 2
innodb_adaptive_hash_index          = 0
innodb_change_buffering             = none

# LOGGING #
log_error                      = /var/lib/mysql/mysql-error.log
log_queries_not_using_indexes  = 1
slow_query_log                 = 1
slow_query_log_file            = /var/lib/mysql/mysql-slow.log
long_query_time                = 1

basedir                        = /usr
tmpdir                         = /tmp
lc_messages_dir                = /usr/share/mysql
explicit_defaults_for_timestamp

master status

show master status\G;
*************************** 1. row ***************************
             File: mysql-bin.000005
         Position: 194
     Binlog_Do_DB:
 Binlog_Ignore_DB:
Executed_Gtid_Set: e4e90c71-4264-11e7-b970-4061862b8d34:1-12803
1 row in set (0.00 sec)

slave status

show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting to reconnect after a failed registration on master
                  Master_Host: xxx.xxx.xxx.xxx
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: Worker-Intel-i7-2600-16gb-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File:
             Slave_IO_Running: Connecting
            Slave_SQL_Running: Yes
          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: 0
              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: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 1130
                Last_IO_Error: Master command COM_REGISTER_SLAVE failed: Access denied for user 'repl'@'176.9.137.3' (using password: YES) (Errno: 1045)
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 0
                  Master_UUID:
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp: 170529 17:24:04
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set: 8976078a-40a0-11e7-8043-c8600054b161:1-1085
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)

start/setup slave

# mysql -u root -pxxxxxxxxxxx
# stop slave;
# CHANGE MASTER TO 
# MASTER_HOST = 'xxx.xxx.xxx.xxx',
# MASTER_PORT = 3306,
# MASTER_USER = 'repl',
# MASTER_PASSWORD = 'xxxxxxxxxxxxx',
# MASTER_AUTO_POSITION = 1;
# start slave;
# show slave status\G;
  • Have you opened the firewall ports? – Philᵀᴹ May 29 '17 at 15:31
  • What do you mean? – clarkk May 29 '17 at 15:49
  • The servers are located at hetzner so that should not be needed – clarkk May 29 '17 at 15:50
  • What does the GRANT for repl look like? Did the IP address change? – Rick James May 29 '17 at 20:11
  • Its stated in the bottom of the question.. have updated the question.. If I try to connect to the master from the slave with the repl user I get no errors... – clarkk May 29 '17 at 20:19
4

Clark you mentioned USAGE only as the grants applied you also need REPLICATION SLAVE.

mysql> show grants;
+--------------------------------------------+
| Grants for repl@xxx.xxx.xxx.xxx            |
+--------------------------------------------+
| GRANT USAGE ON *.* TO 'repl'@'xxx.xxx.xxx.xxx' |
+--------------------------------------------+
1 row in set (0.00 sec)

If usage means you can only connect to the DB Server and not anything else. Whereas in this case REPLICATION SLAVE will require to read and pull binlog events from Master.

To Fix this:

On Master Execute:

GRANT REPLICATION SLAVE ON *.* TO 'repl'@'xxx.xxx.xxx.xxx' identified by 'xxxxx';

flush privileges;

[difference this time is you are granting with the password for REPLICATION SLAVE GRANT]

Show Grants:

If you do show grants; after you give GRANT REPLICATION command. You should get below grants from same slave host via CLI.

mysql> show grants;
+-------------------------------------------------------------------------------+
| Grants for repl@xxx.xxx.xxx.xxx                                                              |
+-------------------------------------------------------------------------------+
| GRANT REPLICATION SLAVE ON *.* TO repl@xxx.xxx.xxx.xxx  IDENTIFIED BY PASSWORD <secret> |
+-------------------------------------------------------------------------------+
1 row in set (0.03 sec)

mysql>
  • I already have run this CREATE USER 'repl'@'176.9.xxx.xxx' IDENTIFIED BY 'slave_pass'; GRANT REPLICATION SLAVE ON *.* TO 'repl'@'176.9.xxx.xxx'; on master – clarkk May 31 '17 at 9:33
  • but I don't see that in show grants. can you execute GRANT REPLICATION SLAVE ON . TO 'repl'@'xxx.xxx.xxx.xxx' identified by 'xxxxx'; and let me know about show grants ? – Mannoj May 31 '17 at 9:47
  • strange now I get ERROR 1045 (28000): Access denied for user 'root'@'localhost' when trying to execute the statement from root user.. When I look into mysql.user all columns is set to Y on root – clarkk May 31 '17 at 9:50
  • have also tried to service mysql restart but still get the error when trying to grant privileges to repl from root – clarkk May 31 '17 at 9:57
  • So you mean to say you can't login to master as root which you were able to before? – Mannoj May 31 '17 at 9:59
1

Sounds like a password issue. 1045 Does your password have the # character? remove it Is your password longer than 32 characters? shorten it

See TROUBLESHOOTING MYSQL REPLICATION ERROR 1045

  • If I login via mysql client from the slave it works like mysql -h xxx.xxx.xxx.xxx -u repl -pxxxxxxxxxxxx – clarkk May 30 '17 at 8:36
  • the password has 16 chars – clarkk May 30 '17 at 8:38
  • can you do show grants after you login from slave client ? – Mannoj May 30 '17 at 9:34
  • @Mannoj Yes.. Have updated my question.. It looks right – clarkk May 30 '17 at 10:13
  • GRANT USAGE ON *.* TO 'repl'@'xxx.xxx.xxx.xxx' – clarkk May 30 '17 at 10:17
0

This is not the correct solution to the problem (the error code is really different), but I'll leave it, as I wasted lot of time searching for a solution to this problem. The answer might be useful to somebody after all.


I had similar case with error in the slave log file

error connecting to master '...' - retry-time: 60  retries: 12, Error_code: 3159

The problem was that the master required secure connection. Starting the slave with

Master_SSL_Allowed  Yes

Fixed my problems

  • This is a different error code. I don't think this is a valid answer in response to the question. – hot2use Jul 26 '18 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.