时间:2021-07-01 10:21:17 帮助过:148人阅读
在ubuntu18.04中安装mysql时,没有提示设置密码,但是登陆的时候又需要密码才能登陆
在网上找了很久,找到了一篇文章:https://blog.csdn.net/qq_38737992/article/details/81090373
首先:
- <span style="color: #0000ff;">sudo</span> <span style="color: #0000ff;">cat</span> /etc/mysql/debian.cnf
可以看到上面红色箭头指出来的密码
然后登陆:
- mysql -u debian-sys-maint -p
登陆输入的密码就是上面的密码
然后修改密码:
- <span style="color: #000000;">use mysql;
- update mysql.user set authentication_string</span>=password(<span style="color: #800000;">‘</span><span style="color: #800000;">root</span><span style="color: #800000;">‘</span>) where user=<span style="color: #800000;">‘</span><span style="color: #800000;">root</span><span style="color: #800000;">‘</span> and Host =<span style="color: #800000;">‘</span><span style="color: #800000;">localhost</span><span style="color: #800000;">‘</span><span style="color: #000000;">;
- update user set plugin</span>=<span style="color: #800000;">"</span><span style="color: #800000;">mysql_native_password</span><span style="color: #800000;">"</span><span style="color: #000000;">;
- flush privileges;
- quit;</span>
最后重启数据库服务:
- <span style="color: #0000ff;">sudo</span> service mysql restart
此时,就可以使用自己的密码登陆数据库了。
初次安装mysql时,没有设置初始密码的解决方法
标签:cat string sql数据库 get user detail ubuntu 初始密码 main