MySQL reset password under Linux (forgot password also applies)

Step 1: Set to skip the verification of the permission table when logging in

To complete this step, you need to modify the main configuration file /etc/my.cnf, namely:

 vim /etc/my.cnf

After entering the file, you need to add skip-grant-tablesit under the following two lines of code:

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

The result of the addition is shown in the figure below:
mysql

Step 2: Change the password after entering MySQL

 #进入mysql
mysql
#修改root用户密码,该命令适用于MySQL8.0版本及以上
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '新密码';

Step 3: Skip the verification of the permission table when withdrawing login

 vim /etc/my.cnf

After entering the file, delete skip-grant-tablesand save

Step 4: Restart the MySQL service

#方法一
#关闭服务
systemctl stop mysqld
#启动服务
systemctl start mysqld

#方法二
systemctl restart mysqld.service

Note: The Linux system I use is CentOS7.8

Guess you like

Origin blog.csdn.net/qq_42103091/article/details/109055621