Load Data InFile 的用法

很文博客hinven.com 数据库评论88字数 666阅读模式
广告也精彩

Load Data InFile是用于批量向数据表中导入记录。
首先创建一个表
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`文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/52477.html

常用如下:
Load Data InFile 'C:/Data.txt' Into Table `TableTest` Lines Terminated By '\r\n';
这个语句,字段默认用制表符隔开,每条记录用换行符隔开,在Windows下换行符为“\r\n”文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/52477.html

C:/Data.txt 文件内容如下面两行:
1 A
2 B
“1”和“A”之间有一个制表符
这样就导进两条记录了。文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/52477.html

自定义语法
Load Data InFile 'C:/Data.txt' Into Table `TableTest` Fields Terminated By ',' Enclosed By '"' Escaped By '"' Lines Terminated By '\r\n';文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/52477.html

Fields Terminated By ',' Enclosed By '"' Escaped By '"'
表示每个字段用逗号分开,内容包含在双引号内文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/52477.html

Lines Terminated By '\r\n';
表示每条数据用换行符分开文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/52477.html

和 Load Data InFile 相反的是
Select * From `TableTest` Into OutFile 'C:/Data_OutFile.txt';
把表的数据导出文章源自很文博客https://www.hinven.com很文博客-https://www.hinven.com/52477.html

工具:作品在线观看

女优:最新作品观看

中文:国语在线观看

weinxin
我的微信
扫一扫更精彩
大家的支持是我更新的动力!!!
 
广告也精彩
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定

拖动滑块以完成验证