我想要使用Python来连接MySQL数据库,但是报了如下错误
File "/usr/local/lib/python3.5/dist-packages/pymysql/__init__.py", line 94, in Connect return Connection(*args, **kwargs) File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 325, in __init__ self.connect() File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 599, in connect self._request_authentication() File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 861, in _request_authentication auth_packet = self._read_packet() File "/usr/local/lib/python3.5/dist-packages/pymysql/connections.py", line 684, in _read_packet packet.check_error() File "/usr/local/lib/python3.5/dist-packages/pymysql/protocol.py", line 220, in check_error err.raise_mysql_exception(self._data) File "/usr/local/lib/python3.5/dist-packages/pymysql/err.py", line 109, in raise_mysql_exception raise errorclass(errno, errval) pymysql.err.InternalError: (1049, "Unknown database 'expert'")
百度结果均告知为未创建相应的数据库导致本错误,但是我已经创建了expert数据库,但仍然提示数据库不存在。
此外,本服务器下的数据库均能正常连接。
这是我的数据库连接代码:
config = { 'host': cf.get("mySql", "host"), 'port': int(cf.get("mySql", "port")), 'user': cf.get("mySql", "user"), 'password': cf.get("mySql", "password"), 'db': cf.get("mySql", "db"), 'charset': cf.get("mySql", "charset") } table_to_save = cf.get("mySql", "save_table") try: con = pymysql.connect(**config) except Exception: con = Exception log_info = "Connection to MySQL has been rejected" print(log_info) os._exit(0)
配置文件为:
[mySql]host=127.0.0.1port=3306user=rootpassword=123456db=expertcharset=utf8
有大佬可以帮忙解决一下吗?
精慕HU
开心每一天1111
相关分类