将pymysql与python3.6.4和mysql 8在windows10上结合使用。我有奇怪的语法错误。但是,这些命令通常用于mysql 5.7,它们自己工作。这里有两个例子:
create table Guest(
guestNo INT,
firstName varchar(15),
lastName varchar(15),
phoneNo VARchar(20));
python打印的错误 print(ex.args)
前男友在哪 Exception
:
(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 'create table Guest(\n\t\t guestNo INT,\n firstName varchar(15' at line 2")
另一个例子:
insert into Booking
values (101, '2014-06-01', '2014-06-30', 500);
insert into Booking
values (101, '2014-08-01', '2014-08-31', 500);
insert into Booking
values (102, '2014-07-01', '2014-07-31', 500);
insert into Booking
values (102, '2015-07-01', '2015-07-31', 500);
insert into Booking
values (103, '2014-09-01', '2014-09-30', 500);
python打印的错误 print(ex.args)
前男友在哪 Exception
:
(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 'insert into Booking\nvalues (101, '2014-06-01', '2014-06-30', 500);\ninsert into B' at line 2")
似乎我可以连接良好(不使用新的身份验证)。
1条答案
按热度按时间omjgkv6w1#
因此,有几点不同于mysql 5.7和pymysql:1。
cursor.exec(q)
. q必须是一个命令。多个命令之间用分隔符分隔;不要工作。2在仔细查看python代码之后,它附加了一个额外的SET @some_var = 0;
在每次查询之前,将我的查询转换为多语句查询。我希望这能帮助别人。