我是CloudSQL的新手,我正在尝试插入40多个不同列和超过150万行的记录。但是我无法在Google CloudSQL中执行此操作。我已经采取了下面列出的许多措施来解决这个问题,但我得到的主要错误是:
ERROR:
textPayload: "2019-04-12T06:10:47.348295Z 8554 [Note] Aborted connection 8554 to db: 'xxxxx_xxx' user: 'root' host: 'x.x.x.x' (Got an error reading communication packets)"
摘要:
PyMySql
将150万行数据插入到35列的表中MySql
错误日志显示了上述内容。我已经尝试了以下行动:
API URL
/ .txt
/ .json
文件上传,而不是使用.csv
。def adddata():
try:
conn = pymysql.connect(unix_socket='/cloudsql/' + 'karto-235001:asia-east1:karto', user='xxx', password='xxx', db='xxx')
cur = conn.cursor()
insert_ = "INSERT INTO data_table(a, b, c) VALUES (%s, %s, %s)"
with open('info.csv', newline='') as myFile:
reader = csv.reader(myFile)
for item in reader:
cur.execute(insert_, (item[3], item[4], item[5]))
conn.commit()
cur.close()
finally:
conn.close()
我已经在线检查并实施了CloudSQL和其他堆栈溢出用户推荐的解决方案。如果有人能够确定我做错了什么,或者我的代码或配置是否有问题?非常感谢你。
我发现你想使用Python上传CSV文件中包含的信息。您是否尝试过直接导入数据库?您可以按照链接[1]中的步骤操作。
与此同时,我会尝试复制你的案子。您还可能想要检查您的安装和配置是否正确。
验证您的Cloud SQL实例和连接[2]以及您的Python安装[3]。
[1]https://cloud.google.com/sql/docs/mysql/import-export/importing#csv
[2]https://cloud.google.com/sql/docs/mysql/connect-compute-engine
[3]https://cloud.google.com/python/setup