How can I move MySQL tables from one physical server to another?
Such as this exact scenario: I have a MySQL server that uses innodb table and is about 20GB size.
I want to move it to a new server, what's the most efficient way to do this?
feedback
|
|
My favorite way is to pipe a sqldump command to a sql command. You can do all databases or a specific one. So, for instance,
You can do all databases with
The only problem is when the database is too big and the pipe collapses. In that case, you can do table by table or any of the other methods mentioned above. | |||
|
feedback
|
|
You don't even need mysqldump if you're moving a whole database schema, and you're willing to stop the first database (so it's consistent when being transfered)
I can't remember if mysqldump handles users and permissions, or just the data ... but even if it does, this is way faster than doing a dump & running it. I'd only use that if I needed to dump a mysql database to then re-insert into some other RDBMS, if I needed to change storage options (innodb vs. myisam), or maybe if I was changing major versins of mysql (but I think I've done this between 4 & 5, though) | |||
feedback
|
There might be this posibility where you move the actual database files ( for my install they are located at /var/lib/mysql ) , but i'm not realy shure how it will act/work out . | ||||
|
feedback
|
|
I recently moved a 30GB database with the following stragegy: Old Server
New Server
| |||
|
feedback
|
|
According to the MySQL 5.0 Certification Study Guide, Chapter 32 Section 32.3.4, Pages 456,457 describe the Conditions for Binary Potability which bring out the following:
There are two major ways based on storage engine to move individual tables. For the given example we will suppose the following:
MyISAM tables If mydb.mytable uses the MyISAM storage engine, the table will physically be manifested as three separate files
The .frm contains the table structure These files are used interdependently to represent the table from a logical standpoint in mysql. Since these file have no further logical association attach to it, migrating a table from one DB server to another. You can even to this from a Windows server to a Linux Server or a MacOS. Of course, you could shutdown mysql and copy the 3 table files. You could run the following:
in one ssh session to hold table as read only and hold the lock for 24 hours. One second later, perform the copy in another ssh session. Then kill the mysql session with the 24 hour lock. You need not wait 24 hours. InnoDB tables Based on the aforementioned quote from the Certification book, there are many factors that govern how to backup a specific InnoDB table. For sake of simplicity, clarity, and brevity, simply perform a mysqldump of the desired table using the --single-transaction parameters to have perfect point-in-time dump of the table. No need to cncern yourself with InnoDB semantics if you just want one table. You can reload that dumpfile to any MySQL server of your choose. Since two questions were merged here (jcolebrand): EDIT If you are more than willing to live with some slow DB performance, you can perform a series of rsyncs from the old server (ServerA) to the new server (ServerB) even while mysql is still running on ServerA. Step 01) install the same version of mysql on ServerB that ServerA has Step 02) On ServerA, run Step 03) rsync /var/lib/mysql of ServerA to /var/lib/mysql on ServerB Step 04) Repeat Step 03 until an rsync takes less than 1 minute Step 05) Step 06) Perform one more rsync Step 07) scp ServerA:/etc/my.cnf to ServerB:/etc/. Step 08) Step 08) Give it a Try !!! CAVEAT You can create a replication slave like this. Just remember to have server-id explcitly set in the master /etc/my.cnf and a different number for server-id in the slave /etc/my.cnf | ||||
|
feedback
|
|
If you just want to move a specific table try:
You can specify more table names above, in the same command. Once the command completes, move the databasename.tablename.sql file to the other server and then restore using:
Note that the back .sql file is created using the mysqldump program, and the restore is done directly into mysql. | |||
|
feedback
|
|
You're going to need to take a downtime. It's going to take a while depending on what your network speed is. I'm going to assume your running MySQL on Linux/Unix. Here's the process I use:
Then proceed as usual getting the local MySQL set up. *Note: you can also use the -c parameter with rsync to add a checksum to the transfer, however this will be sloooow depending on CPU speed. | ||||
|
feedback
|
|
are you moving it to another mysql server db ? if so use, do an export on it
| |||||||
feedback
|
|
Generic linux method:
edit the datadir (and socket) for both mysqld and mysqld_safe (if applicable) to point to the new location, then
I posted this because no one seemed simply list out the least amount of steps to do this and I feel it's the simplest way personally. | |||
|
feedback
|