# 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
不知道为什么,怎么着都是上边这种情况!!
提示那么明显了,不懂英文也查一下字典或翻译一下很麻烦么?test用户没访问权限...
多谢大哥!!!!!!!!提示那么明显了,不懂英文也查一下字典或翻译一下很麻烦么?test用户没访问权限...
我设置一个全新的root权限的账号都不行,难道还得修改MySQL的配置文件?算了,晚上是是其他数据库。这种错误都是mysql那边报出来的,和你用什么连接没关系。你唯一要关心的就是用户有没有权限,而且可能有ip限制,同一用户可能在这台机器上能访问,在另一台机上就不行。好好检查mysql的权限设置pymysql.err.OperationalError:(1045,"Accessdeniedforuser'test'@'localhost'(usingpassword:YES)")
很明显,就是你用的用户无法访问系统级的数据字典信息
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。