krishna kumar nokha
krishna kumar nokha

Reputation: 11

How to create MySQL database in Python?

I run the following Python script and receive the following error message:

mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'check' at line 1")

When I changed the database from check to check1 it the script works and also I didn't have earlier defined "check" database.

import MySQLdb as db
db1 = db.connect(host="localhost",user="root",passwd="vision@123")
cursor = db1.cursor()
sql = "CREATE DATABASE check;"
cursor.execute(sql)
db1.close()

Upvotes: 0

Views: 112

Answers (2)

Joseph Idziorek
Joseph Idziorek

Reputation: 5071

Check is a reserved word in MySQL: http://dev.mysql.com/doc/refman/5.7/en/keywords.html and hence the error with "check" and not "check1".

Upvotes: 1

Drew
Drew

Reputation: 24949

check is a reserved word.

https://dev.mysql.com/doc/refman/5.5/en/keywords.html

The also will fail:

Create database select;

Upvotes: 1

Related Questions