Change Mysql password in Linux system

1. Have the root password of the original myql;

Method 1: 
Use mysqladmin outside the mysql system

mysqladmin -u root -p password " test123 " 
Enter password: [Enter the original password]

Method 2: 
By logging in to the mysql system,

mysql -uroot -p
Enter password: [Enter the original password]
mysql>use mysql;
mysql> update user set password=passworD("test") where user='root';
mysql> exit;    

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

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

2. Forget the root password of the original myql;

Method three:

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

# service mysql stop

then execute

# mysqld_safe --skip-grant-tables &

& means running in the background. If it is no longer running in the background, open another terminal. 
Then log in to MySQL to change the password

# mysql
mysql> use mysql;
mysql> UPDATE user SET password=password("test123") WHERE user='root';   
mysql> exit;   

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

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

Guess you like

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