您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章给大家分享的是有关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”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。