MYSQL如何使用infile/outfile-创新互联
这篇文章给大家分享的是有关MYSQL如何使用infile/outfile的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
创新互联公司2013年至今,先为南岸等服务建站,南岸等地企业,进行企业商务咨询服务。为南岸企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。由于现有的东家要求使用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”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
分享标题:MYSQL如何使用infile/outfile-创新互联
本文网址:http://myzitong.com/article/cdjgoc.html