简体   繁体   English

mysql 语法错误 1064 (42000)

[英]mysql syntax error 1064 (42000)

I have a standard LAMP configuration (apache2, mysql, php5), running on ubuntu, and I'm just typing mysql commands into my terminal.我有一个标准的 LAMP 配置(apache2、mysql、php5),在 ubuntu 上运行,我只是在我的终端中输入 mysql 命令。 I'm logged into the mysql command line as root.我以 root 身份登录到 mysql 命令行。 So far I've created a new database, but now trouble started.到目前为止,我已经创建了一个新数据库,但现在麻烦开始了。

I'm trying to create a simple table but am getting a mysql syntax error and can't figure out what I'm doing wrong.我正在尝试创建一个简单的表,但遇到 mysql 语法错误并且无法弄清楚我做错了什么。

This is the error:这是错误:

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 ')' at line 10

And this is my query:这是我的查询:

CREATE TABLE IF NOT EXISTS `customers` (
  `uid` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `name` varchar(50) NOT NULL,
  `email` varchar(50) NOT NULL,
  `phone` varchar(100) NOT NULL,
  `password` varchar(200) NOT NULL,
  `address` varchar(50) NOT NULL,
  `city` varchar(50) NOT NULL,
  `created` datetime NOT NULL DEFAULT TIMESTAMP
);

No idea what's wrong honestly.老实说不知道出了什么问题。

timestamp is not a value. timestamp不是一个值。 I'm guessing you meant to populate created with the current timestamp by default, which would be the function call CURRENT_TIMESTAMP() .我猜你的意思是默认使用当前时间戳填充created ,这将是函数调用CURRENT_TIMESTAMP() The complete statement:完整的声明:

CREATE TABLE IF NOT EXISTS `customers` (
  `uid` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `name` varchar(50) NOT NULL,
  `email` varchar(50) NOT NULL,
  `phone` varchar(100) NOT NULL,
  `password` varchar(200) NOT NULL,
  `address` varchar(50) NOT NULL,
  `city` varchar(50) NOT NULL,
  `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP()
);

You can assign default value as current_timestamp not just timestamp您可以将默认值指定为current_timestamp而不仅仅是timestamp

CREATE TABLE IF NOT EXISTS `customers` (
  `uid` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `name` varchar(50) NOT NULL,
  `email` varchar(50) NOT NULL,
  `phone` varchar(100) NOT NULL,
  `password` varchar(200) NOT NULL,
  `address` varchar(50) NOT NULL,
  `city` varchar(50) NOT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);

TIMESTAMP is not valid, it should be CURRENT_TIMESTAMP , so your code must be TIMESTAMP无效,它应该是CURRENT_TIMESTAMP ,所以你的代码必须是

CREATE TABLE IF NOT EXISTS `customers` (
  `uid` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `name` varchar(50) NOT NULL,
  `email` varchar(50) NOT NULL,
  `phone` varchar(100) NOT NULL,
  `password` varchar(200) NOT NULL,
  `address` varchar(50) NOT NULL,
  `city` varchar(50) NOT NULL,
  `created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
);

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

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