In this quick article, you will learn how to solve the “ERROR 1130 (HY000): Host x.x.x.x is not allowed to connect to this MySQL server” error in MySQL/MariaDB database deployment on a Linux system. This is one of the common remote database connection errors encountered by users.
Test Environment:
- Application Server IP: 10.24.96.5
- Database Server IP: 10.24.96.6
We encountered the error while testing database connection from one of our app servers to a database server, using the mysql client as shown.
# mysql -u database_username -p -h 10.24.96.6
The error indicates that the host 10.24.96.5 that the database user is connecting from is not allowed to connect to the MySQL server. In this case, we have to make some changes to the database server to enable the user to connect remotely.
On the database server, we have to check the host the user above is allowed to connect from.
# mysql -u root -p
Run the following SQL commands to check the user’s host:
MariaDB [(none)]> SELECT host FROM mysql.user WHERE user = "database_username";
From the output of the command, the user is only allowed to connect to the database server from the localhost. So, we need to update the user’s hosts as follows.
Run the following GRANT command to enable MySQL access for the remote user from a remote host. Make sure to replace “10.24.96.6” with the IP address of the remote system, and “database_password” to the password that you want “database_username” to use:
MariaDB [(none)]> GRANT ALL ON database_name.* to 'database_username'@'10.24.96.5' IDENTIFIED BY 'database_password'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> SELECT host FROM mysql.user WHERE user = "database_username";
To give a user remote access from all host on a network, use the syntax below:
MariaDB [(none)]> GRANT ALL ON database_name.* to 'database_username'@'10.24.96.%' IDENTIFIED BY 'database_password';
After making the above changes, try to remotely connect to the MySQL database server once more. The connection should be successful as shown in the following screenshot.
# mysql -u database_username -p -h 10.24.96.6
We hope this solution helped you in solving your Mysql remote connection error. If have any queries reach us via the feedback form below.
I have been searching the internet and reading dozens of solutions to this problem—none of which worked—and yours is the only one that addressed permissions on the server.
Thank you so much.
Well yes, I can connect now. But I still don’t see any tables on the related database (which I can see when I connect locally).
How can I do these on windows 10?
Thank you for this article.
It was super helpful.
@Promise
Great! Many thanks for the useful feedback.