我已经从MySQL 5.5.40版本导出了一个数据库,但是当我将它导入MySQL 5.5.44时,我收到了关于语法的错误。
CREATE TABLE IF NOT EXISTS `key_value` (
`collection` varchar(128) CHARACTER SET ascii NOT NULL DEFAULT '' COMMENT 'A named collection of key and value pairs.'
`value` longblob NOT NULL COMMENT 'The value.',
PRIMARY KEY (`collection`,`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Generic key-value storage table. See the state system for…';
收到的错误是:
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 '`value` longblob NOT NULL COMMENT 'The value.',
PRIMARY KEY (`collection`,`nam' at line 3
请建议。
答案 0 :(得分:4)
每个this comment in the drupal.org issue queue的解决方案是:
改变这个:
CREATE TABLE ``key_value`` (
``collection`` varchar(128) CHARACTER SET ascii NOT NULL DEFAULT '' COMMENT 'A named collection of key and value pairs.'
``value`` longblob NOT NULL COMMENT 'The value.',
PRIMARY KEY (``collection``,``name``)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Generic key-value storage table. See the state system for…'
到此:
CREATE TABLE ``key_value`` (
``collection`` varchar(128) CHARACTER SET ascii NOT NULL DEFAULT '' COMMENT 'A named collection of key and value pairs.',
``name`` varchar(128) CHARACTER SET ascii NOT NULL DEFAULT '' COMMENT 'The key of the key-value pair. As KEY is a SQL reserved keyword, name was chosen instead.',
``value`` longblob NOT NULL COMMENT 'The value.',
PRIMARY KEY (``collection``,``name``)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Generic key-value storage table. See the state system for';
然后在结尾附近删除它以防止出现其他错误:
ALTER TABLE ``key_value``
ADD ``name`` varchar(128) CHARACTER SET ascii NOT NULL DEFAULT '' COMMENT 'The key of the key-value pair. As KEY is a SQL reserved keyword, name was chosen instead.';
答案 1 :(得分:0)
您的表格中没有name
列,但您正在使用PRIMARY KEY(collection
,name
)的组合创建主键。所以只需删除名称并尝试。
在Khalid建议的收集列之后和值列之前添加','。
最后你可以使用 -
CREATE TABLE IF NOT EXISTS `key_value` (
`collection` VARCHAR(128) CHARACTER SET ASCII NOT NULL DEFAULT '' COMMENT 'A named collection of key and value pairs.',
`value` LONGBLOB NOT NULL COMMENT 'The value.',
PRIMARY KEY (`collection`)
) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COMMENT='Generic key-value storage table. See the state system for…';