【发布时间】:2019-08-29 06:49:45
【问题描述】:
我正在使用 select 语句声明 mysql 游标并使用变量传递数据库名称但出现错误。我正在使用 python 2.7 和 mysql 5.6 版 使用 MySQLdb 包。
我已经尝试了通过堆栈溢出提供的所有方法。 cur.execute("select distinct U.user,U.password,U.host from user U,db D where U.user=D.user and D.db=%s and U.host= '%' order by user ;",[db])
cur.execute("select distinct U.user,U.password,U.host from user U,db D where U.user=D.user and D.db=%s and U.host= '%'按用户排序;",db)
cur.execute("select distinct U.user,U.password,U.host from user U,db D where U.user=D.user and D.db=%s and U.host= '%'按用户订购;",(db))
cur.execute("select distinct U.user,U.password,U.host from user U,db D where U.user=D.user and D.db=%s and U.host= '%'按用户排序;",db)
MySQLdb.connect(host='##############',user='#####,passwd='###',db='mysql')
cur = conn.cursor()
db="mysql"
query = """select distinct U.user,U.password,U.host from user U,db D where U.user=D.user and D.db=%s and U.host= '%' order by user;"""
cur.execute(query, (db))```
expecting values from tables but getting error.
ValueError: unsupported format character ''' (0x27) at index 104
【问题讨论】: