
Originally Posted by
Will.Spencer
I use the
source command from the MySQL shell.

I use mysql commands as well. Here's example syntax:
This is ideal if you'd like to migrate a site DB (WordPress, Drupal, etc) and have access to a shell account.
STEP 1: Download/dump your DB contents into a file:
Code:
mysqldump -h<yourhostname> -u<dbusername> -p'<enterpasswordhere>' <olddbname> > <thefilenameyouwant>.sql
STEP 2: Restore/source your old DB contents to the new DB:
Code:
mysql -h<your(new)hostname> -u<dbusername> -p'<enterpasswordhere>' <newdbname>
The command will drop you into mysql. At the mysql prompt enter:
Code:
source filename.sql;
NOTE: filename.sql is the value for <thefilenameyouwant>.sql
With STEP 2, you should see the contents of your DB file scroll by while it imports. This should allow you to quickly verify your dump has worked without feeling the need to leave the prompt.
NOTE: If you are migrating the site to a new machine/hostname:
After STEP 1 (DB Dump), use a text editor (vi, emacs, etc) to open your newly created file:
Example:
Code:
vi <thefilenameyouwant>.sql
You should see something like this:
Code:
-- MySQL dump 10.x
--
-- Host: localhost Database: <olddbname>
-- ------------------------------------------------------
-- Server version 5.x.x
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
<snip>
If your Hostname is changing, do a search and replace to update your hostname in the file. If you are using "localhost" you should be fine. Unless you have a special configuration, the hostname normally only appears at the top.
If your Database name is changing, do a search and replace to update the olddbname to the newdbname. For simple configurations, the database also usually only appears at the top of the file.
Bookmarks