B
Brandon
Guest
Does anyone know how to transfer the contents from one MySql database to another on the same server? Can some one give me the code to do it in Cron?
<?
/* Database Information - Required!! */
/* -- Configure the Variables Below --*/
$dbhost = 'localhost';
$dbusername = 'enigma_meh';
$dbpasswd = '******';
$database_name = 'saxattac_users';
$tablename_backup = "xxxxxx"; //talbe you want to backup
$tablename_restore = "xxxxxx"; //if you want to restore it to a different table
//you do have to fill this in
$backupfile = "xxxxxx"; // the file you want to restore and create the backup into
/* Database Stuff, do not modify below this line */
$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd")
or die ("Couldn't connect to server.");
$db = mysql_select_db("$database_name", $connection)
or die("Couldn't select database.");
?>
<?php
$tableName = "$tablename_restore";
$backupFile = "$backupfile";
$query = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
$result = mysql_query($query);
?>
<?php
$tableName = "$tablename_restore";
$backupFile = "$backupfile";
$query = "LOAD DATA INFILE "$backupFile" INTO TABLE $tableName";
$result = mysql_query($query);
?>
<?php
include ('db.php');
$tableName = "$tablename_restore";
$backupFile = "$backupfile";
$query = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
$result = mysql_query($query);
?>
<?php
include ('db.php');
$tableName = "$tablename_restore";
$backupFile = "$backupfile";
$query = "LOAD DATA INFILE "$backupFile" INTO TABLE $tableName";
$result = mysql_query($query);
?>
#/bin/sh
mysql -u <mysql username> -p<mysql password> -e "<mysql query>" <mysql database>
<?php
include ('db.php');
$tableName = "$tablename_backup";
$backupFile = "$backupfile";
$query = "SELECT * INTO OUTFILE "$backupFile" FROM $tableName";
$result = mysql_query($query);
?>