Mysql创建表过程中报1064错误
发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,我在自己搭建的mysql服务中,在使用create table创建表时报了1064错误,尝试网上找了各种解决方法,最后还是被自己试着解决了。解决的有的稀里糊涂的,毕竟我自己对数据库知识还没个很清晰的认
千家信息网最后更新 2024年09月22日Mysql创建表过程中报1064错误
我在自己搭建的mysql服务中,在使用create table创建表时报了1064错误,尝试网上找了各种解决方法,最后还是被自己试着解决了。解决的有的稀里糊涂的,毕竟我自己对数据库知识还没个很清晰的认知。废话不多说了,下面看我的解决历程吧。
自己创建表的初衷:想要从无到有的尝试
set names utf8set foreign_key_checks=0drop 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 '项目名称', `venue_name` char(30) default comment '场馆名称', `personnel_name` char(30) default comment '人员', `hotel_expense` float(7) default comment '住宿费', `taxi_fare` float(7) not null default comment '打的费', `travel_allowance` float(7) not null default comment '出差补助', `road_fee` float(7) not null default comment '路费', `subsidy` float(7) not null default comment '报销合计', 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', '江西景德镇','xx项目','xxxx运动中心','王思聪','1830','195.8','750','738','3513.8');COMMIT;SET FOREIGN_KEY_CHECKS = 1;
在执行时一直报1064错误,让我百思不得其解,还傻傻的以为真是version问题,还特意找了相关的version说明看(下了英文版的一脸懵逼的),无赖直接简单粗暴的在网上搜mysql 创建表示报1064错误,还真看到不少解决方法,但没一条适用的。
[SQL]set names utf8set foreign_key_checks=0drop 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=0drop table if exists `own_reimbursement`' at line 2
网上解决版本:
1.查看create table 语句里面的表、列、索引都要反斜杠符号也可以不使用,但不能写成 '单引号。不然执行就会报1064错误了
2.不要使用mysql的保留字
我的错误是因为 没搞清楚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 '项目名称', `venue_name` char(30) NOT NULL comment '场馆名称', `personnel_name` char(30) NOT NULL comment '人员', `hotel_expense` float(7) comment '住宿费', `taxi_fare` float(7) not null comment '打的费', `travel_allowance` float(7) not null comment '出差补助', `road_fee` float(7) not null comment '路费', `subsidy` float(7) not null comment '报销合计', primary key (`id`)) ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8;SET FOREIGN_KEY_CHECKS = 1;
原因:
default 修饰符
可以使用 DEFAULT 修饰符为字段设定一个默认值。
如果一个字段中没有指定 DEFAULT 修饰符,MySQL 会依据这个字段是 NULL 还是 NOT NULL 自动设置默认值。
如果指定字段可以为 NULL,则 MySQL 为其设置默认值为 NULL。
如果是 NOT NULL 字段,MySQL 对于数值类型插入 0,字符串类型插入空字符串,
时间戳类型插入当前日期和时间,ENUM 类型插入枚举组的第一条。
如果创建表时要使用default修饰符,那不要忘记在default后面加个默认值。
例如:
CREATE TABLE `websites` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` char(20) NOT NULL DEFAULT '' COMMENT '站点名称', `url` varchar(255) NOT NULL DEFAULT '', `alexa` int(11) NOT NULL DEFAULT '0' COMMENT 'Alexa 排名', `country` char(10) NOT NULL DEFAULT '' COMMENT '国家', PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;
错误
名称
字段
类型
项目
人员
住宿费
地名
场馆
打的费
方法
时间
路费
还是
尝试
补助
成功
粗暴
百思不得其解
从无到有
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络安全体系的部分
osx邮件服务器安全认证
阿里云服务器外网端口无法绑定
软件开发的总体框架
网络安全法答题小结
以系统思维审视网络安全工作
数据库更名需要脱机吗
steam无法更新服务器
想找服务器怎么建
网络安全威胁举报记录
服务器的io口是干什么的
如何把台式机变成服务器
南京知一点网络技术
云表管理软件开发平台
网络安全研究生报考
选择前十行数据库
河南常见软件开发成本价
河南联通服务器名称或地址云主机
dell 服务器 论坛
衢州数据网络技术咨询热线
网络安全扫描拍立得mini
在服务器新建安全组
索尼电视不能投屏要连服务器
南京软件开发哪家最好
软件开发公司部门分类
北京志虎软件开发有限公司
中国有多少人从事软件开发
幻塔分服务器
数据库删除某个时间段的某个数据
软件开发经营需要什么条件