当我输入下面一段代码的时候:

create TABLE 'items'(
         'id' int(11) NOT NULL AUTO_INCREMENT,
         'name' varchar(32) NOT NULL COMMENT '商品名称',
         'price' float(10,1) NOT NULL COMMENT '商品定价',
         'detail' text COMMENT '商品描述',
         'pic' varchar(64) DEFAULT  NULL COMMENT  '商品图片',
         'createtime' datetime NOT NULL  COMMENT '生产日期',
          PRIMARY KEY ('id')
         )ENGINE=InnoDB DEFAULT  CHARSET =utf8

系统报错:

[2022-06-30 14:09:55] [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 ''items'(
[2022-06-30 14:09:55] 'id' int(11) NOT NULL AUTO_INCREMENT,
[2022-06-30 14:09:55] 'name' varchar(32) NOT NULL COM' at line 1

 改成下面一段后:

create TABLE `items`(
         `id` int(11) NOT NULL AUTO_INCREMENT,
         `name` varchar(32) NOT NULL COMMENT '商品名称',
         `price` float(10,1) NOT NULL COMMENT '商品定价',
         `detail` text COMMENT '商品描述',
         `pic` varchar(64) DEFAULT  NULL COMMENT  '商品图片',
         `createtime` datetime NOT NULL  COMMENT '生产日期',
          PRIMARY KEY (`id`)
         )ENGINE=InnoDB DEFAULT  CHARSET =utf8

代码运行成功:

 查阅资料后:

在MySQL中,为了区分MySQL的关键字与普通字符

关键字采用反引号`name`(ESC下面那个波浪键~)

普通字符采用 引号'abc'

也就是上述的关键字`name` 和普通字符'商品定价'
错误的原因事数据库名称和关键字使用的是单引号而不是反引号,

所以会就报了这个错误出来。

思路源于下面的文章: