centos-mysql忘记登录密码
1、说明:
本例的操作系统是centos7,mysql是5.7的版本,可能不同版本的命令稍有不同,可以自行根据系统版本查询相关命令。
2、在启动mysql时不启动授权表功能,可以直接免密码登录
3、修改/etc/my.cnf文件
vim /etc/my.cnf
#在[mysqld]区域添加配置,并保存my.cnf文件
skip-grant-tables
注:将密码修改完后将此条命令注释掉或删掉
4、重启mysql
systemctl restart mysqld
5、登录mysql
mysql -u root -p
6、如果出现输入密码,直接回车,就可以进入数据库了
7、update mysql.user set authentication_string=password('密码') where user='root' ;
注:mysql5.7更改密码应该采用命令
set PASSWORD = PASSWORD('密码');
8、刷新
flush privileges;
9、给用户授权
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
10、刷新