环境: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'
pymysql.connect只负责连接数据库,它不会帮你创建数据库的,你要先创建一个
1049 (42000): Unknown database 'test' 说明你没有test这个数据库
你手动在mysql里面创建一个再试试
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。