473,320 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Copy MySql DB between servers

code green
1,726 Expert 1GB
How do I update the same MySql database from server 1 to server 2 using a php script.
I can make the connection between the two and 'see' the tables using SHOW TABLES.
Now I want to replace the data of certain tables in server 2 with server 1.
I've looked at mysqldump and mysqlimport but can't find any PHP examples between two servers.
Jul 11 '07 #1
2 1942
code green
1,726 Expert 1GB
Hello. Anybody there?.OK. I'll go some way to solving my own problem.
Found this chunk of code
[PHP] // Source server settings
$from_user = "Put User Here";
$from_password = "Put password here";
$from_database = "Put Database name here";
$from_server = "Put Source Server here";
$from_41 = False;

// Destination Server Settings
$to_user = "Put User here";
$to_password = "Put Password here";
$to_database = "Put Database name Here";
$to_server = "Put Source Server here";
// $to_server = "localhost";

// Don't Edit below here!!!! (Unless you know what your doing).
if ($from_41) {
$theOpt = "--skip-opt ";
} else {
$theOpt = "";
}

$Results = system( "mysqldump $theOpt -h$from_server -u$from_user -p$from_password $from_database | mysql -u$to_user -p$to_password -h$to_server $to_database", $ResultErr );

echo "Results from MySQL import of $DatabaseName with User $User with file $TheFile:\r\n $Results\r\n $ResultErr";[/PHP]At the following address. Will try to make it work then report back!
Expand|Select|Wrap|Line Numbers
  1. http://wiki.i40.com/MigratingmySQL
Jul 12 '07 #2
code green
1,726 Expert 1GB
Struggled with mysqldump all day.
Tried implementing with system() and exec() by creating a backup file (mysqldumper.sql).
The code runs, creates the file but it is empty.
[PHP]$res = exec($dump,$result,$err)[/PHP];exec() returns an empty value, the array $result is empty and $err returns 1;
system() produces similar results.
Have used the full path to mysqldump.exe and tested it is there.
[PHP]$dumpfile = '../../../../mysql/bin/';
if(file_exists($dumpfile))
{
$dumpfile .= 'mysqldump';
$dump = "$dumpfile --opt $this->name -h $this->host -u $this->user > $to_name.sql"; [/PHP]
echoing out $dump gives
Expand|Select|Wrap|Line Numbers
  1. ../../../../mysql/bin/mysqldump --opt db198743945 -h localhost -u root > mysqldumper.sql 
  2.  
Can anybody help?
Jul 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Marc | last post by:
Hello, Newbie here..... Searching and working this for a week now. We too are having the same problems. Using MySql 4.0.14 and there are "no problems" at all.
5
by: Perttu Pulkkinen | last post by:
I want to copy certain tables from server to server b. How do I make it fastly and efficiently with PHP? I wrote below my current start, but it may not be the best approach. Perttu Pulkkinen,...
0
by: Luc Foisy | last post by:
Last week many of our server and client servers had a power problem. Not = quite sure how the servers were handled, wasn't on site, but I don't = think some of these servers got shut down...
1
by: adiavr | last post by:
Hi, I have read up on MySQL failover/replication and decided that weren't many cons to setting up two way replication where two servers are both master and slave to eachother. Here's the my.cnf:...
39
by: Mairhtin O'Feannag | last post by:
Hello, I have a client (customer) who asked the question : "Why would I buy and use UDB, when MySql is free?" I had to say I was stunned. I have no experience with MySql, so I was left sort...
10
by: Simon | last post by:
Hi, I need to export a 200MB database from one domain to another. phpMyAdmin timeout after a while and is not ideal. I don't mind spending money if I have to but this is rather urgent. I...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
8
by: deko | last post by:
I've just loaded phpMyAdmin on a Debian Linux server with Apache2, MySql5 and PHP5. myserver # dpkg -l | grep php ii libapache-mod-php5 5.2.0-8+etch4 ii libapache2-mod-php4 4.4.4-8+etch2 ii...
2
by: 2401 members, members can post | last post by:
Always MultiPost and Cross-Post messages to enhance the chance to reach you. Bob Hi, Ever be in a position of too-much traffic ?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.