2

I'm trying to manage a way of edit content on test_db and when I'm happy with results use a button to update the backup_db, just like you get in blogger per example. When you're happy, you choose the option to publish and your edits go online.

Having no idea on how to, I Googled a while and made this php script.

<?php
$connection = mysql_connect("localhost", "user", "pass") or die("Error!: " . mysql_error()." : ".$connection);

mysql_select_db("test_db") or die (mysql_error()." : ".$connection);

$sql = "mysqldump -h [localhost] -u [user] - p[pass] test_db | mysql -h [localhost] -u [user] -p[pass] backup_db";

system($sql);

mysql_close($connection);

?>

it doesn't work. How can I do this?

3
  • Accept your recent questions. Commented Apr 26, 2011 at 21:56
  • Please refine your question. You wrote PHP code, which connects to a mySQL instance, and shell code, which executes mysql-tools. Both aren't related. What you do using mysql_* fuctions, doesn't affect the mysqldump tool and vice versa. Commented Apr 26, 2011 at 22:00
  • What I want is to clone content from 1 db to another Commented Apr 26, 2011 at 22:07

1 Answer 1

5

Mysqldump is a command line utility, not a SQL command.

Try this:

<?php exec('mysqldump -h [localhost] -u [user] -p[pass] test_db | mysql -h [localhost] -u [user] -p[pass] backup_db');
Sign up to request clarification or add additional context in comments.

5 Comments

Just to check, you are substituting your actual connection data, right? Like exec('mysqldump -h localhost -u bob -pPASSWORD test | mysql -h localhost -u bob -pPASSWORD test_backup'); 'cause that works for me. Try doing it manually on the command line until it works and then copy/paste that into your PHP.
sorry for late reply, it doesn't work, changed my settings of course, but no results, either on localhost or in webserver :-(
I was using [username] [password] with the brackets... :-( Thanks for help
no space between the dash and the p switch(SO won't let me change less than 6 words or so :+)
and depending on privileges aka user rights, using the --single-transaction switch might be necessary (I had to...).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.