【发布时间】:2021-04-19 18:58:32
【问题描述】:
在执行加粗的 sql 命令时发现未读结果错误。 python 代码位于 docker 容器中,MySQL db 也是如此。截断代码以突出显示问题所在。
import mysql.connector
from datetime import datetime
import requests
import json
import math
import os
import logging
# Use logging.info() to output info to the console
logging.basicConfig(level=logging.INFO)
# Connecting to the MySQL Docker image
cnx = mysql.connector.connect(user='test', password='test', host='db', database='VisualDB')
logging.info(cnx.is_connected())
# Use mycursor for pointing to tables and making queries<br>
mycursor = cnx.cursor()
userRows = mycursor.execute("SELECT * FROM user;")
cnx.commit()
logging.info(userRows)
sensorRows = mycursor.execute("SELECT * FROM SENSOR;")
cnx.commit()
logging.info(sensorRows)
这是我得到的错误:mysql.connector.errors.InternalError: Unread result found
做了一堆评论来确认这些行是问题所在,我有时也会在cnx().commit
我的图像本身有问题吗? mysql:最新
此外,数据库是使用“db”文件夹中指向 sql 文件的 Dockerfile 创建的
提前感谢您提供的任何建议!
【问题讨论】:
标签: python mysql docker mysql-connector pika