linux下mysql密码忘记解决办法
- 将停掉mysql服务
sudo service mysql stop
- 将mysql切换为免密码登录状态
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
#添加
skip-grant-tables
- 重启mysql服务
sudo service mysql start
- 进入mysql
mysql -uroot
- 修改密码
#直接修改密码如果报
#ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
#可以先
flush privileges
#修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';
- 取消免密登录
拿掉
skip-grant-tables
- 重启服务
sudo service mysql restart