usemysql;4mysql>updateusersetpassword=passworD("test")wher"/> usemysql;4mysql>updateusersetpassword=passworD("test")wher">

Home  >  Article  >  Database  >  How to change mysql password in Linux system

How to change mysql password in Linux system

王林
王林forward
2023-05-27 19:16:571945browse

1. Have the original mysql root password

Method one:

Outside the mysql system, use mysqladmin

 1 mysqladmin -u root -p password "test123"
 2 Enter password: 【输入原来的密码】

Method two:

By logging in to the mysql system

 1 mysql -uroot -p
 2 Enter password: 【输入原来的密码】
 3 mysql>use mysql;
 4 mysql> update user set password=passworD("test") where user='root';
 5 mysql> exit;

Note: If the version of Mysql is 5.7 and above, replace the update statement as follows:

 1 mysql> update user set authentication_string=passworD("test") where user='root';

2. Forgot the original mysql root password

Method 3:

First get the root permissions of the operating system, and then kill the Mysql service or stop it manually. Here I recommend using manual stop;

 1 service mysql stop

Then execute

 1 mysqld_safe --skip-grant-tables &

& means running in the background. If it no longer runs in the background, just open another terminal.

Then log in to MySQL and change the password

 1 mysql
 2 mysql> use mysql;
 3 mysql> UPDATE user SET password=password("test123") WHERE user='root';  
 4 mysql> exit;

Note: If the version of Mysql is 5.7 or above, the update statement is as follows:

 1 mysql> update user set authentication_string=passworD("test") where user='root';

The above is the detailed content of How to change mysql password in Linux system. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete