首先,如果mysql不是你自己装的,我们首先要找到配置文件在哪里
which mysql
查找配置文件用如下命令
/usr/bin/mysql --verbose --help | grep -A 1 'Default options'
这个信息的意思是:
服务器首先读取的是/etc/my.cnf文件,如果前一个文件不存在则继续读/etc/mysql/my.cnf文件,如若还不存在便会去读~/.my.cnf文件
修改my.conf
skip-grant-tables
service mysqld restart
use mysql
注意此处不是password而是authentication_string
update user set authentication_string=password('root') where user='root';
刷新权限并退出
flush privileges;
exit
删除my.cnf中增加的skip-grant-tables ,重启mysql,就可以用新设置的密码登录了







网友评论