You are here:Home»KB»PC»Windows Family»How to backup a MySQL database?
Sunday, 16 November 2008 14:42

How to backup a MySQL database?

Written by

The following PHP Script will backup the content of a MySQL Database in a GZip file:

{code class="brush: php"}{/code}

If your database is too big and the script times out, here is another PHP script that gives you the opportunity to backup separate Tables.

You will need to create the folder called "DB_backup".

{code class="php"}Database Server could not be reached"); MYSQL_SELECT_DB($db) or die ( "

Database not Available

"); $path = getenv('DOCUMENT_ROOT')."/DB_backup"; $result = MYSQL_QUERY("SHOW TABLES"); $numrow = MYSQL_NUM_ROWS($result); for($i = 0;$i < $numrow;$i++) { $table = MYSQL_RESULT($result,$i); echo "$table ... "; system(sprintf("mysqldump --opt -h $host -u $dbuser -p$dbpw $db $table | gzip > %s/$table.sql.gz",$path)); echo "DONE\n\n"; } MYSQL_CLOSE(); ?>{/code}

Backup by SSH (untested but works on 1and1)

1. Using the Secure Shell interface to log in and run the following commands.

2. use the following command to dump the database to your web space:

mysqldump -h [hostname] -u [username] -p[password] [databasename] > [outputfile])

After pressing [Enter] the system will prompt you for the password of your database.

Once the dump has been completed you will find the outputfile in your web space.

Having filled in all the information the command will look like this:

mysqldump -h db73.oneandone.co.uk -u dbo42764332 -p XXXXXXXX db42764332 > db42764332.dump
Read 713 times Last modified on Tuesday, 06 July 2010 22:17