MySQL does not allow remote access to the solution

  • 2020-05-10 22:59:49
  • OfStack

Solutions:
1. Change table method.
It may be that your account is not allowed to log in remotely from localhost only. At this point, once you have logged into mysql from the localhost computer, change the "host" entry in the "user" form of the "mysql" database from "localhost" to "%".

mysql -u root -pvmwaremysql>use mysql; 
mysql>update user set host = '%' where user = 'root'; 
mysql>select host, user from user; 

2. Authorization.
For example, if you want myuser to connect to the mysql server from any host using mypassword.
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
If you want to allow user myuser to connect to the mysql server from ip's 192.168.1.6 host and use mypassword as the password
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
If you want to allow the user myuser to connect from the ip 192.168.1.6 host to the dk database on the mysql server and use mypassword as the password
GRANT ALL PRIVILEGES ON dk.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
The first method I used, I found at the beginning that I couldn't do it, so I checked the Internet for 1 time and executed 1 statement mysql less > FLUSH RIVILEGES puts the changes into effect. That's it
The other method, which I haven't tried in person, is on csdn.net.
Run on the machine where mysql is installed:
1, d: \ mysql \ bin \ > mysql-h localhost-u root // this should allow access to the MySQL server
2, mysql > GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION // gives any host access to the data
3, mysql > FLUSH PRIVILEGES // amendment effective
4, mysql > EXIT // quit MySQL server
This allows you to log in as root on any other host!

Related articles: