Chinaunix首页 | 论坛 | 博客
  • 博客访问: 592723
  • 博文数量: 207
  • 博客积分: 10128
  • 博客等级: 上将
  • 技术积分: 2440
  • 用 户 组: 普通用户
  • 注册时间: 2004-10-10 21:40
文章分类

全部博文(207)

文章存档

2009年(200)

2008年(7)

我的朋友

分类: Mysql/postgreSQL

2009-03-29 11:56:47

MySQL is one of the most popular open source database management system for the development of interactive Websites.

If your site stores its sensitive data in a MySQL database, you will most definitely want to backup that information so that it can be restored in case of any disaster (we all have been there).

There are several ways to backup MySQL data. In this article we’ll look at how to backup your databases using different methods, we will also learn how to achieve an automatic backup solution to make the process easier. Starting with the mysqldump utility that comes with MySQL, we will review several examples using mysqldump, including the backup of your database to a file, another server, and even a compressed gzip file and send it to your email.

1. Automatically backup mysql database to Amazon S3

MySQL Backup Solution

Many of users use Amazon S3 to backup their mysql databases. Here is an automated script which does this task of taking the backup of a mysql database and then moving it to the Amazon S3.

2.

  1. 15 2 * * * root mysqldump -u root -pPASSWORD --all-databases | gzip > /mnt/disk2/database_`data ' %m-%d-%Y'`.sql.gz  

This post will show you how to backup MySQL Database automatically if you are a linux user. You can use cron to backup your MySQL database automatically.”cron” is a time-based scheduling utility in Unix/Linux
operating system.

3.

has some great features to: backup a single database, multiple databases, or all the databases on the server; each database is saved in a separate file that can be compressed (with gzip or bzip2); it will rotate the backups and not keep them filling your hard drive (as normal in the daily backup you will have only the last 7 days of backups, the weekly if enabled will have one for each week, etc.).

4.

  1. mysqldump ---user [user name] ---password=[password]   
  2. [database name] > [dump file]  

In this article we’ll look at how to backup our databases using the mysqldump utility that comes with MySQL. Several examples will be reviewed using mysqldump, including the backup of your database to a file,
another server, and even a compressed gzip file.

5.

  1. mysqldump ---user [user name] ---password=[password]   
  2. [database name] > [dump file]  

Here’s a PHP snippet that outputs your database as XML. XML isn’t the easiest format to restore a table but it can be easier to read.

6.

Execute a database backup query from PHP file. Below is an example of using SELECT INTO OUTFILE query for creating table backup:

  1. include 'config.php';   
  2. include 'opendb.php';   
  3.   
  4. $tableName  = 'mypet';   
  5. $backupFile = 'backup/mypet.sql';   
  6. $query      = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";   
  7. $result = mysql_query($query);   
  8.   
  9. include 'closedb.php';   
  10. ?>  

To restore the backup you just need to run LOAD DATA INFILE query like this :

  1. include 'config.php';   
  2. include 'opendb.php';   
  3.   
  4. $tableName  = 'mypet';   
  5. $backupFile = 'mypet.sql';   
  6. $query      = "LOAD DATA INFILE 'backupFile' INTO TABLE $tableName";   
  7. $result = mysql_query($query);   
  8.   
  9. include 'closedb.php';   
  10. ?>  

7. Backup MySQL Database Via SSH

A simple solution to backup your large MySQL databases through SSH. You will need to enable shell access inside your Plesk control panel and use a utility such as PuTTY to log into your server via SSH.

8. How to e-mail yourself an automatic backup of your MySQL database table with PHP

This script will send an e-mail to you with an .sql file attached, thus enabling you to back up specific tables easily. You could even set up an e-mail account just to receive these backups…

9.

If you have a dedicated VPS server running Ubuntu Linux. Here is how to backup all your mysql server databases to your ftp server

10.

This is a simple backup solution for people who run their own web server and MySQL server on a dedicated box or VPS. The main advantage of using FTP or NAS backup is a protection from data loss.First you will need to backup each database with mysqldump command, Automating tasks of backup with tar, Setup a cron job and generate FTP backup script.

  1. $ mysqldump -u root -h localhost -pmypassword faqs | gzip -9 > faqs-db.sql.gz  

11.

You can easily create a dump file(export/backup) of a database used by your account. In order to do so you should access the phpMyAdmin tool available in your cPanel.

阅读(939) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~