MYSQL如何使用infile/outfile
这篇文章给大家分享的是有关MySQL如何使用infile/outfile的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
创新互联是一家成都网站设计、网站制作,提供网页设计,网站设计,网站制作,建网站,专业公司,网站开发公司,2013年至今是互联行业建设者,服务者。以提升客户品牌价值为核心业务,全程参与项目的网站策划设计制作,前端开发,后台程序制作以及后期项目运营并提出专业建议和思路。
由于现有的东家要求使用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://azwzsj.com/article/jphpps.html