相对较新的Python和MySQL,但我正在使用MySQL Python Connector在开发环境中执行简单的DB查询。我已经创建了一个缓冲光标来将结果作为字典返回。当我执行简单查询时:
family_query =(“SELECT * FROM family as FF”)
...我得到了一个错误列表,所有这些都是错误2013:错误连接到MySQL服务器。
>python "FitMatch v1.5.py"
Traceback (most recent call last):
File "FitMatch v1.5.py", line 505, in <module>
fit_match_cursor.execute(fit_family_query, () )
File "C:\Python34\lib\site-packages\mysql\connector\cursor.py", line 507, in execute
self._handle_result(self._connection.cmd_query(stmt))
File "C:\Python34\lib\site-packages\mysql\connector\cursor.py", line 421, in _handle_result
self._handle_resultset()
File "C:\Python34\lib\site-packages\mysql\connector\cursor.py", line 895, in _handle_resultset
(self._rows, eof) = self._connection.get_rows()
File "C:\Python34\lib\site-packages\mysql\connector\connection.py", line 671, in get_rows
rows = self._protocol.read_text_result(self._socket, count)
File "C:\Python34\lib\site-packages\mysql\connector\protocol.py", line 309, in read_text_result
packet = sock.recv()
File "C:\Python34\lib\site-packages\mysql\connector\network.py", line 226, in recv_plain
raise errors.InterfaceError(errno=2013)
mysql.connector.errors.InterfaceError: 2013: Lost connection to MySQL server during query
我已经尝试将我的connection_timeout增加到超过10,000(正如我在其他堆栈溢出帖子上看到的那样可能是问题)但它没有效果。
任何可能导致“丢失与MySQL服务器的连接”错误的想法?
答案 0 :(得分:0)
按照我的方式,你切换到PyMySQL,你可以随心所欲地工作
我的示例代码用于打印数据
import pymysql
connection = pymysql.connect(user='XYZ', passwd='XYZ',host='XYZ',database='XYZ')
cursor = connection.cursor()
query = ("YOUR_QUERY")
cursor.execute(query)
for item in cursor:
print item