导致这个错误的原因是通过pymysql连接MySQL,没有关闭连接的操作,所以短时间内不会出问题,长时间保持这个连接会出现连接混乱。虽然看着自己的代码没错,还是会报

pymysql.err.InterfaceError: (0, '')错误。所以这个连接要么连上之后,用完就关闭。要么就用下面的代码,检查连接是否存在,断开的话会重连。

db = pymysql.connect(host='127.0.0.1',port=3306,user='user', passwd='pwd', db='db_name', charset='utf8')
sql = 'select * from table_name'
db.ping(reconnect
=True) cur.execute(sql) db.commit()

结束!

 

相关文章:

  • 2021-11-15
  • 2022-02-13
  • 2021-09-27
  • 2022-12-23
  • 2021-10-07
  • 2021-10-24
猜你喜欢
  • 2022-01-14
  • 2021-10-02
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
  • 2022-02-17
  • 2022-12-23
相关资源
相似解决方案