mysql 備份滿足特定條件的資料

來源:互聯網
上載者:User

標籤:sel   sql   mysqldump   mysql   mina   from   sele   檔案   mysq   

使用mysql資料匯出進行備份時,會備份整個表的資料,有時候只想備份一部分資料,這個時候可以使用如下方法:

1. 使用insert into 和 select結合:

insert into talbe_bak(`id`,`name`) select `id`,`name` from table_data where stat_time >= "2017-08-30" and stat_time < "2017-9-03";

這樣會將滿足where限制的資料備份到新的table_bak表中。

2. 使用select into outfile將資料備份到檔案:

SELECT `id` INTO OUTFILE "/tmp/result.text" FIELDS TERMINATED BY ‘,‘ OPTIONALLY ENCLOSED BY ‘"‘ LINES TERMINATED BY ‘\n‘ FROM table_data;

這種方法需要有運行mysql服務的機器的操作許可權。部分雲端資料庫不會提供對運行mysql服務的機器的操作許可權,所以這種方法不一定適用。

3. mysqldump -w

mysqldump -u root -p password table_data –where stat_time >= "2017-08-30" > tmp.dump

此法未測試。

 

mysql 備份滿足特定條件的資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.