[mysql]root用户登录mysql,输入密码后报错:Access denied for user 'root'@'localhost'
2024-10-22 02:38:40
问题如下:
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错误解决方法
最新文章
- 如何解读SQL Server日志(1/3)
- Linux文件管理相关命令
- jquery判断radioButton是否被选中
- imx6 kernel clock
- (C#) Lock - 将对象上锁,互斥多个线程,使同步。
- java读取目录下所有csv文件数据,存入三维数组并返回
- FluentData微型ORM
- php执行效率相关的语句
- 如何关闭UINavigationController 向右滑动 返回上一层视图
- nargin函数的用法
- html5之canvas困惑 在canvas标签内需要设置了宽跟高,如果在css中设置同样的宽跟高,画出来的图像变形了?
- Js判断来访问者的系统
- chrome pyv8下载
- HDU 5612 Baby Ming and Matrix games(DFS)
- 【物联网云端对接-4】通过MQTT协议与百度云进行云端通信
- webpack全局安装
- 利用WSUS部署更新程序
- 【菜鸟学Python】案例一:汇率换算
- 解决Windows下文件在Linux下打开出现乱码的问题
- vmware下centos克隆功能对网络的设置