[mysql]root用户登录mysql,输入密码后报错:Access denied for user 'root'@'localhost'
问题如下:
wangju@wangju-HP-348-G4:~$ mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
解决办法: 分2步
- 配置mysql不用密码也能登录
- 重新配置mysql用户名密码
首先:配置mysql不用密码也能登录
step1:
使用find全局搜索mysql配置文件
root@wangju-HP-348-G4:/home/wangju# find / -name mysqld.cnf
/etc/mysql/mysql.conf.d/mysqld.cnf
step2:
在mysql的配置文件[mysqld]中加入下面这句话:
skip-grant-tables <-- add here

作用:就是让你可以不用密码登录进去mysql。
step3:
保存修改,重新启动mysql
service mysql restart
step4:
在终端上输入mysql -u root -p,遇见输入密码的提示直接回车即可进入mysql

然后:重新配置mysql用户名密码
step1:
进入mysql后分别执行下面三句话配置root用户密码
use mysql; 然后敲回车
update user set authentication_string=password("你的密码") where user="root"; 然后敲回车
flush privileges; 然后敲回车
结果如下:
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> update user set authentication_string=password("admin123456") where user="root";
Query OK, 1 row affected, 1 warning (0.02 sec)
Rows matched: 2 Changed: 1 Warnings: 1 mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
然后输入quit,退出mysql。
step2:
重新进入到mysqld.cnf文件中去把刚开始加的skip-grant-tables这条语句给注释掉。

再返回终端输入mysql -u root -p,报错:
root@wangju-HP-348-G4:/home/wangju# mysql -u root -p
Enter password:
ERROR 1524 (HY000): Plugin 'auth_socket' is not loaded
再把刚才注释掉的skip-external-locking取消注释,然后重启mysql
执行下面的命令:
use mysql;
#切换数据库 select user,plugin from user;
#查询user表 user列,plugin列的值
#从查询结果可以看出plugin root的字段是auth_socket,把它改为mysql_native_password update user set authentication_string=password("admin123456"),plugin='mysql_native_password' where user='root';
#更新user表plugin root
执行结果:
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed
mysql> select user,plugin from user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| root | auth_socket |
| mysql.session | mysql_native_password |
| mysql.sys | mysql_native_password |
| debian-sys-maint | mysql_native_password |
| root | mysql_native_password |
| tester | mysql_native_password |
+------------------+-----------------------+
6 rows in set (0.00 sec) mysql> update user set authentication_string=password("admin123456"),plugin='mysql_native_password' where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 2 Changed: 1 Warnings: 1
再输入select user,plugin from user;回车,我们能看到root用户的字段改成功了。
mysql> select user,plugin from user;
+------------------+-----------------------+
| user | plugin |
+------------------+-----------------------+
| root | mysql_native_password |
| mysql.session | mysql_native_password |
| mysql.sys | mysql_native_password |
| debian-sys-maint | mysql_native_password |
| root | mysql_native_password |
| tester | mysql_native_password |
+------------------+-----------------------+
6 rows in set (0.00 sec)
step3:
quit退出,再执行step3,重启mysql
结果:
再用mysql -u root -p,回车,输入密码之后,就可以登录成功了
参考文档:
mysql出现ERROR1698(28000):Access denied for user root@localhost错误解决方法
[mysql]root用户登录mysql,输入密码后报错:Access denied for user 'root'@'localhost'的更多相关文章
- linux下mysql登录报错“Access denied for user 'root'@'localhost' (using password: YES”)的处理方法
最近登录某台服务器的mysql时候总报错: Access[root@log01 ~]# mysql -u root -p Enter password: ERROR 1045 (28000): Acc ...
- 网站报错Access denied for user 'root'@'localhost' -问题排查续
网站报错Access denied for user 'root'@'localhost' (using password: YES) 每次的挽救办法就是: /etc/init.d/mysqld st ...
- 运行JavaWeb项目报错Access denied for user 'root'@'localhost' (using password: YES)
问题重现:(以下讨论范围仅限Windows环境): C:\AppServ\MySQL> mysql -u root -p Enter password: ERROR 1045 (28000): ...
- 008-MySQL报错-Access denied for user 'root'@'localhost' (using password: NO)
1.新安装的mysql报错 MySQL报错-Access denied for user 'root'@'localhost' (using password: NO) 解决方案 1.先停掉原来的服务 ...
- mysql登录报错“Access denied for user 'root'@'localhost' (using password: YES”)的处理方法
环境 CentosOS 6.5 ,已安装mysql 情景 root密码忘记,使用普通用户无法登录 解决 问题一 无法使用mysql命令 参考文章:https://www.cnblogs.com/com ...
- MySQL登录报错"Access denied for user 'root'@'localhost' (using password: YES)"
最近登录MySQL时候总报错: # mysql -uroot -p Enter password: ERROR (): Access denied for user 'root'@'localhost ...
- root用户登录mysql后新建用户提示1045错误
执行以下命令查看root权限 show grants for 'root'@'localhost'; 如果没有显示with grant option,说明是root没有拥有新建授权用户的权限(为什么会 ...
- MySQL密码正确却无法本地登录,ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
MySQL密码正确却无法本地登录 报错如下: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password ...
- mysql登录遇到ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
执行mysql -uroot -p,出现如下问题 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using pass ...
随机推荐
- Dedecms 生成速度慢 的解决办法
从dedecms官网论坛找到个合适的代码 include/inc/inc_fun_SpGetArcList.php for($i=0;$i<$ridnum;$i++){ if($tpsql==& ...
- linux内核配置与编译
配置内核:配置硬件和软件需的部分. make config:基于文本模式的交互式配置.(一问一答) make menuconfig:基于文本模式菜单性配置.(直观简单高效) <*>会产生b ...
- 模拟赛小结:The 2019 China Collegiate Programming Contest Harbin Site
比赛链接:传送门 上半场5题,下半场疯狂挂机,然后又是差一题金,万年银首也太难受了. (每次银首都会想起前队友的灵魂拷问:你们队练习的时候进金区的次数多不多啊?) Problem J. Justify ...
- HTTP与TCP的区别和联系(转)
https://www.cnblogs.com/baizhanshi/p/8482612.html
- js/html 判断ie浏览器版本
1.html判断浏览器:<!--[if !IE]><!-->除ie外都可以识别<!--<![endif]--><!--[if IE]>所有ie可以 ...
- 如何理解Hibernate的延迟加载机制?
延迟加载就是并不是在读取的时候就把数据加载进来,而是等到使用时再加载.Hibernate使用了虚拟代理机制实现延迟加载.返回给用户的并不是实体本身,而是实体对象的代理.代理对象在用户调用getter方 ...
- 关于在react里面es6构建类的时候,一些开始的问题
一般来说我们写react代码,个人习惯 这个里面没有constructor和super的,这样写也没啥问题.因为他会默认加上 但是有的时候有人会加上这两个 可以不写constructor,一旦写了co ...
- 【51nod1220】约数之和
题目 d(k)表示k的所有约数的和.d(6) = 1 + 2 + 3 + 6 = 12. 定义S(N) = ∑1<=i<=N ∑1<=j<=N d(i*j). 例如:S(3) ...
- MFC:OnCreate PreCreateWindow PreSubclassWindow
OnCreate PreCreateWindow PreSubclassWindow PreCreateWindow和PreSubclassWindow是虚函数,而OnCreate是一个消息响应函数. ...
- 12、label控件
label可以展示文本.超链接.图片.动图 新建项目Demo526,QMainWindow,勾选ui.将image文件夹(有2个图片)拷贝到项目路径下. [添加图像资源文件] 项目Demo526处,右 ...