MySQL open remote login

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 created in the user table. The host field represents the logged in host. Its value can be IP or hostname,

Sometimes 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 the host field to% means that you can log in to the MySQL server as root on any client machine

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

Change permissions to ALL 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 change method)

use mysql;

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

In this way, MySQL can be accessed remotely through the root user

Posted by prc on Mon, 25 Nov 2019 07:44:31 -0800