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?
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?
Ahh... Im paying 50 points.
Ok, I am going to take a stab in the dark and have you try this code
backup.phpPHP Code:<?
/* 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.");
?>
restore.phpPHP Code:<?php
$tableName = "$tablename_restore";
$backupFile = "$backupfile";
$query = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
$result = mysql_query($query);
?>
PHP Code:<?php
$tableName = "$tablename_restore";
$backupFile = "$backupfile";
$query = "LOAD DATA INFILE "$backupFile" INTO TABLE $tableName";
$result = mysql_query($query);
?>
Last edited by Chris S; 02-22-2006 at 11:44 AM.
I would love to change the world, but they won't give me the source code
Use PHPAdmin ;) You can export tables and the such, and just import the info my using the SQL feature of PHPMyAdmin on the other account.
-Corey
think he wanted it automatic, well you can use a script like above, should work well with cron, becasue there is no way to export the file in phpmyadmin every day, unless by hand...
█ Jake Omann | Developer
█ 888-X10-9668 - jake[@]x10hosting.com
█ x10Hosting - Giving Away Hosting Since 2004
█ Premium Hosting | VPS Services
does it work?
I would love to change the world, but they won't give me the source code
it shouldn't because i made some mistakes
(i was in a rush and trying to hide it from the media center people)
backup.php
restore.phpPHP Code:<?php
include ('db.php');
$tableName = "$tablename_restore";
$backupFile = "$backupfile";
$query = "SELECT * INTO OUTFILE '$backupFile' FROM $tableName";
$result = mysql_query($query);
?>
and name the first file db.phpPHP Code:<?php
include ('db.php');
$tableName = "$tablename_restore";
$backupFile = "$backupfile";
$query = "LOAD DATA INFILE "$backupFile" INTO TABLE $tableName";
$result = mysql_query($query);
?>
I would love to change the world, but they won't give me the source code
if you want to use cron, use something like this
Save the above code as a file in your cgi-bin as "dcopy.sh"Code:#/bin/sh mysql -u <mysql username> -p<mysql password> -e "<mysql query>" <mysql database>
Remember to Insert your info between the <>. All that remains is the query to copy database. Unfortunately, i dont know it!
Create a cron job to point to it and it will be executed at the times you set.
NOw that I ve taken you halfway there how about 25 points :-)
Last edited by chitwa; 03-06-2006 at 09:19 AM.
if you see, I've taken him all the way there except I did just notice that I have made another error in my code.
backup.php:
that should be right FINALLYPHP Code:<?php
include ('db.php');
$tableName = "$tablename_backup";
$backupFile = "$backupfile";
$query = "SELECT * INTO OUTFILE "$backupFile" FROM $tableName";
$result = mysql_query($query);
?>
I would love to change the world, but they won't give me the source code
Thanks works.