MySQL can be connected locally, but cannot be connected remotely

Use Xshell to connect to the ECS server, enter the database, and use the command
 # mysql -u root -p
 # Enter the mysql login password
 
 . The commands are executed in the mysql environment.
 
 use mysql;
 SELECT user, host from mysql.user;
 //View the permissions of the mysql user host used for remote access, % means that all machines are allowed to access. If the host is 127.0.0.1/localhost, then this user can only access locally, you need to change the host to%
   
update user set host='%' where user='root';

//若输出ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'

//implement

flush privileges;

// check permissions again

SELECT user, host from mysql.user;
   
OK. You can log in remotely!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325119513&siteId=291194637