mysql忘记root密码
太久没登陆忘记了密码,百度后尝试登陆可行:
1.停止mysql服务
2.修改配置文件,设置skip-grant-tables 选项:
(这个选项导致服务器根本不使用权限系统,从而给每个人以完全访问所有数据库的权利,通过执行 flush privileges 语句,可以让一个正在运行的服务器再次开始使用授权表)
3.无密码登录mysql,修改root用户的密码
4.修改配置文件,删除 skip-grant-tables 选项:
5.重启 mysql 服务
6.使用密码登录
mysql 版本:Server version: 5.7.35-0ubuntu0.18.04.1 (Ubuntu)
1.
service mysql stop
’
2.
cd /etc/mysql/mysql.conf.d
vi mysqld.cnf
在[mysqld]下添加skip-grant-tables,然后保存并退出
3.
重启以后,执行mysql命令进入mysql命令行
[root@master1 ~]# mysql
mysql> alter user root@‘localhost’ identified by ‘新密码’;
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql>
mysql> flush privileges; # 手工加载授权表
mysql> alter user root@‘localhost’ identified by ‘mysql’;
4.
5. service mysql restart
6. mysql -u root -p