Python 3.6.1 MySQL pymysql连接总是报错!!愤怒了!!

J_sky 发布于 2017/06/29 09:15
阅读 2K+
收藏 1
# coding=utf8

import pymysql

conn = pymysql.Connect(host='127.0.0.1', port=3306, user='test', passwd='8888aaaa', db='test', charset='UTF8')
cur = conn.cursor()
cur.execute("select version()")
for i in cur:
    print(i)
cur.close()

运行报错如下:

Traceback (most recent call last):
  File "/Users/mac/PycharmProjects/PythonTest/mysql/MySQLtest.py", line 5, in <module>
    conn = pymysql.Connect(host='127.0.0.1', port=3306, user='test', passwd='8888aaaa', db='test', charset='UTF8')
  File "/Users/mac/Library/Python/3.6/lib/python/site-packages/pymysql/__init__.py", line 90, in Connect
    return Connection(*args, **kwargs)
  File "/Users/mac/Library/Python/3.6/lib/python/site-packages/pymysql/connections.py", line 706, in __init__
    self.connect()
  File "/Users/mac/Library/Python/3.6/lib/python/site-packages/pymysql/connections.py", line 932, in connect
    self._request_authentication()
  File "/Users/mac/Library/Python/3.6/lib/python/site-packages/pymysql/connections.py", line 1152, in _request_authentication
    auth_packet = self._read_packet()
  File "/Users/mac/Library/Python/3.6/lib/python/site-packages/pymysql/connections.py", line 1014, in _read_packet
    packet.check_error()
  File "/Users/mac/Library/Python/3.6/lib/python/site-packages/pymysql/connections.py", line 393, in check_error
    err.raise_mysql_exception(self._data)
  File "/Users/mac/Library/Python/3.6/lib/python/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1045, "Access denied for user 'test'@'localhost' (using password: YES)")

系统配置:

Python 3.6.1 数据库连接用的 pymysql

PyCharm Community Edition 2017.1.4
Build #PC-171.4694.38, built on June 13, 2017
JRE: 1.8.0_112-release-736-b21 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Mac OS X 10.11.6

MySQL 5.6.30

 

不知道为什么,怎么着都是上边这种情况!!

 

加载中
1
wei2011
wei2011

提示那么明显了,不懂英文也查一下字典或翻译一下很麻烦么?test用户没访问权限...

J_sky
J_sky
多谢大哥!!!!!!!!
0
J_sky
J_sky

引用来自“wei2011”的评论

提示那么明显了,不懂英文也查一下字典或翻译一下很麻烦么?test用户没访问权限...

我测试了一下,只能用root帐户,其它账户,我换了好几个了,我确定帐号权限都正常的,因为用其它方法都能查到数据的,但在PY里就是不行,一直提示这种错误 ,只有root帐号可以正常使用。

J_sky
J_sky
我设置一个全新的root权限的账号都不行,难道还得修改MySQL的配置文件?算了,晚上是是其他数据库。
wei2011
wei2011
这种错误都是mysql那边报出来的,和你用什么连接没关系。你唯一要关心的就是用户有没有权限,而且可能有ip限制,同一用户可能在这台机器上能访问,在另一台机上就不行。好好检查mysql的权限设置
0
Feng_Yu
Feng_Yu
pymysql.err.OperationalError: (1045, "Access denied for user 'test'@'localhost' (using password: YES)")
0
hzajie
hzajie

很明显,就是你用的用户无法访问系统级的数据字典信息

返回顶部
顶部