错误使用Python在MySQL中创建表
我正在尝试使用 python 创建 MySQL 表,但它一直给我这个错误:连接到 MySQL 1064 (42000) 时出错:您的 SQL 语法中有错误;检查与您的 MariaDB 服务器版本相对应的手册,了解在第 1 行的“close FLOAT、high FLOAT、low FLOAT、open FLOAT、volume FLOAT、instrument CHA...”附近使用的正确语法
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")
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")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为没有这样的数据类型为
smalldateTime
。您可能是要说:评论后续行动。
要使用MariaDB连接器,您将执行类似的操作:
此时,
cursor.execute()
行应该正常工作。It is because there is no such data type as
smalldatetime
. You probably meant to say:Comment follow-up.
To use mariadb connector, you would do something like this:
At this point the
cursor.execute()
line should work fine.