Mysql Backup with PHP

Mysql Backup with PHP

Database is one of the most important thing in building a website. Therefore, making database backup is also very important. Database backup will avoid loss if there is a crash in our database.

In this article I will try to share a method that i use to make Mysql Backup with PHP. The frist thing that we need to do is making the code it self.

The php code:

$current = date("Y-m-d_H-i-s");
$host = "";//fill it with host name
$user = "";//fill it with user name
$pass = "";//fill it with password
$database = "";//fill it with database name
exec("mysqldump --opt --host=$host --user=$user --password=$pass $database | gzip --best > $database_$current.sql.gz");

That is it, the code will automatically make a backup with extention .sql.gz and save it with the same directory with your code.

You can combine this code with Attachment Email with PHP

Cogratulation you just learn how to make Mysql Backup with PHP.

Good luck.

http://septiadi.com/2011/02/28/mysql-backup-with-php/

Advertisements

One response to “Mysql Backup with PHP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: