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

          主站蜘蛛池模板: 玉环县| 荆州市| 三原县| 清水县| 梓潼县| 宜兴市| 东兰县| 横峰县| 玛曲县| 凉城县| 句容市| 营山县| 民乐县| 都安| 玛曲县| 德昌县| 高陵县| 会东县| 商南县| 苍梧县| 乐陵市| 昌邑市| 句容市| 宝坻区| 兴义市| 射洪县| 普兰店市| 嘉荫县| 玛纳斯县| 渝北区| 张家口市| 武穴市| 石景山区| 登封市| 墨江| 桦川县| 淅川县| 普定县| 陈巴尔虎旗| 织金县| 屯门区|