Ubuntu18踩坑系列

霸气de小男生 提交于 2020-02-07 21:54:01

mysql忘记密码
不知道为啥,我用apt-get install 安装mysql,安装直接完成,不会提示输入密码.
搞得装完数据库就得进入忘记密码模式/(ㄒoㄒ)/~~
之前老是百度,累了,征得大佬同意,放一篇转载.
mysql忘记密码踩坑记
关键步骤:
1.进入/etc/mysql/目录,并用root权限打开debian.cnf文件
2.复制账号密码备用([client]下的user 和 password)

[client]
host     = localhost
user     = debian-sys-maint
password = ExL3iUl2zfI5K8p7x

3.使用这个账号密码登入mysql
4.use mysql;
5.查看数据库表结构:desc user;
6. select user,plugin from user;

7.一般来说,authentication_string 字段存储的就是密码,修改 authentication_string 的值即可.但是若结果如上图所示,则增加一句

update user set authentication_string=password("123456"),plugin='mysql_native_password' where user='root';
    update mysql.user set authentication_string=password('123456') where user='root';  
    flush privileges;    //刷新重置
    quit             //退出

8.重启数据库:

service mysql restart 
mysql -u root -p      // 输入密码,登陆成功

搞定.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!