对于忘了密码这种事再经常不过了。刚装过mysql/mariadb,几天没用,密码忘了怎么办。解决方式如下:


1.查看当前mysql服务是否活着,如果活着先停掉:

ps -ef|grep msql

Centos MySQL/MariaDB root密码重置

如果活着那么先停掉服务:

killall -TERM mysqld

2.停掉之后安全模式启动MySQL

mysqld_safe --skip-grant-tables &

3.再次使用root用户连接,此时密码留空不用输入,直接回车

mysql -u root -p

Centos MySQL/MariaDB root密码重置

4.使用mysql系统库

use mysql;

5.更新root用户密码:

MariaDB [mysql]> update user set password=password("passwordxxx") where user='root';

6.刷新权限:

MariaDB [mysql]> flush privileges;

7.退出安全模式

MariaDB [mysql]> quit


8.重新启动

systemctl start mariadb;

9.使用root用户和新密码连接db:

mysql -u root -p

Centos MySQL/MariaDB root密码重置

至此密码修改完毕!

相关文章:

  • 2021-08-11
  • 2021-05-28
  • 2022-01-05
  • 2021-07-03
  • 2022-12-23
  • 2021-06-19
  • 2021-07-24
猜你喜欢
  • 2021-12-01
  • 2021-06-17
  • 2021-11-02
  • 2022-12-23
  • 2021-10-21
  • 2021-12-02
  • 2022-01-04
相关资源
相似解决方案