How to reset MySQL database password

MySQL is a commonly used relational database management system. When using MySQL, sometimes we may encounter situations where we forget or need to reset the database password. Below we will introduce several commonly used methods to reset MySQL database password.

Method 1: Use the mysqladmin command

  1. First, open a terminal or command prompt and log in to the MySQL server using the following command (a current and valid username and password are required):
mysql -u 用户名 -p
  1. After successfully logging in, enter the following command to change the password (replace新密码 with the new password you want to set):
mysql> ALTER USER '用户名'@'localhost' IDENTIFIED BY '新密码';
  1. If you want to reset the superuser (root) password, you can use the following command:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
  1. After changing the password, use the following command to refresh the permissions:
mysql> FLUSH PRIVILEGES;

Method 2: Use the SET PASSWORD command

  1. Similar to method one, first log in to the MySQL server through the following command:
mysql -u 用户名 -p
  1. After successful login, enter

Guess you like

Origin blog.csdn.net/ZaxfSass/article/details/133262726