Home > Database > Mysql Tutorial > What should I do if mysql cannot connect remotely?

What should I do if mysql cannot connect remotely?

WBOY
Release: 2022-07-01 10:57:15
Original
4238 people have browsed it

Solution: 1. Use "select host,user from user;" to view the root user's connectable host range; 2. Use "update user set host='%' where user='root'; "The host range for modifying the root user's modification permissions is any host; 3. Use "systemctl restart mysqld" to restart the database.

What should I do if mysql cannot connect remotely?

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

What to do if mysql cannot be connected remotely

My analysis and solution steps:

1. Check the root user’s connectable permissions host range

step 1: Log in to the mysql monitor through the command: mysql -uroot -p

step 2.: Enter the password according to the prompts

step 3: Select the mysql database through the command: use mysql;

step 4: Through the command: select host,user from user;

If the interface is as follows, the output is:

±----------±----------+
| host | user |
±----------±----------+
| localhost | mysql.sys |
| localhost | root |
±----------±----------+
Copy after login

From above As can be seen from the picture, the host range of the root user's connectable permissions is localhost. I am here for testing and playing. The IP is not fixed, so I directly open permissions to all hosts.

2. Modify the host range of the root user's connection permissions

#step 5: Modify the host range of the root user's connection permissions to any Host, execute the command: update user set host='%' where user='root';

step 6: Check the root user's connection permissions again: select host,user from user;

The interface will output as follows:

±----------±----------+
| host | user |
±----------±----------+
| % | root |
| localhost | mysql.sys |
±----------±----------+
Copy after login

As you can see from the picture, the host range that the root user can connect to has the "%" symbol, which indicates any host.

3. Restart the database

#step 7: If you still cannot connect to the mysql database remotely after modifying the permissions, you need to restart it. Mysql server, execute the command:

systemctl restart mysqld
Copy after login

At this point, you can retry the connection through the root user.

Finally, attach an example picture:

What should I do if mysql cannot connect remotely?

Recommended learning: mysql video tutorial

The above is the detailed content of What should I do if mysql cannot connect remotely?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template