집 >데이터 베이스 >MySQL 튜토리얼 >mysql Load Data InFile 的用法_MySQL
bitsCN.com
首先创建一个表
Use Test;
Create Table TableTest(
`ID` mediumint(8) default '0',
`Name` varchar(100) default ''
) TYPE=MyISAM;
向数据表导入数据
Load Data InFile 'C:/Data.txt' Into Table `TableTest`
常用如下:
Load Data InFile 'C:/Data.txt' Into Table `TableTest` Lines Terminated By '/r/n';
这个语句,字段默认用制表符隔开,每条记录用换行符隔开,在Windows下换行符为“/r/n”
C:/Data.txt 文件内容如下面两行:
1 A
2 B
“1”和“A”之间有一个制表符
这样就导进两条记录了。
自定义语法
Load Data InFile 'C:/Data.txt' Into Table `TableTest` Fields Terminated By ',' Enclosed By '"' Escaped By '"' Lines Terminated By '/r/n';
Fields Terminated By ',' Enclosed By '"' Escaped By '"'
表示每个字段用逗号分开,内容包含在双引号内
Lines Terminated By '/r/n';
表示每条数据用换行符分开
和 Load Data InFile 相反的是
Select * From `TableTest` Into OutFile 'C:/Data_OutFile.txt';
把表的数据导出bitsCN.com