重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3482|回复: 3
打印 上一主题 下一主题

数据导入导出的一些选项格式

[复制链接]
跳转到指定楼层
楼主
发表于 2014-11-12 15:48:12 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
 使用select ...into outfile 'file.name'

select * from city into outfile 'city.bak' fields TERMINATED BY ','

TERMINATED BY 指定间隔符号
示例:导出的文件。

1,Kabul,AFG,Kabol,1780000
2,Qandahar,AFG,Qandahar,237500
3,Herat,AFG,Herat,186800
4,Mazar-e-Sharif,AFG,Balkh,127800
5,Amsterdam,NLD,Noord-Holland,731200
6,Rotterdam,NLD,Zuid-Holland,593321
7,Haag,NLD,Zuid-Holland,440900
8,Utrecht,NLD,Utrecht,234323
9,Eindhoven,NLD,Noord-Brabant,201843
10,Tilburg,NLD,Noord-Brabant,193238
11,Groningen,NLD,Groningen,172701
12,Breda,NLD,Noord-Brabant,160398

引用字符:
(root@localhost) [world]> (root@localhost) [world]> select * from City into outfile 'city.bak' fields TERMINATED BY ','  ENCLOSED BY '"';
示例:
"1","Kabul","AFG","Kabol","1780000"
"2","Qandahar","AFG","Qandahar","237500"
"3","Herat","AFG","Herat","186800"
"4","Mazar-e-Sharif","AFG","Balkh","127800"
"5","Amsterdam","NLD","Noord-Holland","731200"
"6","Rotterdam","NLD","Zuid-Holland","593321"
"7","Haag","NLD","Zuid-Holland","440900"
"8","Utrecht","NLD","Utrecht","234323"
"9","Eindhoven","NLD","Noord-Brabant","201843"
"10","Tilburg","NLD","Noord-Brabant","193238"
"11","Groningen","NLD","Groningen","172701"
"12","Breda","NLD","Noord-Brabant","160398"
"13","Apeldoorn","NLD","Gelderland","153491"
"14","Nijmegen","NLD","Gelderland","152463"

如果你设置了自己的转义字符来代表,回车,换行。制表符。导出时也是按照自己的转义字符来定义。
select * from City into outfile 'city.bak' fields TERMINATED BY ','  ENCLOSED BY '"' escaped by 'i'


指定换行符:
LINES TERMINATED BY

select * from City into outfile 'city.bak' fields TERMINATED BY ','  ENCLOSED BY '"' escaped by 'i' LINES TERMINATED BY '\r' ;


示例:
"1","Kabul","AFG","Kabol","1780000"^M"2","Qandahar","AFG","Qandahar","237500"^M"3","Herat","AFG","Herat","186800"^M"4","Mazar-e-Shariif","AFG","Balkh","127800"^M"5","Amsterdam","NLD","Noord-Holland","731200"^M"6","Rotterdam","NLD","Zuiid-Holland","593321"^M"7","Haag","NLD","Zuiid-Holland","440900"^M"8","Utrecht","NLD","Utrecht","234323"^M"9","Eiindhoven","NLD","Noord-Brabant","201843"^M"10","Tiilburg","NLD","Noord-Brabant","193238"^M"11","Groniingen","NLD","Groniingen","172701"^M"12","Breda","NLD","Noord-Brabant","160398"^M"13","Apeldoorn","NLD","Gelderland","153491"^M"14","Niijmegen","NLD","Gelderland","152463"^M"15","Enschede","NLD","Overiijssel","149544"^M"16","Haarlem","NLD","Noord-Holland","148772"^M"17","Almere","NLD","Fl


指定换行符后导出的文件格式就成了这样。建议不修改换行符格式。
用什么格式导出的。就用什么格式导入
select * from City into outfile 'city.bak' fields TERMINATED BY ','  ENCLOSED BY '"' escaped by 'i' LINES TERMINATED BY '\r' ;



load data infile 'city.bak' into table city_copy fields  TERMINATED BY ',' ENCLOSED BY '"' escaped by 'i' LINES TERMINATED BY '\r' ;


导出的格式文件。都在服务器端。要想从客户端的机器上导入数据。需要加上local 选项。
示例:
(win_ssl@192.168.154.190) [world]> load data local infile 'city.bak' into table
city_copy fields  TERMINATED BY ',' ENCLOSED BY '"' escaped by 'i' LINES TERMINA
TED BY '\r' ;

city.bak 是从linux主机上传送回来的。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

沙发
发表于 2014-11-12 17:53:09 | 只看该作者

在oracle中通过 spool方式产生的 类似输出,

"1","Kabul","AFG","Kabol","1780000"
"2","Qandahar","AFG","Qandahar","237500"
"3","Herat","AFG","Herat","186800"
"4","Mazar-e-Sharif","AFG","Balkh","127800"
"5","Amsterdam","NLD","Noord-Holland","731200"
"6","Rotterdam","NLD","Zuid-Holland","593321"
"7","Haag","NLD","Zuid-Holland","440900"
"8","Utrecht","NLD","Utrecht","234323"
"9","Eindhoven","NLD","Noord-Brabant","201843"
"10","Tilburg","NLD","Noord-Brabant","193238"
"11","Groningen","NLD","Groningen","172701"
"12","Breda","NLD","Noord-Brabant","160398"
"13","Apeldoorn","NLD","Gelderland","153491"
"14","Nijmegen","NLD","Gelderland","152463"

是否也可以导入到 mysql

回复 支持 反对

使用道具 举报

板凳
发表于 2014-11-12 17:54:27 | 只看该作者

这里的导入,有点象oracle里面的 sqlloader吧 。

 

回复 支持 反对

使用道具 举报

地板
 楼主| 发表于 2014-11-12 20:07:13 | 只看该作者
 通过 oracle 导出的格式化 文本是可以导入MySQL中的。设置好 格式就可以无错的导入导出
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-11-28 14:27 , Processed in 0.111415 second(s), 21 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表