mysql 資料備份

來源:互聯網
上載者:User

標籤:

 

每天淩晨 2 點備份資料

crontab -e

0 2 * * * mysqldump ${mysqldir}/bin/mysqldump  -h$host -P$port -uadmin -p"$passwd" --events  --flush-logs --master-data=2  --all-databases| gzip > ${dailyBackupDir}/$date/allback.sql.gz

 

計劃任務這些命令要寫絕對路徑

 

crontab 查看、編輯和刪除

    -u 指定使用者名稱,預設是目前使用者。如果是在 su 命令下,應該總是使用 -u 選項(for safety‘s sake)

    -l 列出當前計劃任務

    -r 刪除目前使用者的計劃任務

    -e Edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables.  The specified editor must edit the file in place; any editor that unlinks the file and recreates it cannot be used.  After you exit from the editor, the modified crontab will be installed automatically.

linux Crontab 使用

cron服務每分鐘不僅要讀一次 /var/spool/cron 目錄內的所有檔案,還需要讀一次 /etc/crontab 檔案。配置這個檔案也能讓cron執行任務。使用crontab命令是對使用者級任務的配置,而編輯 /etc/crontab 檔案是對系統級任務的配置

 

mysqldump 常用方法:

(1) 匯出整個資料庫(包括資料庫中的資料)

    mysqldump -u username -p dbname > dbname.sql

(2) 匯出資料庫結構(不含資料)

    mysqldump -u username -p -d dbname > dbname.sql

(3) 匯出資料庫表(包括資料庫中的資料)

    mysqldump -u username -p dbname tablename > tablename.sql

(4) 匯出資料庫表結構(不含資料)

    mysqldump -u username -p -d dbname tablename > tablename.sql

 

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.