[英]why i can't create the database automatically?
import pymysql
con = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='******')
db_name=['Cinfos', 'Holders', 'Capitals','Dividends','Fi_Dis','Finances']
for db in db_name:
cur=con.cursor()
cur.execute("create database if not exit %s" %db)
con.commit()
cur.close()
我得到了錯誤:
pymysql.err.ProgrammingError:(1064,“您的SQL語法有錯誤;請參見與MySQL服務器版本相對應的手冊,以在第1行的'exit Cinfos'附近使用正確的語法”)
我的pymysql代碼怎么了?
您的查詢有誤。
cur.execute("create database if not exit %s" %db)
應該:
cur.execute("create database if not exists %s" %db)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.