You can use PHP to take backup of a table in MySQL. For this, you need to write the following code:
$dbhost = 'localhost';
$dbuser = 'dbusername';
$dbpass = 'dbpassword';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$table_name = "tablename";
$backup_file = "/var/tmp/tablebck.sql";
$sql = "SELECT * INTO OUTFILE '$backup_file' FROM $table_name";
mysql_select_db('tablename');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not take data backup: ' . mysql_error());
}
echo "Backedup data successfully\n";
mysql_close($conn);
0 Comment(s)