python连接mysql服务执行load data异常

问题1:

(1148, u'The used command is not allowed with this MySQL version')
原因:
python 通过load data 导入mysql 数据库时候需要配置connect为 local_infile=1
解决方案:
db = pymysql.connect(hostname, user, password, database, port=port, local_infile=1)

问题2:

命令执行成功,但其实没有导入数据
原因:
pymysql在连接数据库的时候会有一个参数autocommit默认为False,表示执行完SQL语句后是否自动提交到真正的数据库,如果没有设置为True,那么你执行sql过后,是需要显式提交的,即conn.commit()。
解决方案:
db = pymysql.connect(hostname, user, password, database, port=port, local_infile=1, autocommit=True)

你可能感兴趣的:(Python)