[42000][1064] You have an error in your SQL syntax; check the manual that corresponds to your MySQL

时间:2025-04-22 15:55:24

1. 环境

今天使用idea 操作mysql建表时,碰到一个错误 

2. 错误提示

 [42000][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 ''goodss' (
  'goods_id' bigint(12) NOT NULL AUTO_INCREMENT COMMENT '商品ID',
 ' at line 1
3. 数据库代码
CREATE TABLE 'goodss' (
  'goods_id' bigint(12) NOT NULL AUTO_INCREMENT COMMENT '商品ID'
)ENGINE =InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET =utf8;

4. 解决办法

把 表名 和 字段名  的英文字符下的单引号 改成 英文字符下的反引号,默认值 和 comment 使用单引号(反引号,即键盘左上角 ‘1’ 左侧的那个键)

5.修改后的代码

CREATE TABLE `goods` (
  `goods_id` bigint(12) NOT NULL AUTO_INCREMENT COMMENT '商品ID'
)ENGINE =InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET =utf8;