Skip to content

Instantly share code, notes, and snippets.

@shadowhand
Created December 16, 2011 17:40
Show Gist options
  • Save shadowhand/1487069 to your computer and use it in GitHub Desktop.
Save shadowhand/1487069 to your computer and use it in GitHub Desktop.
MySQL Server Migation
<?php
$host = 'remotehost.com';
$servers = array(
'db/username' => 'password',
);
foreach ($servers as $db => $pw)
{
$command = strtr('mysqldump -u:db -p:pw :db | ssh :sv "mysql -u:db -p:pw :db"', array(
':sv' => escapeshellarg($host),
':db' => escapeshellarg($db),
':pw' => escapeshellarg($pw),
));
shell_exec($command);
}
@shadowhand
Copy link
Author

This works best when your server is set up to login using pubkeys, so that you don't have to type your password for every database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment