mysql8 修改root密码

Posted lovedan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql8 修改root密码相关的知识,希望对你有一定的参考价值。

mysql8忘记了root密码,需要修改

步奏:

1. 从/etc/my.cnf 配置文件中加入skip-grant-table后正常登陆,把 localhost和user=root 的 authentication_string设置为空字符串

# systemctl restart mysqld

# mysql -u root -p
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set authentication_string=‘‘ where user=‘root‘;
mysql> select Host,User,authentication_string from user; +-----------+------------------+------------------------------------------------------------------------+ | Host | User | authentication_string | +-----------+------------------+------------------------------------------------------------------------+ | localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | | localhost | root | | +-----------+------------------+------------------------------------------------------------------------+ 4 rows in set (0.00 sec)
mysql> flush privileges;

mysql> exit

2. 把  skip-grant-table 去掉 重启mysql后,这时候 用空字符串可以登录mysql了

# systemctl restart mysqld
# mysql -u root -p
mysql>

 3. 再修改密码

mysql> alter user ‘root‘@‘localhost‘IDENTIFIED BY ‘MyNewPas‘;

mysql> flush privileges;

 修改完成.

 

以上是关于mysql8 修改root密码的主要内容,如果未能解决你的问题,请参考以下文章

MySql8.0修改root密码

MYSQL8.0以上版本ROOT密码报错及修改

mysql8安装后如何修改root密码

Mysql8初始密码查看&修改root用户密码(linux)

mint下apt安装MySQL8.0修改密码

mysql8.0.x跳过权限效验,重置root密码