mysql grant 不能登录_MySQL密码正确却无法本地登录

MySQL密码正确却无法本地登录

报错如下:

ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

解决方法:

1、在启动mysql的参数中加入跳过密码问题方式,如下:

vim /etc/my.cnf

并在[mysql]下面加上skip-grant-tables,

这个用于跳过密码问题,但是这并不能彻底解决。

2、重启mysql服务

本人用的是Linux系统的Mysql,语句如下:

查看端口号:

ps aux|grep mysqld

查看状态:

systemctl status mysqld

重启mysql服务

systemctl restart mysqld

尝试连接:

mysql -uroot -p123456

输入密码,刚才已经设置跳过密码了可忽略

操作步骤如下:

[root@localhost ~]# mysql -uroot -p123456

mysql> use mysql

Database changed

mysql> select user,host,password from user where user='root';

+------+-----------------------+-------------------------------------------+

| user | host | password |

+------+-----------------------+-------------------------------------------+

| root | % | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |

| root | localhost.localdomain | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |

| root | 127.0.0.1 | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |

| root | ::1 | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |

+------+-----------------------+-------------------------------------------+

4 rows in set (0.02 sec)

mysql> update user set host='localhost' where user='root' and host='%';

Query OK, 1 row affected (0.01 sec)

Rows matched: 1 Changed: 1 Warnings: 0

mysql> flush privileges;

Query OK, 0 rows affected (0.03 sec)

mysql> quit

Bye

OK,退出mysql,重启mysql就解决问题了

前后对比一下:

[root@localhost ~]# mysql -uroot -p

mysql> use mysql;

Database changed

mysql> select user,host,password from user where user='root';

+------+-----------------------+-------------------------------------------+

| user | host | password |

+------+-----------------------+-------------------------------------------+

| root | localhost | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |

| root | localhost.localdomain | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |

| root | 127.0.0.1 | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |

| root | ::1 | *00A51F3F48415C7D4E8908980D443C29C69B60C9 |

+------+-----------------------+-------------------------------------------+

4 rows in set (0.00 sec)

mysql>

OK!

gook luck!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值