我对mysql连接器python还比较陌生。我正在学习如何使用python使我的工作更轻松一些。你能帮忙吗?在
我有一个数据库桌子。让我们称之为“table1”表由如下列组成:
sent_time | delivered_time |id1_active |id2_active |id3_active |id1_inactive |id2_inactive |id3_inactive |location_active |location_inactive….`更多
假设这是两个或两个以上的客户在彼此之间传递货物。每个客户都有三个身份证
现在我想看看我是否能至少打印出所有的id1_active和id2_active…理想情况下,我想打印所有列中提到的特定id的整行…你能看看下面我做错了什么,也许能帮我找到一个理想目标的解决方案吗?在
我总是犯这个错误line 18, in
c.writerow([id1_active,id2_active] )
TypeError: ‘str’ does not support the buffer interface
这就是我目前所拥有的
我创造了一个'配置.ini“文件让我的生活轻松一点[mysql]
host = localhost
database = db_name
user = root
password = blahblah
我创建了一个“python_mysql”_数据库配置.py'
^{pr2}$
然后我创造了导出.py'from mysql.connector import MySQLConnection, Error
from python_mysql_dbconfig import read_db_config
import csv
filename=open(‘test.csv’,’wb’)
c=csv.writer(filename)
db_config = read_db_config()
conn = MySQLConnection(**db_config)
cursor = conn.cursor()
query = (“SELECT id1_active, id2_active from table1”)
cursor.execute(query)
for id1_active, id2_active in cursor:
c.writerow([id1_active,id2_active] )
cursor.close()
filename.close()
cnn.close()
你能告诉我我做错了什么吗?在