读取文件存储到MySQL数据库报 Warning: (1265, “Data truncated for column ‘name’ at row 1”)
import pymysql
db = pymysql.Connection(user='root', password='****', host='127.0.0.1', port=3306, db='test')
cur = db.cursor()
with open('test.txt','r',encoding='utf-8') as f:
data = f.readlines()
for i in data:
one = i.replace('\n','')
sql = 'insert table value (0,"%s","%s");'%(one,'false')
cur.execute(sql)
db.commit()
报**Warning: (1265, “Data truncated for column ‘name’ at row 1”)**错误
通过查阅资料发现:
- 由于定义v_mmi为char(32),因为当初考虑,该值是由md5加密的值,所以长度正好为32。但是没有考虑到,v_mobile、v_mac、v_imei这三者连接后的长度已经超过32字符,所以mySQL显示警告信息“Warning(1265)Data truncated for column ‘v_mmi’ at row 1”,表明数据被截断
- 数据全部存储到mysql中,显示警告信息“Warning(1265)Data truncated for column ‘v_mmi’ at row 1”,表明数据被截断,
后在编译器中发现因为最后一行没有数据,所以全部数据入库后,显示数据被截断