1、作用:把文件系统中的内容导入到数据库中
2、语法:
load data infile "文件名"
into table 表名
fields terminated by "分隔符" #每条记录的各字段值之间
lines terminated by "\n";
3、将scoretable.csv文件导入到数据库的表中
1、在数据库中创建对应的表
create table student(
id int primary key auto_increment,
name varchar(7),
score float(5,2),
number bigint,
class char(7)
);
2、把文件拷贝到数据库的默认搜索路径中
1、查看默认搜索路径
show variables like "secure_file_priv";
#默认为:/var/lib/mysql-files/
2、拷贝文件
sudo cp ~/scoretable.csv /var/lib/mysql-files/
3、执行数据导入语句
load data infile
"/var/lib/mysql-files/scoretable.csv"
into table student
fields terminated by ","
lines terminated by "\n";
4、Excel表格如何转化为CSV文件
打开Excel文件->另存为->CSV(逗号分隔)
5、更改文件编码格式
用记事本/编辑器打开,文件->另存为->选择编码
数据导出
1、作用:
将数据库中表的记录导出到系统文件里
2、语法格式
select ... from 表名
into outfile "/var/lib/mysql-files/文件名"
fields terminated by "分隔符"
lines terminated by "\n";
3、将mysql库下的user表中的user、host两个字段的值导出到user.txt
select user,host from mysql.user
into outfile "/var/lib/mysql-files/user.txt"
fields terminated by " "
lines terminated by "\n";
数据导入1、作用:把文件系统中的内容导入到数据库中2、语法: load data infile "文件名" into table 表名 fields terminated by "分隔符" #每条记录的各字段值之间 lines terminated by "\n";3、将scoretable.csv文件导入到数据库的表中 1、在数据库中创建对应的表 creat...