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

开发者社区> 问答> 正文

python3连接Mysql错误

我的中国 2016-02-08 19:42:37 6109

环境: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 "", line 1, in
File "C:Python34libsite-packagespymysql__init__.py", line 88, in Connect

return Connection(*args, **kwargs)

File "C:Python34libsite-packagespymysqlconnections.py", line 678, in init

self.connect()

File "C:Python34libsite-packagespymysqlconnections.py", line 890, in connect

self._request_authentication()

File "C:Python34libsite-packagespymysqlconnections.py", line 1097, in _request_authentication

auth_packet = self._read_packet()

File "C:Python34libsite-packagespymysqlconnections.py", line 965, in _read_packet

packet.check_error()

File "C:Python34libsite-packagespymysqlconnections.py", line 394, in check_error

err.raise_mysql_exception(self._data)

File "C:Python34libsite-packagespymysqlerr.py", line 120, in raise_mysql_exception

_check_mysql_exception(errinfo)

File "C:Python34libsite-packagespymysqlerr.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 "", line 1, in
File "C:Python34libsite-packagesmysqlconnector__init__.py", line 179, in connect

return MySQLConnection(*args, **kwargs)

File "C:Python34libsite-packagesmysqlconnectorconnection.py", line 95, in init

self.connect(**kwargs)

File "C:Python34libsite-packagesmysqlconnectorabstracts.py", line 719, in connect

self._open_connection()

File "C:Python34libsite-packagesmysqlconnectorconnection.py", line 210, in _open_connection

self._ssl)

File "C:Python34libsite-packagesmysqlconnectorconnection.py", line 144, in _do_auth

self._auth_switch_request(username, password)

File "C:Python34libsite-packagesmysqlconnectorconnection.py", line 177, in _auth_switch_request

raise errors.get_exception(packet)

mysql.connector.errors.ProgrammingError: 1049 (42000): Unknown database 'test'

关系型数据库 MySQL Python
分享到
取消 提交回答
全部回答(1)
  • 我的中国
    2019-07-17 18:28:20

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

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

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

推荐文章
相似问题