创建MySql表格的时候,顺利建表成功,但是在插入数据时却报了如下错误:
_mysql_exceptions.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 'current_date,knowledge_level,grade_group_id,subject_id,current_arrive_level,curr' at line 1")
下面将详细给出本文的解决方案过程:
给出报错-> 打印出报错的sql语句->命令行执行->
(1)下面是具体报错的情况:
_mysql_exceptions.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 'current_date,knowledge_level,grade_group_id,subject_id,current_arrive_level,curr' at line 1")
(2) 打印报错sql语句 很明显,错误提示是mysql的插入语句出错了,这时你应该把这个mysql 语句打印出来,然后判断其是否出错。
下面是程序打印结果
replace into students_arrive_knowledge_level_for_master_ratio_new(student_id,knowledge_id,current_date,knowledge_level,grade_group_id,subject_id,current_arrive_level,current_score,next_arrive_level,next_score,ctime,utime,moji_knowledge_node_id,total_number) values('113356','6oo7ryi0e79zkqai08wbmeohxn6c022f','2017-08-09','3','3','5','1','0.900000','2','0.800000','2017-08-09 15:28:09','2017-08-09 15:28:09','1200174','10')
(3)命令行执行:用眼看不出来错误,接着,下一个大招是在mysql命令行下,再次这行打印出来的这条mysql命令,但不幸的是,错误依然存在
mysql> replace into students_arrive_knowledge_level_for_master_ratio_new(student_id,knowledge_id,current_date,knowledge_level,grade_group_id,subject_id,current_arrive_level,current_score,next_arrive_level,next_score,ctime,utime,moji_knowledge_node_id,total_number) values('113356','6oo7ryi0e79zkqai08wbmeohxn6c022f','2017-08-09','3','3','5','1','0.900000','2','0.800000','2017-08-09 15:18:41','2017-08-09 15:18:41','1200174','10')
-> ;
ERROR 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 'current_date,knowledge_level,grade_group_id,subject_id,current_arrive_level,curr' at line 1
(4)解决之道: 苦思冥想之际,发觉问老司机才是解决之捷径,遂问之,他给出如下两个步骤:
第一,根据出错原因,将出错字段添加倒引号(一般在你键盘左上角的esc下面那个),添加之后,在mysql命令行之下执行成功
mysql> replace into students_arrive_knowledge_level_for_master_ratio_new(student_id,knowledge_id,`current_date`,knowledge_level,grade_group_id,subject_id,current_arrive_level,current_score,next_arrive_level,next_score,ctime,utime,moji_knowledge_node_id,total_number) values('113356','6oo7ryi0e79zkqai08wbmeohxn6c022f','2017-08-09','3','3','5','1','0.900000','2','0.800000','2017-08-09 15:18:41','2017-08-09 15:18:41','1200174','10');
Query OK, 1 row affected (0.01 sec)
第四,解决策略有两个:第一,修改该表格中的字段名,改成不是mysql的内置关键字
第二,继续使用该表格定义,在插入数据时,对该关键字两边添加倒引号