当前位置:数据库 > MySQL >>

mysql数据导入与导出实例

没有指定字段表,所以load data infile期望输入行对每个表列包含一个字段。使用缺省fields和lines值。

如果你希望仅仅装载一张表的某些列,指定一个字段表:

mysql教程> load data infile 'persondata.txt'
           into table persondata (col1,col2,...);

如果在输入文件中的字段顺序不同于表中列的顺序,你也必须指定一个字段表。否则,mysql不能知道如何匹配输入字段和表中的列。

如果一个行有很少的字段,对于不存在输入字段的列被设置为缺省值


select <columns>
from <table_name>
into outfile <file_name>
 
select
employee.id,
employee.first_name,
employee.last_name,
employee.start_date,
employee.salary,
employee.city
from employee into outfile 'c:employee.txt';

导入

load data infile 'file_name.txt'
into table tbl_name (field1, field2...etc)
 
load data infile 'c:employee.txt'
into table employee (id, first_name, last_name, start_date, salary, city);


 
从文件导入

mysql> load data local infile 'c:mytable.txt' into table mytable lines terminated by 'rn';


mysql>

 

 

补充:数据库,mysql教程 
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,