pycharm pymysql连接mysql 执行MySQL操作遇到以下报错信息:
conn.query(q)
File "C:\Software\Python37\lib\site-packages\pymysql\connections.py", line 547, in query
self._execute_command(COMMAND.COM_QUERY, sql)
File "C:\Software\Python37\lib\site-packages\pymysql\connections.py", line 793, in _execute_command
raise err.InterfaceError(0, "")
pymysql.err.InterfaceError: (0, '')
查了下资料问题是数据库关闭连接了. 在执行sql语句前加上
db.ping(reconnect=True) # 检查连接是否存在,断开的话会重连。
会在执行sql语句前 检查连接是否存在,断开的话会重连。即可解决问题.