ERROR1698(28000):Accessdeniedforuserroot@localhost
| 分类: 常用 |
ERROR 1698 (28000): Access denied for user 'root'@'localhost'安装MySQL时未设置密码,普通用户连接MySQL时需要密码进入的解决办法
1.使用sudo apt-get install
mysql-server安装数据库,在安装的过程中未设置密码。
2.在普通用户下使用命令mysql -uroot
-p连接数据库,由于没有设置密码,所以在需要输入密码的时候,直接按了Enter键,从而导致了错误:ERROR 1698
(28000): Access denied for user 'root'@'localhost'
解决办法:在连接mysql数据库的时候,使用命令sudo mysql -uroot
-p连接数据库,由于没有设置密码,所以在需要输入密码的时候,直接按Enter键。
---------------------
在终端上输入mysql -u root
-p,遇见输入密码的提示直接回车即可,进入mysql后,分别执行下面三句话:
1 use mysql; 然后敲回车 2 update user set authentication_string=password("你的密码") where user="root" 然后敲回车 3 flush privileges 然后敲回车
先选择一个数据库(use mysql),然后输入select
user,plugin from user,看下图:
从图中可以看到在执行了select user,plugin from user后,错误原因是因为plugin root的字段是auth_socket,那我们改掉它为下面的mysql_native_password就行了。输入:
1 update user set authentication_string=password("123456"),plugin='mysql_native_password' where user='root'
然后回车执行以下,再输入select user,plugin from user;回车,我们能看到root用户的字段改成功了。
来源:https://blog.csdn.net/weixin_41115274/article/details/78974472

加载中…