How to Backup MySQL Database
- Automatically backup MySQL database to Amazon S3
- Automatically backup MySQL Database on Linux
- Automatically backup MySQL Database with AutoMySQLBackup
- Back Up with MySQLDump
- Backup into an XML File Using PHP
- Use PHP to backup
- Backup via SSH
- Backup with Ubuntu Linux Backup MySQL Server Shell Script
- Backup MySQL database and web server files to an FTP server automatically
- Backup MySQL Database with phpMyAdmin
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.
Just so you know
Sign up for a free Jotform account to create powerful online forms in minutes — with no coding required.
1. Automatically backup MySQL database to Amazon S3
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.
Automatically backup mysql database to Amazon S3
2. Automatically backup MySQL Database on Linux
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.
How to Backup MySQL Database automatically (for Linux users)
3. Automatically backup MySQL Database with AutoMySQLBackup
AutoMySQLBackup 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.).
Backup your MySQL databases automatically with AutoMySQLBackup
4. Back Up with MySQLDump
mysqldump ---user [user name] ---password=[password] [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.
Backing Up With MySQLDump
5. Backup into an XML File Using PHP
XML isn’t the easiest format to restore a table but it can be easier to read.
Backup Your Database into an XML File Using PHP
6. Use PHP to backup
Execute a database backup query from PHP file. Below is an example of using SELECT INTO OUTFILE query for creating table backup:
<?php include 'config.php'; include 'opendb.php'; $tableName = 'mypet'; $backupFile = 'backup/mypet.sql'; $query = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName"; $result = mysql_query($query); include 'closedb.php'; ?>
To restore the backup you just need to run LOAD DATA INFILE query like this :
<?php include 'config.php'; include 'opendb.php'; $tableName = 'mypet'; $backupFile = 'mypet.sql'; $query = "LOAD DATA INFILE 'backupFile' INTO TABLE $tableName"; $result = mysql_query($query); include 'closedb.php'; ?>
How to – Using PHP To Backup MySQL Database
7. Backup 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.
Backup MySQL Database Via SSH
8. Backup with Ubuntu Linux Backup MySQL Server Shell Script
If you have a dedicated VPS server running Ubuntu Linux. Here is how to backup all your mysql server databases to your ftp server
Ubuntu Linux Backup MySQL server Shell Script
9. Backup MySQL database and web server files to an FTP server automatically
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.
$ mysqldump -u root -h localhost -pmypassword faqs | gzip -9 > faqs-db.sql.gz
How to backup MySQL databases, web server files to a FTP server automatically
10. Backup MySQL Database with phpMyAdmin
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.
1. Open phpMyAdmin from your web hosting control panel like cPanel.
2. Select the database from the sidebar navigation panel of phpMyAdmin.
3. Click the Export link from the top navigation bar.
4. Choose Custom option in the Export page.
In the Export page, there will be two options; Quick and Custom. Let’s choose the Custom option.
5. Select the tables that you want to backup.
When you select Custom option, the page will allow us to select tables that we want to take backups. If you are not sure what to select, keep it as it; all tables are selected by default.
6. Choose gzipped option for Compression and keep the rest as is.
Next step is compression. In the center of the page, you will see the compression option that will gain us lots of time. Choose the gzipped option and keep the rest as is.
7. Click the Go button and then your backup file will automatically be downloaded.
We are ready to get our compressed database backup. Just click to the Go button and then your backup file will automatically be downloaded. The file name will be NameOfYourDB.sql.gz file. Depending on your database size, this procedure may take some time.
MySQL Export: How to backup your MySQL database?
Are you using someone else’s backup solution for your MySQL data? Do you care a lot about your data? Are you sure you’re getting a reliable, recoverable backup that’ll work for your business and your application, and won’t impact your critical processes while it runs? Here are ten questions you need to be able to answer.
10 things you need to know about backup solutions for MySQL
Send Comment:
117 Comments:
More than a year ago
10 ways yet: 1, 2, 4, 7, 8, 9 are all ways to invoke mysqldump.
I was hoping to get alternatives to ZRM (which isn't even listed).
The article is fine, just the title a bit misleading.
More than a year ago
The PHP is outdated - mysql_ lib was deprecated in PHP5 and removed in 7.
More than a year ago
I love this blog . This is one of the best blog i ever seen. It's all about what i'm searching for. I love to read this blog again and again . Every time i enter this blog i get something new. This blog inspire me to write new blog. I write a blog name tutorialabc.com. It's about sql,c#,net etc
More than a year ago
Number eleven and surely best for me - try dbForge Studio. Its MySQL Dump tool is very fast and works with great amount of data! Read more here:
More than a year ago
We would recommend our backup tool MySql Backup And Ftp (MySqlBF, ). MySqlBF allows to schedule backups using a Windows Task Scheduler or a custom windows service for a complex backup scenarios.
It supports connecting securely over an SSH connection and has such a unique feature as creating a backup via phpMyAdmin. The tool allows to archive, encrypt and save backups to HDD, FTP, Network or most popular cloud storage services (Dropbox, Amazon S3, Google Drive, SkyDrive, Box) and sends email notifications on success or failure.
More than a year ago
I have used automysqlbackup and Dropbox. It is very simple to install and configure:
More than a year ago
Why it not mention the software "Automatic Backup Scheduler for MySQL"
I think it a good software to back up and restore MySQL databases automatically.
The website is
Hope it helps you.
More than a year ago
I have created a backup script using Java. and executes it remotely. it successfully creates a .sql file in specified folder.
I wants a post that helps me to taking physical backup automatically. at another location.
Thanks every one for all theses posts. Thanks SAM.
More than a year ago
Noupe, thanks for showing so many MySQL backup solutions! Since this post is over three years old, I’d like to make some suggestions for your next article.
Sigh regard to the first option you mentioned, Amazon’s EC2 already has automatic backup. To this, I’d like to add the options offered by the increasingly popular Database-as-a-Solution (DBaaS) solutions, like Amazon’s RDS ( , and the lesser-known Xeround Cloud Database (), among others.
With Amazon’s RDS, aside from automated backups, you also have what they call “Database (DB) Snapshots”. According to their Website: “DB Snapshots are user-initiated and enable you to back up your DB Instance in a known state as frequently as you wish, and then restore to that specific state at any time.”
Xeround adds an alternative they call “Hot” Backups. You can do these “Hot” Backups online, without suffering downtime or interruptions. They let you choose between backups that either automatic or user initiated, on-demand. Does anyone here have experience with these “Hot” Backups?
More than a year ago
I'm pretty curious on what is your conclusion about quality/version control after a while that you wrote this.
More than a year ago
Do any of these solutions work if your data base is hosted externally? e.g. Go Daddy
More than a year ago
Thank you for the article and for all the post that I can read.
Grazie davvero!
More than a year ago
You can also use Auto Backup for MySQL Professional Edition software to schedule automatic backup which is totally free utility. The software can be used to backup MySQL database from the remote server runs under Any Operating Systems, including Unix, Linux, Mac OS, Windows and all.
More than a year ago
thank u but i am not understand u r format, so i request u send the simple format in"how to get the mysql backup"
More than a year ago
thank you for info,
I like to use a phpMybackup Pro,,,
happy blogging
More than a year ago
Hi again,
Sorry for the second post...
Here's my BASH script that I use to backup all of my mySQL databases on a local Linux (Turnkey LAMP 11.3) host:
#!/bin/bash
# Purpose: Backup all mySQL databases
# Author: Jason TEPOORTEN (JTepoorten@smsmt.com)
mysqldump -u root -pmissMantisBT --all-databases | gzip -9
More than a year ago
Hi,
Thanks VERY much for the helpful link.
I used #2. I changed the date format in the filename to reflect YYYYMMDD_HHMMSS as I find it easier to file sort in a directory simply using the filename.
Here's an example of the command I use in the root crontab:
mysqldump -u root -pmissMantisBT --all-databases | gzip -9
More than a year ago
I know best option use phpmyadmin to import and export .
More than a year ago
thanks, very helpful, this is what I was looking for.
More than a year ago
i hav a .csv file when I use the the load data infile it show me that u did syntax error this s not the correct syntax can anyone give me a clear syntax
More than a year ago
Nice collection for db backup.thanks
More than a year ago
thanks man its really helping
More than a year ago
I use Automatic MySQL Database Backup Plugin. It works with Unix and windows servers and doesn't use Cron Tabs either. The best part is that it doesn't backup if nothing has changed which really cuts down on server load since we run a few high traffic sites.
More than a year ago
There's another solution that is useful if you have, like me, multiple dbs to backup.
Here:
More than a year ago
@Peter
I love your 'git' method. I never would have thought of putting mysqldump and git together.
I'm not sure I'll implement it right now though because I'm spending so much time doing things in a quality way that I am wasting to much time on my business. i.e. I am using a backup system (CrashPlan) while using automysqlbackup. I was using git but the learning curve is a bit steep... however it's not an option NOT to use a version control system!
I've also got automated tests (code checker tests, doxygen documentation tests, unit tests, and functional tests via browser). A lot to take on. I know someone who didn't bother with any quality control and made a million creating Google Adsense websites! So I'm not sure if quality equals wealth... but hey... maybe I'm a dumbass!
Still let's see what happens ;-)