day = datetime.datetime.today().strftime('%Y%m%d')
def connect():
conn = None
try:
conn = mysql.connector.connect(user='elijah', password='12345678',
host='127.0.0.1', database='userdb',
auth_plugin='mysql_native_password')
if conn.is_connected():
print('Connected to MySQL database')
cursor = conn.cursor()
sql = '''CREATE TABLE %s(
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
rating VARCHAR(255) NOT NULL,
reservation_rate VARCHAR(255) NOT NULL
)'''%day
cursor.execute(sql)
我试图在表名中插入一个变量,但它一直给我这个错误:
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 '20200320(
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) ' at line 1
我已经尝试了格式,字符串串联和%s替换到目前为止没有任何效果。
慕妹3146593
相关分类