Modify mysql8.0 password in Linux environment

Since the password function is abolished in versions above mysql8, the mysql password cannot be changed in the previous way. This article is to modify the original password without knowing the original password.

1. Modify mysql configuration to enter without password

修改mysql配置文件my.cnf文件
在mysqld下添加skip-grant-tables
[mysqld]
skip-grant-tables
重启mysql
service mysqld restart

2. Enter mysql to clear the data

这个时候不需要密码,直接可以进入,执行以下修改数据库
use mysql;
update user set authentication_string = ''  where user='root' ;
exit;

3. Reset password

修改mysql配置文件my.cnf文件
在mysqld下注释掉skip-grant-tables
[mysqld]
#skip-grant-tables
重启mysql
service mysqld restart
执行完以上还是可以无密码进入,依次执行以下
mysql -u root -p
use mysql
ALTER USER 'root'@'%' IDENTIFIED BY '新的密码';
以上没有报错,证明修改成功

Guess you like

Origin blog.csdn.net/qq_41526316/article/details/108434810