mysql localhost 拒绝_MySQL错误:用户’a’@’localhost’拒绝访问(使用密码:YES)

我使用root帐户创建帐户’a’@’%’.但是当我指定host参数时,我无法使用该帐户连接到

MySQL服务器.我可以在没有-h参数的情况下成功连接.请参阅下面的成绩单.我希望有人可以帮我解释一下.谢谢.

mysql> grant all on *.* to 'a'@'%' identified by a;

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a' at line 1

mysql> grant all on *.* to 'a'@'%' identified by 'a';

Query OK, 0 rows affected (0.00 sec)

mysql> show grants for 'a'@'%';

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

| Grants for a@% |

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

| GRANT ALL PRIVILEGES ON *.* TO 'a'@'%' IDENTIFIED BY PASSWORD '*667F407DE7C6AD07358FA38DAED7828A72014B4E' |

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

1 row in set (0.00 sec)

mysql> exit

Bye

[root@localhost ~]# mysql -h localhost -u a -p

Enter password:

ERROR 1045 (28000): Access denied for user 'a'@'localhost' (using password: YES)

[root@localhost ~]# mysql -h 127.0.0.1 -u a -p

Enter password:

ERROR 1045 (28000): Access denied for user 'a'@'localhost' (using password: YES)

[root@localhost ~]# mysql -u a -p

Enter password:

ERROR 1045 (28000): Access denied for user 'a'@'localhost' (using password: YES)

[root@localhost ~]# mysql -u a

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 20

Server version: 5.5.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

mysql> status

--------------

mysql Ver 14.14 Distrib 5.5.17, for Linux (x86_64) using readline 5.1

Connection id: 20

Current database:

Current user: a@localhost

SSL: Not in use

Current pager: stdout

Using outfile: ''

Using delimiter: ;

Server version: 5.5.17 MySQL Community Server (GPL)

Protocol version: 10

Connection: Localhost via UNIX socket

Server characterset: utf8

Db characterset: utf8

Client characterset: utf8

Conn. characterset: utf8

UNIX socket: /var/lib/mysql/mysql.sock

Uptime: 15 days 15 hours 20 min 18 sec

Threads: 1 Questions: 40 Slow queries: 0 Opens: 41 Flush tables: 1 Open tables: 4 Queries per second avg: 0.000

--------------

mysql>

编辑:

是的,MySQL正在侦听端口3306.

[root@localhost ~]# nmap localhost

Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2012-01-18 07:35 CST

Interesting ports on localhost.localdomain (127.0.0.1):

Not shown: 1674 closed ports

PORT STATE SERVICE

22/tcp open ssh

25/tcp open smtp

111/tcp open rpcbind

631/tcp open ipp

840/tcp open unknown

3306/tcp open mysql

Nmap finished: 1 IP address (1 host up) scanned in 0.064 seconds

[root@localhost ~]#

用户'root'@'localhost'被拒绝访问(使用密码:YES)的错误信息是ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)。这个错误信息有两个关键点需要解析。首先是"Access denied",意味着拒绝访问。其次是"using password: YES",表示使用密码进行访问。\[1\] 解决这个问题的方法有两种。第一种方法是通过修改MySQL用户的host属性来允许用户'root'@'localhost'连接到MySQL服务器。可以使用以下命令来更新用户的host属性:use mysql; update user set host="%" where user='root';\[2\] 第二种方法是通过跳过密码验证来修改密码。首先停止MySQL服务:service mysqld stop,然后使用以下命令跳过密码验证并进入MySQL:/usr/bin/mysqld_safe --skip-grant-tables,接着进入MySQL并修改密码:use mysql; update user set password=PASSWORD("123456") where User='root';最后启动MySQL服务:service mysqld start。这样应该就可以解决访问被拒绝的问题了。\[2\]\[3\] #### 引用[.reference_title] - *1* [错误1045(28000):用户‘root‘@‘localhost‘(使用密码YES拒绝访问](https://blog.csdn.net/wretch_/article/details/114595124)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [错误1045(28000):用户‘root‘@‘localhost‘的访问被拒绝(使用密码:YES)](https://blog.csdn.net/weixin_44725128/article/details/107495730)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值