我的编程空间,编程开发者的网络收藏夹
学习永远不晚

pymysql.err.ProgrammingError: (1064, “You have an error in your SQL syntax; check the manual that co

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

pymysql.err.ProgrammingError: (1064, “You have an error in your SQL syntax; check the manual that co

pymysql.err.ProgrammingError: (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 `sinatop20` ( `snid` int(11) NOT NULL AUTO_INCREMENT, `id` varchar(' at line 1")

对于报错解析:很明显这是语法错误,我上看下看,左看右看,都没有看出问题来。

在pycharm中执行报语法错误,但是我复制到mysql数据库去执行又是正常的。就很纳闷。

目录

一、执行的语句

二、分析

1、 在pycharm运行就报错了:

 2、在mysql运行是正常的

3、错误寻找

4、答案在这:


一、执行的语句

原来的执行语句的功能:"""如果存在表就卸载表;然后创建表"""

DROP TABLE IF EXISTS `sinatop20`; CREATE TABLE `sinatop20` ( `snid` int(11) NOT NULL AUTO_INCREMENT, `id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `media` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `author` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `comment_url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `create_date` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `create_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `cat_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `top_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `top_num` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext3` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext4` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext5` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,  PRIMARY KEY (`snid`) USING BTREE ) ENGINE = MyISAM AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

DROP TABLE IF EXISTS `sinatop20`; CREATE TABLE `sinatop20` ( `snid` int(11) NOT NULL AUTO_INCREMENT, `id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `media` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `author` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `comment_url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `create_date` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `create_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `cat_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `top_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `top_num` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext3` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext4` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext5` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,  PRIMARY KEY (`snid`) USING BTREE ) ENGINE = MyISAM AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

二、分析

1、 在pycharm运行就报错了:

Traceback (most recent call last):  File "E:\WorkSpace\GraPro\DISHSASysBTM_ManageSys\DataCrawl\sinaTop20.py", line 62, in     cur.execute(create_sql)  File "C:\Programs\Python\Python310\lib\site-packages\pymysql\cursors.py", line 170, in execute    result = self._query(query)  File "C:\Programs\Python\Python310\lib\site-packages\pymysql\cursors.py", line 328, in _query    conn.query(q)  File "C:\Programs\Python\Python310\lib\site-packages\pymysql\connections.py", line 517, in query    self._affected_rows = self._read_query_result(unbuffered=unbuffered)  File "C:\Programs\Python\Python310\lib\site-packages\pymysql\connections.py", line 732, in _read_query_result    result.read()  File "C:\Programs\Python\Python310\lib\site-packages\pymysql\connections.py", line 1075, in read    first_packet = self.connection._read_packet()  File "C:\Programs\Python\Python310\lib\site-packages\pymysql\connections.py", line 684, in _read_packet    packet.check_error()  File "C:\Programs\Python\Python310\lib\site-packages\pymysql\protocol.py", line 220, in check_error    err.raise_mysql_exception(self._data)  File "C:\Programs\Python\Python310\lib\site-packages\pymysql\err.py", line 109, in raise_mysql_exception    raise errorclass(errno, errval)pymysql.err.ProgrammingError: (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 `sinatop20` ( `snid` int(11) NOT NULL AUTO_INCREMENT, `id` varchar(' at line 1")Process finished with exit code 1

 2、在mysql运行是正常的

DROP TABLE IF EXISTS `sinatop20`> OK> 时间: 0.001sCREATE TABLE `sinatop20` ( snid int(11) NOT NULL AUTO_INCREMENT, `id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `title` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `media` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `author` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `comment_url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `create_date` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `create_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `cat_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `top_time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `top_num` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext1` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext2` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext3` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext4` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `ext5` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `time` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,  PRIMARY KEY (`snid`) USING BTREE ) ENGINE = MyISAM AUTO_INCREMENT = 1 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic> OK> 时间: 0.003s

3、错误寻找

找了很多,有人说是使用的字段有可能是关键字,要用 `` 把关键字包起来,我也包起来了,其他什么逗号,括号都没有问题。毕竟在mysql查询里可以运行,那就语句是没有问题的。

然后想起昨晚第一次运行都没有问题,后来我是改了哪里出了问题?

4、答案在这:

因为在pycharm里,上述sql语句中,我同时执行了两个命令!!!

要把DROP和CREATE分开两次运行,不能放在一个excute执行!!!

我的代码在这:

-------报错的代码示例:

 -----解决错误后代码示例:

来源地址:https://blog.csdn.net/c_lanxiaofang/article/details/130385282

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

pymysql.err.ProgrammingError: (1064, “You have an error in your SQL syntax; check the manual that co

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

pycharm中的python与mysql(1064):“You have an error in your SQL syntax; check the manual that corresponds

一、报错信息及代码 1064, “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version fo
2023-08-16

You have an error in your SQL syntax; check the manual that corresponds解决方法

You have an error in your SQL syntax; check the manual that corresponds to your mysql server version这种错误主要是由于,使用了现在版本的m
2023-02-05

Django中创建数据库报错:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corre

一、问题描述  Django中执行create database charset=utf8;命令报错:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
Django中创建数据库报错:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corre
2020-11-22

Mysql出现问题:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corres解决方案

回城传送–》《数据库问题解决方案》 ❤️作者主页:小虚竹 ❤️作者简介:大家好,我是小虚竹。Java领域优质创作者?,CSDN博客专家?,华为云享专家?,掘金年度人气作者?,阿里云专家博主?,51CTO专家博主? ❤️技
2023-08-30

修改mysql的密码时遇到问题ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corre

由于找不到mysql的初始密码,我用免密码的方式在cmd中进入mysql对密码做了修改,并且最后成功修改了,但是走了一些弯路,就此记录一下。 注意 :我想要改为的密码为 mysql,大家想要什么密码设自己喜欢的就行 进入mysql后修改密码
2023-08-17

全网多种方法解决You have an error in your SQL syntax; check the manual that corresponds to your MySQL server

文章目录 1. 复现错误2. 分析错误3. 解决错误4. 解决该错误的其他方法 1. 复现错误 今天在调试低代码的接口,突然报出如下的错误: 即You have an error in your SQL syntax; ch
2023-08-16

编程热搜

目录