Chan Chen Coding...

          MySQL Auto Backup

          Below is the script example to backup mysql database in command line:-
          $ mysqldump -h localhost -u username -p database_name > backup_db.sql
          If your mysql database is very big, you might want to compress your sql file.
          Just use the mysql backup command below and pipe the output to gzip,
          then you will get the output as gzip file.
          $ mysqldump -u username -h localhost -p database_name | gzip -9 > backup_db.sql.gz
          If you want to extract the .gz file, use the command below:-
          $ gunzip backup_db.sql.gz
          Type the following command to import sql data file:
          $ mysql -u username -p -h localhost DATA-BASE-NAME < data.sql
          In this example, import 'data.sql' file into 'blog' database using vivek as username:
          $ mysql -u vivek -p -h localhost blog < data.sql
          If you have a dedicated database server, replace localhost hostname with with actual server name or IP address as follows:
          $ mysql -u username -p -h 202.54.1.10 databasename < data.sql
          OR use hostname such as mysql.cyberciti.biz
          $ mysql -u username -p -h mysql.cyberciti.biz database-name < data.sql
          If you do not know the database name or database name is included in sql dump you can try out something as follows:
          $ mysql -u username -p -h 202.54.1.10 < data.sql
          To auto backup database, please read 10 ways to Automatically & Manually Backup MySQL Database , here is one example
          [root@sdc-d1-pangaea-devops1 ~]# vi /etc/crontab
          SHELL
          =/bin/bash
          PATH
          =/sbin:/bin:/usr/sbin:/usr/bin
          MAILTO
          =root
          HOME
          =/

          # 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 executed
          59 23 * * tue root mysqldump -u root -proot123 jira > /export/home/web/dbbak/jira/jira_$(date +\%Y\%m\%d).sql
          This script will generate an backup file at 23:59 every Tue.
          Note
          The cron does not regonize `date +%Y%m%d`, so use $(date +\%Y\%m\%d) instead of it.


          -----------------------------------------------------
          Silence, the way to avoid many problems;
          Smile, the way to solve many problems;

          posted on 2012-03-21 17:43 Chan Chen 閱讀(291) 評論(0)  編輯  收藏 所屬分類: DB

          主站蜘蛛池模板: 双桥区| 长治市| 伊宁县| 吉安市| 怀远县| 东乡族自治县| 靖州| 沂源县| 剑河县| 北宁市| 武隆县| 娱乐| 阿荣旗| 余干县| 贞丰县| 玛纳斯县| 常熟市| 巴彦淖尔市| 义乌市| 郧西县| 菏泽市| 寻乌县| 鄂尔多斯市| 定兴县| 华宁县| 郓城县| 酉阳| 威远县| 秦皇岛市| 叙永县| 新巴尔虎右旗| 永嘉县| 乡城县| 含山县| 巧家县| 屏东市| 潍坊市| 郸城县| 康定县| 岳普湖县| 商都县|