当前位置:Gxlcms > 数据库问题 > 初次安装mysql时,没有设置初始密码的解决方法

初次安装mysql时,没有设置初始密码的解决方法

时间:2021-07-01 10:21:17 帮助过:148人阅读

apt-get install mysql-server sudo apt install mysql-client sudo apt install libmysqlclient-dev

在ubuntu18.04中安装mysql时,没有提示设置密码,但是登陆的时候又需要密码才能登陆

在网上找了很久,找到了一篇文章:https://blog.csdn.net/qq_38737992/article/details/81090373

首先:

  1. <span style="color: #0000ff;">sudo</span> <span style="color: #0000ff;">cat</span> /etc/mysql/debian.cnf

技术图片

 

 可以看到上面红色箭头指出来的密码

然后登陆:

  1. mysql -u debian-sys-maint -p

登陆输入的密码就是上面的密码

然后修改密码:

  1. <span style="color: #000000;">use mysql;
  2. 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;">;
  3. 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;">;
  4. flush privileges;
  5. quit;</span>

技术图片

 

 最后重启数据库服务:

  1. <span style="color: #0000ff;">sudo</span> service mysql restart

此时,就可以使用自己的密码登陆数据库了。

初次安装mysql时,没有设置初始密码的解决方法

标签:cat   string   sql数据库   get   user   detail   ubuntu   初始密码   main   

人气教程排行