DEV Community

Sandip Basnet
Sandip Basnet

Posted on

4 4

Remote access of MySQL from CLI

1) Check if remote access is allowed for user:

SELECT User, Host FROM mysql.user;
Enter fullscreen mode Exit fullscreen mode

if user has % (wildcard just as * ) in host then this user can establish connection from anywhere, you can update this wildcard or specific ip as

UPDATE mysql.user SET HOST='%' WHERE User='<your_username>';
Enter fullscreen mode Exit fullscreen mode

and then flush privileges with:

FLUSH PRIVILEGES;
Enter fullscreen mode Exit fullscreen mode

2) If MySQL is installed on a Ubuntu, you will have to access the file at this location: cd /etc/mysql/mysql.conf.d/mysqld.cnf

Open the file and comment the binded-address i.e.

change: bind-address = 127.0.0.1 to: #bind-address = 127.0.0.1 
Enter fullscreen mode Exit fullscreen mode

to bring changes on effect restart the mysql or reboot the system itself:
i.e. restart:

sudo service mysql restart
Enter fullscreen mode Exit fullscreen mode

3) Access from cli:



mysql -u <user_name> -h <host or ip addrsss> -p
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more