Practical operation method of mysql allowing external network access and modifying mysql account password

  • 2021-12-11 19:19:12
  • OfStack

root account of mysql, I usually use localhost or 127.0. 0.1 when connecting, and mysql on the company's test server is also localhost, so I want to access it, so the test is suspended.

The solution is as follows:

1. Modify the table, log in to mysql database, switch to mysql database, and use sql statement to view "select host, user from user; "


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

Note: The last sentence is important for the modification to take effect. If it is not written, remote connection cannot be made.

2. Authorized user, you want root to use password to connect to mysql server from any host


GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'admin123' WITH GRANT OPTION;
flush privileges;

If you want to allow user root to connect to mysql server from host with ip 192.168. 1.104


GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.104'  IDENTIFIED BY 'admin123' WITH GRANT OPTION;
flush privileges;

Modify MySql password

The password field in MySQL 5.7 has been deleted from the mysql. user table and the new field name is "authenticalion_string".

Select a database:


use mysql;

Update the password for root:


update user set authentication_string=password(' New password ') where user='root' and Host='localhost';

Refresh permissions:


flush privileges;

Related articles: