문제

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()

I got the error :
pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; chec k the manual that corresponds to your MySQL server version for the right syntax to use near 'exit Cinfos' at line 1")
What is the matter with my pymysql code?

도움이 되었습니까?

해결책

You have an error in your query.

cur.execute("create database  if not exit %s" %db)

should be:

cur.execute("create database  if not exists %s" %db)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top