mysql报错:1045, Access denied for user

MySql 码拜 8年前 (2016-02-13) 1558次浏览
MySQL部署在别的机器上
远程登陆MySQL没有问题
mysql -h121.11.11.11 -ucrawler -pcrawler

mysql> show databases;
+--+
| Database              |
+--+
| information_schema      |
| AL                                  |
| cloversoup                     |
| codebar                         |
| mysql                             |
| performance_schema    |
| real_estate_analytics     |
| test                                 |
+--+
8 rows in set (0.00 sec)

查看表什么也可以

mysql> select user,host from mysql.user;
+--+--+
| user     | host      |
+--+--+
| roo   t    | %           |
| crawler | localhost |
| root       | localhost |
+--+--+
3 rows in set (0.00 sec)

权限也是通用的

mysql> show grants;
+--+
| Grants for crawler@localhost                                                                                                              |
+--+
| GRANT ALL PRIVILEGES ON *.* TO "crawler"@"121.11.11.11" IDENTIFIED BY PASSWORD "*A594DECC46D378FDA13D7843740CBF4985E6969B" WITH GRANT OPTION |
+--+
1 row in set (0.00 sec)

但是用Python去连接就会报错

import MySQLdb
import sys
try:
    con = MySQLdb.connect(host = "localhost",user = "crawler",passwd = "crawler", db = "real_estate_analytics")
    #... rest of code ...
except MySQLdb.Error, e:
    print "Error %d: %s" % (e.args[0],e.args[1])
    sys.exit(1)
Error 1045: Access denied for user "crawler"@"localhost" (using password: YES)

问一下这是什么原因?MySQL的配置还是Python模块问题?

解决方案

20

“crawler”@”localhost” 这个用户没有授权

10

host = “localhost”这个localhost是什么ip?
这个”crawler”@”121.11.11.11″和
mysql> select user,host from mysql.user;
+–+–+
| user     | host      |
+–+–+
| roo   t    | %           |
| crawler | localhost |
| root       | localhost |
这个怎么不同?少授权了一个吧

10

mysql的授权除了用户名和密码,还有一个 你登录的主机和ip的限制,就是”crawler”@”localhost” 这个有问题,crawler在机器localhost上登录你的mysql时,是没有权限的。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明mysql报错:1045, Access denied for user
喜欢 (0)
[1034331897@qq.com]
分享 (0)