您好,登錄后才能下訂單哦!
1、select into outfile可以導出數據到指定目錄下的文件中
語法:
SELECT ... INTO OUTFILE 'file_name' [CHARACTER SET charset_name] [export_options] export_options: [{FIELDS | COLUMNS} [TERMINATED BY 'string'] [[OPTIONALLY] ENCLOSED BY 'char'] [ESCAPED BY 'char'] ] [LINES [STARTING BY 'string'] [TERMINATED BY 'string']
2、示例如下:
1)查看要導出數據的表t1
mysql> select * from t1; +------+--------+ | id | name | +------+--------+ | 1 | wang | | 2 | steven | | 3 | tiger | | 4 | lilu | +------+--------+ 4 rows in set (0.00 sec)
2)查看導出的文件
[mysql@oneproxy outfile]$ more t1.file 1,"wang" 2,"steven" 3,"tiger" 4,"lilu"
3)創建要導入的表t2;
mysql> create table t2 as select * from t1 where 1=2; Query OK, 0 rows affected (0.03 sec)
4)將導出的數據導入t2
mysql> LOAD DATA INFILE '/mysql/outfile/t1.file' INTO TABLE t2 FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'; Query OK, 4 rows affected (0.01 sec) Records: 4 Deleted: 0 Skipped: 0 Warnings: 0
5)查看導入的數據
mysql> select * from t2; +------+--------+ | id | name | +------+--------+ | 1 | wang | | 2 | steven | | 3 | tiger | | 4 | lilu | +------+--------+ 4 rows in set (0.00 sec)
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。