Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql命令中出现错误_Mysql_Sql - Fatal编程技术网

mysql命令中出现错误

mysql命令中出现错误,mysql,sql,Mysql,Sql,我正在跟着一本书学习cakephp。我有这个表要在mysql中创建,但我一直有一个错误 CREATE TABLE IF NOT EXISTS 'categories'( 'id' int(10) NOT NULL AUTO_INCREMENT, 'parent_id' int(11) NOT NULL DEFAULT '0', 'name' varchar(50) character NOT NULL, 'description' varchar(200) ch

我正在跟着一本书学习cakephp。我有这个表要在mysql中创建,但我一直有一个错误

 CREATE TABLE IF NOT EXISTS 'categories'(
    'id' int(10) NOT NULL AUTO_INCREMENT,
    'parent_id' int(11) NOT NULL DEFAULT '0',
    'name' varchar(50) character NOT NULL,
    'description' varchar(200) character NOT NULL,
    'image' varchar(255) character NOT NULL,
    PRIMARY KEY ('id'),
    KEY 'cat_parent_id' ('parent_id'),
    KEY 'cat_name' ('name')
);

INSERT INTO 'categories' ('id', 'parent_id', 'name', 'description', 'image') VALUES
(17, 0, 'Jazz', 'Everything from 1890s', ''),
(12, 0, 'Classical', 'From Medieval to Contemporary', ''),
(13, 17, 'Dizzy Gillepsie', 'The Trumpeter Master', ''),
(14, 12, 'Mozart', 'The Old Favourite', '');
第1行的错误??:

#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 ''categories'(
    'id' int(10) NOT NULL AUTO_INCREMENT,
    'parent_id' int(11) NOT NU' at line 1 

单引号用于字符串文字,而不是标识符(列名或表名)。移除它们。另外,我不确定
字符
应该做什么,除非您打算指定(
字符集
):


如果您需要在MySQL中引用一个标识符,请使用backtick`。这有助于轻松识别哪些是表/列名,哪些是关键字。一些开发人员还坚持在任何地方都使用它们作为样式规则:

CREATE TABLE IF NOT EXISTS `categories`(
    `id` int(10) NOT NULL AUTO_INCREMENT,
    `parent_id` int(11) NOT NULL DEFAULT '0',
    `name` varchar(50) NOT NULL,
    `description` varchar(200) NOT NULL,
    `image` varchar(255) NOT NULL,
    PRIMARY KEY (`id`),
    KEY `cat_parent_id` (`parent_id`),
    KEY `cat_name` (`name`)
);
使用保留字作为列名时,必须使用引号(不推荐):


好的,这是信用证。现在我在第4行仍然有一个错误:`#1064-您的SQL语法有一个错误;检查与您的MySQL服务器版本对应的手册,了解在第4行“@PapoucheGuinslyzinho Edited”附近使用的正确语法“NOT NULL,description varchar(200)character NOT NULL,image varchar(255)char”。不知道你从哪里得到的
字符
,但这似乎不正确如果答案对你有帮助,习惯上会给它投一票。您还应该将最有用的答案勾选为“已接受”
CREATE TABLE IF NOT EXISTS `categories`(
    `id` int(10) NOT NULL AUTO_INCREMENT,
    `parent_id` int(11) NOT NULL DEFAULT '0',
    `name` varchar(50) NOT NULL,
    `description` varchar(200) NOT NULL,
    `image` varchar(255) NOT NULL,
    PRIMARY KEY (`id`),
    KEY `cat_parent_id` (`parent_id`),
    KEY `cat_name` (`name`)
);
CREATE TABLE IF NOT EXISTS foobar(
    id int(10) NOT NULL AUTO_INCREMENT,
    `table` int(11) NOT NULL,
    `select` int(11) NOT NULL
);