標籤:mysql outfile 匯出與匯入
備份文法:
select * from 表名 where 條件 into outfile ‘/tmp/表名.txt‘;
#注意儲存位置/tmp的許可權;
#注意備份檔案的格式;
恢複文法:
load data infile ‘表名.txt‘ into table 表名 ;
#注意恢複時備份檔案的位置要存放在mysql 資料庫 data 庫目錄下;
範例:根據時間欄位檢索資料:
備份outfile:
select * from PageView where ActionTime >=‘2015-01-01 00:00‘ and ActionTime <=‘2015-01-01 23:59‘ into outfile ‘/tmp/PageView7.txt‘;
#注意時間的欄位; desc 查看時間欄位;
恢複load data infile:
load data infile ‘PageView7.txt‘ into table PageView ;
使用SELECT * INTO OUTFILE 備份:
SELECT * INTO OUTFILE ‘/tmp/xx.txt‘ FIELDS TERMINATED BY ‘,‘ OPTIONALLY ENCLOSED BY ‘"‘ LINES TERMINATED BY ‘\n‘ FROM 表名;
FIELDS TERMINATED BY ‘,‘ 欄位間分割符
OPTIONALLY ENCLOSED BY ‘"‘ 將欄位包圍 對數值型無效
LINES TERMINATED BY ‘\n‘ 分行符號
使用LOAD DATA INFILE恢複:
LOAD DATA INFILE ‘/tmp/xx.txt‘ INTO TABLE test.fii FIELDS TERMINATED BY ‘,‘ OPTIONALLY ENCLOSED BY ‘"‘ LINES TERMINATED BY ‘\n‘;
參考連結:
http://blog.chinaunix.net/uid-24373487-id-3191050.html
http://www.cnblogs.com/stublue/archive/2012/07/02/2573860.html
mysqldump 備份參考連結:
http://linuxboys.blog.51cto.com/9150052/1579346
本文出自 “思想大於技術” 部落格,謝絕轉載!
mysql into outfile 總結