linux(wsl2 ubuntu) mariadb重置密码

可用于不知道默认密码或忘记密码等场景

操作环境是WSL2版本 ubuntu22

  1. 停止MariaDB服务

 

sudo service mariadb stop 

2. 在不加载授权表的情况下启动 MariaDB 服务

sudo mysqld_safe --skip-grant-tables &

3.使用root用户登录,无需密码

mysql -u root

 

 

 4.使用下面两个命令为root用户重新设置密码(自行替换new_password

FLUSH PRIVILEGES;
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');

5.使用Ctal+c或者exit;退出编辑

exit;

6.停止mysqld_safe进程

sudo pkill mysqld_safe

7.重新启动MariaDB服务

sudo service mariadb start

  重启完毕后可以使用mysql -u root -p连接MySQL然后输入刚刚设置的新密码

 

posted @ 2023-03-14 14:42  莫大元帅  阅读(244)  评论(0)    收藏  举报