开发者社区> 问答> 正文

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

# 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

 

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

 

展开
收起
爱吃鱼的程序员 2020-06-08 13:12:43 943 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

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

    多谢大哥!!!!!!!!

    引用来自“wei2011”的评论

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

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

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

    2020-06-08 13:13:01
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载