问题如下:
1.错误显示ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
解决方式:Load data infile->load data local infile
2.MySQL服务无法启动
解决方法:修改配置文件,并重启MySQL。
3.ERROR 3948 (42000): Loading local data is disabled; this must be enabled on both the client and server sides
解决办法:输入set global local_infile=1,启动服务。
4.导入的txt文件为空
解决办法:数据文件中每一项去掉引号中间使用tab间隔。
文件格式如图:
正确显示:
MySQL语句注意事项:
1.创建表时要注意字段用法:
create table TMS_student(
sno int(10) primary key auto_increment comment '学号',
sname varchar(4) not null comment'姓名',
ssex enum(‘男’,’女’) not null comment'性别',
classno char(4) not null comment'班级编号',
major char(10) not null comment'专业',
birthday date not null comment'出生日期',
league enum(‘是’,’否’) not null comment'是否团员',
admdate date not null comment'入学时间',
enscore tinyint(3) not null comment'入学成绩'
);
enum(',')里面的元素要用单引号引用,多个元素用,分隔开;
comment表示注释;
2.修改操作:
1.修改TMS_teacher表title字段为char(10)
alter table TMS_teacher modify title char(10)
2.删除TMS_student表的league字段
alter table TMS_student drop league
3.在TMS_student表的enscore后面添加字段tel char(11) comment ‘电话',并添加非空约束
alter table TMS_student add tel char(11) not null comment ‘电话' after enscore
4.为TMS_student表的tel字段添加唯一约束(注意添加unique约束同时去掉了not null约束)。
alter table TMS_student drop index tel not mull add tel unique
5.修改TMS_student表damdate字段名为admdate
alter table TMS_student change damdate admdate date default not null comment'入学时间'
6.修改TMS_student表admdate字段的默认值为2021-09-01
alter table TMS_student alter column admdate set default 2021-09-01
7.修改TMS_student表的sno、enscore,TMS_teacher表的tno为无符号类型(注意:其他表外键参照的主键)。
ALTER TABLE 'TMS_student' MODIFY COLUMN ‘sno ‘ INT (10) UNSIGNED DEFAULT '0' COMMENT '学号'
ALTER TABLE 'TMS_student' MODIFY COLUMN ‘enscore‘ tinyint(3) UNSIGNED DEFAULT '0' COMMENT '入学成绩'
ALTER TABLE 'TMS_teacher' MODIFY COLUMN ‘tno‘ INT (6) UNSIGNED DEFAULT '0' COMMENT '教师编号'