Forum Moderators: open

Message Too Old, No Replies

Moving a database in MySQL.

         

Dabrowski

3:19 pm on Mar 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ok,

I've been working on my latest site on my laptop. All is well, the database is quite big and now contains some data.

I want to move the database onto my production server now but have no idea how to do it. On past projects the database has only been very small with no data that I wanted to keep, so I just recreated the database by hand as it only took a few minutes.

Is there a tool that can export this on my laptop, and then import on the other server?

rocknbil

3:58 pm on Mar 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



On the command line (or qq this and drop into an exec or `` command in perl:)

mysqldump -h $db_host --user=$sql_login --password=$sql_pass $db_name > mybackup.sql

Move mybackup.sql to your server.

On your server, create the database and user, log into mysql, switch to the database (use database;) then type

source path/to/mybackup.sql

Will recreate all tables and import the data.

physics

7:08 pm on Mar 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good info from rocknbill.

Except that I usually add --opt after mysqldump, which does things like "Include all MySQL specific create options" (see man mysqldump).

Also you can import the new db on the command line on the remote server with

mysql -u $sql_login -p dbname < mybackup.sql
(you'll be prompted for the password)

p.s.
Note that I think you can do this stuff in PHPMyAdmin if you're not comfortable with the command line.

Dabrowski

9:01 pm on Apr 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks guys that worked a treat.