Mysql remote connection ubuntu

For a remote database setup since MySQL must be able to listen for an external IP address where the server can be reached. To enable this, open up your mysqld.cnf file:

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

It will look like this:

. . .
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
. . .

By default, this value is set to 127.0.0.1, meaning that the server will only look for local connections. You will need to change this directive to reference an external IP address. For the purposes of troubleshooting, you could set this directive to a wildcard IP address, either *::, or 0.0.0.0:

. . .
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address =
0.0.0.0

. . .

 

Then restart the MySQL service to put the changes you made to mysqld.cnf:

sudo systemctl restart mysql

 

To change a user’s host exists, you can use MySQL’s RENAME USER command:

RENAME USER 'exist_acc'@'localhost' TO 'exist_acc'@'%';

Or create new account, you can use MySQL’s Create USER command:

CREATE USER ‘new_acc’@’%’ IDENTIFIED BY ‘password’;

Grant All Privileges on the database:

GRANT ALL PRIVILEGES ON new_acc.* TO ‘auction’@’%’;

Saving Your Changes:
 
FLUSH PRIVILEGES;

Then restart the MySQL service to put the changes you made to mysqld.cnf:

sudo systemctl restart mysql

Done <3

Leave a Reply

Your email address will not be published. Required fields are marked *