The followingArticleThis article mainly introduces the actual operation process for achieving MySQL remote connection.CodeTo introduce the specific operation steps for MySQL remote connection, the following is the main content of the article, I hope to provide you with some help in this regard.
1. Go to MySQL and create a new user root with the password root:
Format: grant permission on database name. Table name to user @ login host identified by "User Password ";
1. Grant select, update, insert, delete on *. * To root@192.168.1.12 identified by "root ";
Original data table structure
1. mysql> use MySQL;
2. Database changed
3. mysql> select host, user, password from user;
4. + ----------- + ------ + --------------------------------------------- +
5. | host | user | password |
6. + ----------- + ------ + --------------------------------------------- +
7. | localhost | root | * 81f5e21e35407d884a6cd4a731aebfb6af209e1b |
8. + ----------- + ------ + --------------------------------------------- +
Result After executing the preceding statement
1. mysql> use MySQL;
2. Database changed
3. mysql> select host, user, password from user;
4. + -------------- + ------ + --------------------------------------------- +
5. | host | user | password |
6. + -------------- + ------ + --------------------------------------------- +
7. | localhost | root | * 81f5e21e35407d884a6cd4a731aebfb6af209e1b |
8. | 192.168.1.12 | root | * 81f5e21e35407d884a6cd4a731aebfb6af209e1b |
9. + -------------- + ------ + --------------------------------------------- +
0.00 rows in SET (SEC)
You can see that the root user you just created already exists in the User table. The Host field indicates the host to log on to. The value can be an IP address or a host name,
(1) If you want to log on with a local IP address, you can change the host value to your own IP address.
2. Implement MySQL remote connection (authorization)
Changing the value of the Host field to % indicates that you can log on to the MySQL server as a root user on any client machine. We recommend that you set the value to % during development.
1. update user set host = '%' where user = 'root'; change the permission to all privileges.
1. mysql> use MySQL;
2. Database changed
3. mysql> grant all privileges on *. * to root @ '%' identified by "root ";
4. query OK, 0 rows affected (0.00 Sec)
5. mysql> select host, user, password from user;
6. + -------------- + ------ + --------------------------------------------- +
7. | host | user | password |
8. + -------------- + ------ + --------------------------------------------- +
9. | localhost | root | * 81f5e21e35407d884a6cd4a731aebfb6af209e1b |
10. | 192.168.1.12 | root | * 81f5e21e35407d884a6cd4a731aebfb6af209e1b |
11. | % | root | * 81f5e21e35407d884a6cd4a731aebfb6af209e1b |
12. + -------------- + ------ + --------------------------------------------- +
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. Implement MySQL remote connection (change table method)
1. Use MySQL;
2. update user set host = '%' where user = 'root ';
In this way, you can access MySQL through the root user at the remote end.