Updated on 2023-03-06 GMT+08:00

RDS for MySQL DB Instance Inaccessible

Scenario

When the MySQL client attempted to connect to a database, the following error information is displayed:

  • Fault 1
    ERROR 1045 (28000): Access denied for user 'root'@'192.168.0.30' (using password:YES)
  • Fault 2
    ERROR 1226 (42000): User 'test' has exceeded the 'max_user_connections' resource (current value:10)
  • Fault 3
    ERROR 1129 (HY000): Host '192.168.0.111' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'

Fault 1

  1. Check whether the password of user root is correct.

    ERROR 1045 (28000) is usually caused by an incorrect password so you need to check the password first.

    select password('Test1i@123');
    select host,user,Password from mysql.user where user='test1';

    An incorrect password will cause a login failure as shown in the following figure.

  2. Check whether the ECS or device has the permission to connect to the DB instance.

    select user,host from mysql.user where user='username';

    If you want to log in to the database from another ECS or device, log in to the database as user root and grant the permission to the user.

    For example, if the IP address of the ECS or device is 192.168.0.76, run the following command:

    GRANT all privileges ON test.* TO 'test1'@'192.168.0.76' identified by 'Test1i@123';

    flush privileges;

  3. Check whether the RDS for MySQL client can ping the DB instance VIP and use telnet to check the connection to the port.

    If the ping and telnet operations are successful, ERROR 1045 (28000) is not caused by the DB instance VIP or port.

  4. Check the security group and rules of the DB instance.
  5. Query the user table and check user information.

    The command output indicates that there are two root users.

    When the client is in the network segment 192.168.***.***, RDS for MySQL authenticates the user root@'192.168.%'. However, if the password is root@'%', there will be a login failure. ERROR 1045 (28000) is caused by an invalid password.

    User root@'%' is used for setting a password when you create a DB instance on the RDS console.

Fault 2

  1. Check whether the max_user_connections option is set when you create an RDS for MySQL user, which limits the number of connections.

    select user,host ,max_user_connections from mysql.user where user='test';

    The command output indicates that the connection failed because the max_user_connections option was used.

  2. Increase the maximum number of connections for the user.

    alter user test@'192.168.0.100' with max_user_connections 15

  3. Query the modification result and check whether the database can be connected to.

Fault 3

  1. Check whether the number of failed connection attempts (not caused by incorrect passwords) of the RDS for MySQL client exceeds the value of max_connection_errors.
  2. Log in to the MySQL database as user root and run flush hosts.

    Alternatively, run the following command:

    mysqladmin flush-hosts –u<user> –p<password> -h<ip> -P<port >

  3. Use the MySQL client to connect to the database again.