带有位置子句的pymysql SELECT

时间:2018-12-03 18:47:47

标签: python mysql pandas sqlalchemy pymysql

我正在尝试将MySql View导出到CSV文件

这是我的代码

import pandas as pd
from sqlalchemy import create_engine
engine = create_engine('mysql+pymysql://root:@localhost:3306/user_database')
sql1 = "SELECT * FROM `users`"
#sql2 = "SELECT * FROM `users` WHERE `SW`='Y'"
df = pd.read_sql(sql1, engine)
df.to_csv('sm_users.csv', index=False)

sql1查询工作正常,但是当我尝试添加WHERE子句时,它给出了错误

sqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1267, u"Illegal mix of collationssqlalchemy.exc.InternalError: (pymysql.err.InternalError) (1267, u"Illegal mix of collations

当我尝试将WHERE条件添加到INT列时,它可以工作,但不适用于String列。

谢谢!

0 个答案:

没有答案