我是 linux(manjaro) mysql版本 15
1. stop mysql
sudo systemctl stop mysqld
再次登录确保已经关掉服务
2.启动服务with the --skip-grant-tables option.
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables" systemctl restart mysqld
3.登录并修改密码
mysql -uroot set password for 'root'@'localhost' = PASSWORD('newpass');
可能会出现类似错误
ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement
这时候先不管继续执行下面的,命令
mysql>>> flush privileges;
然后再次执行步骤3
退出mysql
exit;
4.重启mysql
sudo systemctl unset-environment MYSQLD_OPTS sudo systemctl start mysqld
5.使用密码测试