日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

mysql创建数据库1064_Mysql创建表过程中报1064错误

發(fā)布時(shí)間:2025/3/20 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql创建数据库1064_Mysql创建表过程中报1064错误 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Mysql創(chuàng)建表過(guò)程中報(bào)1064錯(cuò)誤

發(fā)布時(shí)間:2020-06-18 06:23:08

來(lái)源:51CTO

閱讀:7528

作者:白羊IT

我在自己搭建的mysql服務(wù)中,在使用create table創(chuàng)建表時(shí)報(bào)了1064錯(cuò)誤,嘗試網(wǎng)上找了各種解決方法,最后還是被自己試著解決了。解決的有的稀里糊涂的,畢竟我自己對(duì)數(shù)據(jù)庫(kù)知識(shí)還沒(méi)個(gè)很清晰的認(rèn)知。廢話(huà)不多說(shuō)了,下面看我的解決歷程吧。

自己創(chuàng)建表的初衷:想要從無(wú)到有的嘗試

set names utf8

set foreign_key_checks=0

drop table if exists `own_reimbursement`;

create table `own_reimbursement` (

`id` int(10) not null AUTO_INCREMENT,

`start_time` date not null default,

`end_time` date not null default,

`travel_time` int(3) not null default,

`place_name` char(30) default comment '地名',

`project_name` char(30) default comment '項(xiàng)目名稱(chēng)',

`venue_name` char(30) default comment '場(chǎng)館名稱(chēng)',

`personnel_name` char(30) default comment '人員',

`hotel_expense` float(7) default comment '住宿費(fèi)',

`taxi_fare` float(7) not null default comment '打的費(fèi)',

`travel_allowance` float(7) not null default comment '出差補(bǔ)助',

`road_fee` float(7) not null default comment '路費(fèi)',

`subsidy` float(7) not null default comment '報(bào)銷(xiāo)合計(jì)',

primary key (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8;

BEGIN;

INSERT INTO `own_reimbursement` VALUES ('1', '2018-08-22', '2018-08-31', '10', '江西景德鎮(zhèn)','xx項(xiàng)目','xxxx運(yùn)動(dòng)中心','王思聰','1830','195.8','750','738','3513.8');

COMMIT;

SET FOREIGN_KEY_CHECKS = 1;

在執(zhí)行時(shí)一直報(bào)1064錯(cuò)誤,讓我百思不得其解,還傻傻的以為真是version問(wèn)題,還特意找了相關(guān)的version說(shuō)明看(下了英文版的一臉懵逼的),無(wú)賴(lài)直接簡(jiǎn)單粗暴的在網(wǎng)上搜mysql 創(chuàng)建表示報(bào)1064錯(cuò)誤,還真看到不少解決方法,但沒(méi)一條適用的。

[SQL]set names utf8

set foreign_key_checks=0

drop table if exists `own_reimbursement`;

[Err] 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 'set foreign_key_checks=0

drop table if exists `own_reimbursement`' at line 2

網(wǎng)上解決版本:

1.查看create table 語(yǔ)句里面的表、列、索引都要反斜杠符號(hào)也可以不使用,但不能寫(xiě)成 '單引號(hào)。不然執(zhí)行就會(huì)報(bào)1064錯(cuò)誤了

2.不要使用mysql的保留字

我的錯(cuò)誤是因?yàn)?沒(méi)搞清楚default。去掉default后就成功了。

set names utf8;

set foreign_key_checks = 0;

drop table if exists `own_reimbursement`;

create table `own_reimbursement` (

`id` int(10) not null AUTO_INCREMENT,

`start_time` date not null ,

`end_time` date not null ,

`travel_time` int(3) not null ,

`place_name` char(30) NOT NULL comment '地名',

`project_name` char(30) NOT NULL comment '項(xiàng)目名稱(chēng)',

`venue_name` char(30) NOT NULL comment '場(chǎng)館名稱(chēng)',

`personnel_name` char(30) NOT NULL comment '人員',

`hotel_expense` float(7) comment '住宿費(fèi)',

`taxi_fare` float(7) not null comment '打的費(fèi)',

`travel_allowance` float(7) not null comment '出差補(bǔ)助',

`road_fee` float(7) not null comment '路費(fèi)',

`subsidy` float(7) not null comment '報(bào)銷(xiāo)合計(jì)',

primary key (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8;

SET FOREIGN_KEY_CHECKS = 1;

原因:

default 修飾符

可以使用 DEFAULT 修飾符為字段設(shè)定一個(gè)默認(rèn)值。

如果一個(gè)字段中沒(méi)有指定 DEFAULT 修飾符,MySQL 會(huì)依據(jù)這個(gè)字段是 NULL 還是 NOT NULL 自動(dòng)設(shè)置默認(rèn)值。

如果指定字段可以為 NULL,則 MySQL 為其設(shè)置默認(rèn)值為 NULL。

如果是 NOT NULL 字段,MySQL 對(duì)于數(shù)值類(lèi)型插入 0,字符串類(lèi)型插入空字符串,

時(shí)間戳類(lèi)型插入當(dāng)前日期和時(shí)間,ENUM 類(lèi)型插入枚舉組的第一條。

如果創(chuàng)建表時(shí)要使用default修飾符,那不要忘記在default后面加個(gè)默認(rèn)值。

例如:

CREATE TABLE `websites` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`name` char(20) NOT NULL DEFAULT '' COMMENT '站點(diǎn)名稱(chēng)',

`url` varchar(255) NOT NULL DEFAULT '',

`alexa` int(11) NOT NULL DEFAULT '0' COMMENT 'Alexa 排名',

`country` char(10) NOT NULL DEFAULT '' COMMENT '國(guó)家',

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

總結(jié)

以上是生活随笔為你收集整理的mysql创建数据库1064_Mysql创建表过程中报1064错误的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。