文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>MYSQL使用记录之:infile/outfile

MYSQL使用记录之:infile/outfile

时间:2010-11-03  来源:qqmengxue

由于现有的东家要求使用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)

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载