python3连接Mysql错误-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

python3连接Mysql错误

a123456678 2016-07-04 11:56:53 2256

环境:win10-x64/python3.4.3/MySql5.7.10

python连接MySql服务器时,无论使用pymysql还是mysql-connector都无法正常连接,提示 Unknown database

如下

conn = pymysql.connect(user='root', password='password', database='test')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python34\lib\site-packages\pymysql\__init__.py", line 88, in Connect
    return Connection(*args, **kwargs)
  File "C:\Python34\lib\site-packages\pymysql\connections.py", line 678, in __init__
    self.connect()
  File "C:\Python34\lib\site-packages\pymysql\connections.py", line 890, in connect
    self._request_authentication()
  File "C:\Python34\lib\site-packages\pymysql\connections.py", line 1097, in _request_authentication
    auth_packet = self._read_packet()
  File "C:\Python34\lib\site-packages\pymysql\connections.py", line 965, in _read_packet
    packet.check_error()
  File "C:\Python34\lib\site-packages\pymysql\connections.py", line 394, in check_error
    err.raise_mysql_exception(self._data)
  File "C:\Python34\lib\site-packages\pymysql\err.py", line 120, in raise_mysql_exception
    _check_mysql_exception(errinfo)
  File "C:\Python34\lib\site-packages\pymysql\err.py", line 115, in _check_mysql_exception
    raise InternalError(errno, errorvalue)
pymysql.err.InternalError: (1049, "Unknown database 'test'")
conn = mysql.connector.connect(user='root', password='password', database='test')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python34\lib\site-packages\mysql\connector\__init__.py", line 179, in connect
    return MySQLConnection(*args, **kwargs)
  File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 95, in __init__
    self.connect(**kwargs)
  File "C:\Python34\lib\site-packages\mysql\connector\abstracts.py", line 719, in connect
    self._open_connection()
  File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 210, in _open_connection
    self._ssl)
  File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 144, in _do_auth
    self._auth_switch_request(username, password)
  File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 177, in _auth_switch_request
    raise errors.get_exception(packet)
mysql.connector.errors.ProgrammingError: 1049 (42000): Unknown database 'test'
关系型数据库 MySQL Python
分享到
取消 提交回答
全部回答(1)
  • a123456678
    2019-07-17 19:50:37

    pymysql.connect只负责连接数据库,它不会帮你创建数据库的,你要先创建一个
    1049 (42000): Unknown database 'test' 说明你没有test这个数据库
    你手动在mysql里面创建一个再试试

    0 0
数据库
使用钉钉扫一扫加入圈子
+ 订阅

分享数据库前沿,解构实战干货,推动数据库技术变革

推荐文章
相似问题
推荐课程