【发布时间】:2023-01-08 23:58:34
【问题描述】:
这是我连接到 mysql 的脚本
我正在尝试为 mysql 数据库和烧瓶应用程序创建连接器或中间人
当我试图创建一个表时,我遇到了一个错误
#!/usr/bin/python
import mysql.connector
from mysql.connector import Error as SQLError
db_info = ['localhost', 'xxx', 'xxx', 'xxx']
# Trying to connect to server
try:
connection = mysql.connector.connect(host=db_info[0],
database=db_info[1],
user=db_info[2],
password=db_info[3])
if connection.is_connected():
db_Info = connection.get_server_info()
print("Connected to MySQL Server version ", db_Info)
cursor = connection.cursor() # CURSOR
cursor.execute("select database();")
record = cursor.fetchone()
print("You're connected to database: ", record)
except SQLError as e:
print("Error while connecting to MySQL", e)
quit()
artist_table_create = """
CREATE TABLE artist (
id INT NOT NULL,
sid INT NOT NULL,
name VARCHAR(32) NOT NULL,
birthdate DATE NOT NULL,
gender ENUM('0', '1') NOT NULL,
code_melli VARCHAR(32) NOT NULL,
phonenumber VARCHAR(16) NOT NULL,
email VARCHAR(128) NOT NULL,
location1 VARCHAR(32) NOT NULL,
location2 VARCHAR(32) NOT NULL,
date_signedup DATE NOT NULL,
verification_status ENUM('0', '1'),
avatar VARCHAR(1028) DEFAULT `image.jpeg`,
rank VARCHAR(256) NOT NULL,
env1 VARCHAR(256) NOT NULL,
env2 VARCHAR(256) NOT NULL,
env3 VARCHAR(256) NOT NULL,
PRIMARY KEY (id, sid, phonenumber)
);"""
try:
result = cursor.execute(artist_table_create)
except SQLError as e:
print(e)
这是我在命令行中的错误:
1064 (42000): 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 '`image.jpeg`,
rank VARCHAR(256) NOT NULL,
env1 VARCHAR(256) NOT NULL,
' at line 14
我不知道我应该不能理解 mysql 错误
我需要修复这个错误
【问题讨论】:
-
默认值
image.jpeg应该用单引号'括起来,而不是反引号。
标签: python mysql database mysql-connector