MYSQL如何使用infile/outfile
短信预约 -IT技能 免费直播动态提醒
这篇文章给大家分享的是有关MYSQL如何使用infile/outfile的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
由于现有的东家要求使用MYSQL数据库,所以最近也开始了对MYSQL数据库的进一步的研究,首先介入的当然是一些正常的应用了:
outfile/infile的灵活:
今天接触了下mysql下的outfile和infile感觉和实际使用很贴切,不像ORACLE那么商业化,任何操作都要封装成自己的接口来实现、操作,MYSQL直接通过一个简单的语句就完成了数据的导入、导出,满足了日常的灵活性与可控性。
LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name.txt'
[REPLACE | IGNORE]
INTO TABLE tbl_name
[FIELDS
[TERMINATED BY 'string']
[[OPTIONALLY] ENCLOSED BY 'char']
[ESCAPED BY 'char' ]
]
[LINES
[STARTING BY 'string']
[TERMINATED BY 'string']
]
[IGNORE number LINES]
[(col_name_or_user_var,...)]
[SET col_name = expr,...)]
demo:
示例文件:
e.txt
===========================
1 2
1 2
1 2
3 4
1 2
3 4
3 4
==============================
ab
==============================
1,2;3,4
==============================
mysql> load data infile 'd:e.txt' into table test1;
Query OK, 7 rows affected (0.13 sec)
Records: 7 Deleted: 0 Skipped: 0 Warnings: 0
mysql> load data infile 'd:e.txt' replace into table test1;
Query OK, 7 rows affected (0.06 sec)
Records: 7 Deleted: 0 Skipped: 0 Warnings: 0
mysql> load data infile 'd:ab' replace into table test1 FIELDS TERMINATED by ',' LINES TERMINATED by ';';
Query OK, 2 rows affected (0.09 sec)
Records: 2 Deleted: 0 Skipped: 0 Warnings: 0
mysql> load data infile 'd:e.txt' replace into table test1 FIELDS TERMINATED by ',' LINES TERMINATED by ';' ignore 2
Query OK, 0 rows affected (0.00 sec)
Records: 0 Deleted: 0 Skipped: 0 Warnings: 0
outfile
mysql> select * into outfile 'd:out1.txt' from test1;
Query OK, 23 rows affected (0.00 sec)
mysql> select * into outfile 'd:out2.txt' FIELDS TERMINATED by ',' from test1
-> ;
Query OK, 23 rows affected (0.00 sec)
mysql> select * into outfile 'd:out3.txt' FIELDS TERMINATED by ',' lines terminated by ';' from test1
-> ;
Query OK, 23 rows affected (0.02 sec)
感谢各位的阅读!关于“MYSQL如何使用infile/outfile”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341