简体   繁体   English

MySQL查询错误#1064?

[英]MySQL query error #1064?

I'm trying to import my old database but this gave me some errors what makes it impossible im also searching on google for 30 minuts and i can't find any solution? 我正在尝试导入我的旧数据库,但这给了我一些错误,这使我无法在Google上搜索30分钟,并且找不到任何解决方案吗?

SQL-query:


CREATE TABLE `UG_blogs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `catid` int(11) NOT NULL,
  `ownerid` int(11) NOT NULL,
  `content` text NOT NULL,
  `date` datetime NOT NULL DEFAULT TIMESTAMP,
  PRIMARY KEY (`id`), KEY id(`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;


MySQL meldt: Documentatie

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '
  PRIMARY KEY (`id`), KEY id(`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT C' at line 6 

The correct default value is CURRENT_TIMESTAMP : 正确的默认值为CURRENT_TIMESTAMP

CREATE TABLE `UG_blogs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `catid` int(11) NOT NULL,
  `ownerid` int(11) NOT NULL,
  `content` text NOT NULL,
  `date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY id(`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

The SQL Fiddle is here . SQL Fiddle在这里

EDIT: 编辑:

You must be using an old-ish version of MySQL (okay, not that old, just pre-5.6). 您必须使用的是旧版本的MySQL(好的,不是那个旧版本,仅在5.6之前)。 Well, you can't default a datetime value (without a trigger), so you have to live with a TIMESTAMP value and learn to love the timestamp functions: 好吧,您不能默认一个datetime值(没有触发器),因此您必须使用TIMESTAMP值并学会喜欢timestamp函数:

CREATE TABLE `UG_blogs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `catid` int(11) NOT NULL,
  `ownerid` int(11) NOT NULL,
  `content` text NOT NULL,
  `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY id(`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

First solution : change datatype into timestamp like this 第一个解决方案:像这样将数据类型更改为时间戳

CREATE TABLE `UG_blogs` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `catid` int(11) NOT NULL,
  `ownerid` int(11) NOT NULL,
  `content` text NOT NULL,
  `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  KEY id(`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1;

The problem is : The Timestamp data type has a range of 1970-01-01 00:00:01 UTC to 2038-01-19 03:14:07. 问题是:Timestamp数据类型的范围是1970-01-01 00:00:01 UTC到2038-01-19 03:14:07。

So the second solution is, don't change datetime datatype into timestamp. 因此,第二个解决方案是,不要将datetime数据类型更改为timestamp。 But you need a trigger to set default value. 但是您需要一个触发器来设置默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM