I am trying to create a MySQL table using python but it keeps giving me this error: Error while connecting to MySQL 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' close FLOAT, high FLOAT, low FLOAT, open FLOAT, volume FLOAT, instrument CHA...' at line 1
import mysql.connector
from mysql.connector import Error
#connecting to database
try:
connection = mysql.connector.connect(host = "localhost",
user = "root",
database="hindalco"
)
#cursor method used to perform SQL operations
cursor = connection.cursor()
cursor.execute("CREATE TABLE tickersymbol (id INT AUTO_INCREMENT PRIMARY KEY, datetime smalldatetime, close FLOAT, high FLOAT, low FLOAT, open FLOAT, volume FLOAT, instrument CHAR(10)")
#print error messages using error as object
except Error as e:
print("Error while connecting to MySQL", e)
#close open connections after work is complete
finally:
if connection.is_connected():
connection.close()
print("MySQL connection is closed")
datetimeis a type and likely a reserved keyword.smalldatetimeis not a type in mariadb (I beleive it's a type in sql server). Maybe instead:date_time datetime.