Home > Database > Mysql Tutorial > How to change mysql password in Linux system

How to change mysql password in Linux system

王林
Release: 2023-05-27 19:16:57
forward
2004 people have browsed it

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: 【输入原来的密码】
Copy after login

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;
Copy after login

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';
Copy after login
Copy after login

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
Copy after login

Then execute

 1 mysqld_safe --skip-grant-tables &
Copy after login

& 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;
Copy after login

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';
Copy after login
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template