[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 ...
随机推荐
- 两种解决springboot 跨域问题的方法示例
两种解决springboot 跨域问题的方法示例,哪种方法看情况而定,自己选择.社会Boolean哥,人狠话不多,直接上代码. 第一种实现方式: 此种方式做全局配置,用起来更方便,但是无法 ...
- FTP部署与使用
1.1 环境检查 [root@www ~]# cat /etc/redhat-release #系统版本,6系列等区别不大,都可以 CentOS Linux release 7.5.1804 (Cor ...
- 创建CUDA项目
输出选择X64 .cu文件属性: 常规-项类型:CUDA C/C++ 项目属性: 平台:活动(x64) CUDA C/C++ - Common-Target Machine Platform: 64- ...
- 微信小程序 点击事件 传递参数
wxml: data-参数名="值" bindtap="函数名" <view class="buy-button {{cap_select == ...
- BZOJ1257 [CQOI2007]余数之和[规律]
被zcr和yy轮流嘲讽了一番,感觉自己智商日渐下降...\TヘTツ 先拆mod变成整数除法,然后就是$nk- \Sigma_{i=1}^{n} i * \lfloor \frac{k}{i} \rfl ...
- Acwing-278-数字组合(背包)
链接: https://www.acwing.com/problem/content/280/ 题意: 给定N个正整数A1,A2,-,AN,从中选出若干个数,使它们的和为M,求有多少种选择方案. 思路 ...
- Struts2基本原理【转】
阐述struts2的执行流程. Struts 2框架本身大致可以分为3个部分:核心控制器FilterDispatcher.业务控制器Action和用户实现的企业业务逻辑组件. 核心控制器FilterD ...
- 求两个数的最大公约数和最小公倍数Java(cvte考题)
//最大公约数 最小公倍数 通过测试 public class GongYue{ public static int gongyue(int m, int n) throws Exception{ i ...
- zabbix-server一键部署
最近想写一个zabbix脚本,自己尝试几次,能够实现,但是太糙了,在github上发现一个很好,谢谢作者脚本作者:火星小刘 web:www.huoxingxiaoliu.com email:xtlyk ...
- 学习springboot(三)——springboot+mybatis出现org.apache.ibatis.binding.BindingException: Invalid bound state
有段时间没搭建过了生疏了,记录下出现此情况且你能通过注解的方式正常进行数据库操作,只是通过mapper.xml不行就可以看看这个了.主要问题应该是配置上,不要太自信自己,再仔细找找.1.查看xml是否 ...