Home >Database >Mysql Tutorial >How to change the MySQL database password?
Mysql is a relational database. It is often used in daily work. But what should we do when the database is unavailable for a long time or the database password is forgotten under other circumstances?
Here are two solutions for you, guaranteed to better solve your problem. (The following is an example of changing the password under ubuntu)
1. First, enter the console page (enter through ctrl+alt+t under ubuntu, windows Open through the start menu under the system)
2. Enter "mysqld_safe --skip-grant-tablesmysql -u root mysql" in the console, Click on retracement.
3. After that, enter "UPDATE user SET password=PASSWORD("password") WHERE user='root';" (password is New password, you can change it to any password you want to set), the password set in the picture below is 123456.
4. After that, enter "FLUSH PRIVILEGES;" to refresh the update. finished editing.
5. After inputting, click on the backtest, and you will see the information as shown below, indicating that the refresh is successful.
6. Finally, you can use mysql, and the password has been changed to the password you set.
When you know the password/Step 2
1. The following is when you know the password, when you know the password , first enter mysql -u root -p, and then enter the database password to enter the database.
Then enter "use mysql;".
2. Then enter "UPDATE user SET Password = PASSWORD('password') WHERE user = 'root';" (password is the new password, change the password as shown below is 123456)
3. After that, enter "FLUSH PRIVILEGES;" to refresh the update. finished editing.
#4. Finally, when you enter mysql again, you need to enter the newly set password. At the same time, you can see the data under the current database through the (show tables;) command. table information.
Notes
1. All instructions under the database need to be marked with;.
2. If you think this experience is helpful to you, please click the [Thumbs Up] on the left to support it! If you want to browse at any time in the future, please click [Collect] on the right. If you think this experience If it helps you, please click the double arrows at the bottom right of the page to share
The above is the detailed content of How to change the MySQL database password?. For more information, please follow other related articles on the PHP Chinese website!