Hello Friends ,

There are not just a one way to take mysql database back-up. Here you will find some alternative way to take mysql database back-up.

All you know is the simple way to take mysql database back-up from phpmyadmin by just clicking export button. below is some other way to take back-up from php file by executing OUTFILE sql query.

<?php
///*** This file will help you to take mysql database back-up using PHP – Rakshit Patel **////

include(“mysql-connection.php”);

mysql_select_db(“testing”); // select database

$bkfile = ‘backup/back-up.sql’;
$query      = “SELECT * INTO OUTFILE ‘$bkfile’ FROM ‘test_table’”;
$result = mysql_query($query);

mysql_query($sql) or die(‘Error, backup data failed’);

$query      = “LOAD DATA INFILE ‘$bkfile’ INTO TABLE ‘test_table2′”;
$result = mysql_query($query);

mysql_query($sql) or die(‘Error, load data failed’);

include(“mysql-connection-close.php”);
?>

Here first i have added mysql-connection.php file which will make connection with Mysql database. If you dont know how to make connection with Mysql database than click here.

Now i have selected Mysql database (named testing ). if you have not created database than click here.

After selecting database , you need to execute the query as written above to take back-up or load data in to table using backup file . If you have not created table yet , than click here.

Thats it. Just check the back-up after taking back-up and check table data after loading back-up file.

At last i have included mysql-connection-close.php file.

<?php ///*** This file will close MYSQL connection using PHP – Rakshit Patel **////

mysql_close($connection); // close mysql connection
?>

This is nothing but it will close connection which we have made earlier. Its not necessary but a sign of Good Programmer.

Cheers !!

 

Related posts:

  1. Speed up your blog with Asynchronous Tracking of Google Analytics
  2. Mysql Tutorial – Upload files to MYSQL database
  3. Mysql Tutorial – Download files from MYSQL database
  4. Block IP addresses using .htaccess or .php file