Open mysql remote access

Keywords: MySQL Database

  • 1. Log in mysql database

       mysql -u root -p

View user table

mysql> use mysql;
Database changed
mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host         | user | password                                  |
+--------------+------+-------------------------------------------+
| localhost    | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
+--------------+------+-------------------------------------------+
2 rows in set (0.00 sec)

You can see the root user that has been created in the user table. The host field represents the logged in host. Its value can be IP or hostname,

(1) if you want to log in with local IP, you can change the above Host value to your IP.

  • 2. Realize remote connection (authorization law)

Changing the value of host field to% means that you can log in to mysql server as root on any client machine. It is recommended to set it to% during development.    
   update user set host = '%' where user = '-root';

Refresh the database flush privileges;

mysql> use mysql;
Database changed
mysql> grant all privileges  on *.* to root@'%' identified by "password";
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> select host,user,password from user;
+--------------+------+-------------------------------------------+
| host         | user | password                                  |
+--------------+------+-------------------------------------------+
| localhost    | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| 192.168.1.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
| %            | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E |
+--------------+------+-------------------------------------------+
3 rows in set (0.00 sec)

In this way, the machine can remotely access MySql on the machine with the username root password root

  • 3. Realize remote connection (table changing method)
use mysql;

update user set host = '%' where user = 'root';

In this way, Mysql can be accessed remotely through root

Posted by kuk on Tue, 24 Dec 2019 13:26:22 -0800