mysql 访问被拒绝如何解决

经常会发现有很多人出现数据库访问被拒绝的问题,这种情况一般多发于新版的(ubuntu18.04)linux系统上,其他的linux也可能会出现这样的问题,比如deepin(超赞的国产Linux系统),Manjaro系统等,

问题报错如下:

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

这里使用deepin系统进行解决:

1,我们需要进入到mysql数据库中的配置信息里,查看初始的用户名和密码路径为:

/etc/mysql/deban.cnf

2,打开后可以看到初始的数据库用户名和密码:

sudo more deban.cnf

3, 接下来我们就可以通过用户名和密码进入数据库了:

mysql -udebian-sys-maint -pYud65aOMNAS0qTNE

4,接下来我们进入名为mysq的l数据库中,并添加新的用户名和密码:

use mysql;

update mysql.user set authentication_string=password('你要设置的密码') where user='root' and Host ='localhost';

update user set  plugin="mysql_native_password";    

5, 然后刷新数据库,使修改生效,并退出数据库:

flush privileges;

quit;

 6, 最后,我们使用新的数据库的用户名和密码进行登录即可:

 mysql -uroot -pmysql

ok,这样就完成数据库的访问啦!

 

 

Guess you like

Origin blog.csdn.net/James_Nan/article/details/99588119