Linux下實現MySQL資料庫自動備份

來源:互聯網
上載者:User

標籤:tail   sql   檔案   指令碼   inux   crontab   span   目錄   tab   

1.給mysql建立使用者備份的角色,並且授予角色SELECT, RELOAD, SHOW DATABASES, LOCK TABLES等許可權。

mysql> create user ‘backuper‘@‘localhost‘ identified by ‘********‘;Query OK, 0 rows affected (0.00 sec)mysql> grant SELECT, RELOAD, SHOW DATABASES, LOCK TABLES on *.* to backuper@localhost;Query OK, 0 rows affected (0.00 sec)


2.在系統中找到儲存空間比較大的硬碟建立備份目錄,並且建立shell指令碼

[[email protected] backup]# vim backup_qianyu_veeker_db.sh#!/bin/bashmysqldump -ubackuper -p******** qianyu_veeker_db > /home/mysql/backup/qianyu_veeker_db_$(date +%Y%m%d_%H%M%S).sql


注意:-u和使用者名稱中間是沒有空格的,-p和密碼也是這樣的。

3.添加計劃任務,需要安裝crontab
vixie-cron 軟體包是 cron 的主程式;
crontabs 軟體包是用來安裝、卸裝、或列舉用來驅動 cron 守護進程的表格的程式。

[[email protected] ~]# yum -y install vixie-cron[[email protected] ~]# yum -y install crontabs


4.設定開機啟動

[[email protected] ~]# chkconfig --level 345 crond on


5.修改/etc/crontab檔案,添加需要周期執行的任務

[[email protected] etc]# vim crontabSHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=rootHOME=/# For details see man 4 crontabs# Example of job definition:# .---------------- minute (0 - 59)# |  .------------- hour (0 - 23)# |  |  .---------- day of month (1 - 31)# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat# |  |  |  |  |# *  *  *  *  * user-name command to be executed0 0 * * * /home/mysql/backup/backup_qianyu_veeker_db.sh


6.啟動crontab服務

[[email protected] etc]# service crond startStarting crond: [  OK  ]

 ,

Linux下實現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.