数据到数据库的导入,导出

作者:彼岸花开 | 创建时间: 2023-07-30
mysql数据库的数据导入导出...
数据到数据库的导入,导出

操作方法

先建一个txt文件 stud.txt 1,张三 2,李四 3,王五 4,赵六

--创建数据库 db mysql> create database db; -- 使用db数据库 mysql> use db --创建stud表 mysql> create table stud( -> id int(11) not null auto_increment, -> name varchar(30), -> primary key (id) -> )engine=innodb auto_increment=1 default charset=utf8;

--将stud.txt中的文件导入到数据库中 mysql> load data infile 'c:/a/stud.txt'into table stud fields terminated by '\,'  lines terminated by '\r\n'; --查看导入的数据 mysql> select * from stud;

--将数据库中的数据导出到aaa.txt中 mysql> select * into outfile 'c:/aaa.txt' fields terminated by '\,' lines terminated by '\r\n' from stud where id > 4;

--将数据库中的数据导入到excle里 mysql> select * into outfile 'c:/aa.xls' fields terminated by '\t' lines terminated by '\n' from stud;

温馨提示

1.建立的stud.txt文件保存注意保存的编码格式是utf8,否则会出现乱码
点击展开全文

更多推荐