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.
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
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 | ±----------±----------+
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 | ±----------±----------+
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
At this point, you can retry the connection through the root user.
Finally, attach an example picture:
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!