patternsqlMinor
Fastest way to move a database from one server to another
Viewed 0 times
waymovedatabaseonefastestanotherserverfrom
Problem
I'm moving a single MySQL database (~10GB uncompressed) from one server to another on the same network. The current MySQL version is
I realize this basic question has probably been asked 1000 times before but most of the ones I've seen don't mention changing versions & supporting both MyISAM and InnoDB.
5.1.41 and the new version is 5.5.24. The database contains both MyISAM and InnoDB tables. Is it possible to use this method:- Shut down MySQL on both servers
- Copy the
/datadirectory from old server to new server
- Start new server
I realize this basic question has probably been asked 1000 times before but most of the ones I've seen don't mention changing versions & supporting both MyISAM and InnoDB.
Solution
If you are changing versions, DO NOT MOVE THE mysql SCHEMA.
Why should you not move the mysql folder? It has to do with the authentication privileges.
The number of columns in mysql.user is different from version to version
If you run
I wrote about this before
It is OK to move everything else. On the new machine that has MySQL 5.5.24, do this:
So, the question remains:
How do you move the User Privileges in the old MySQL 5.1.41 to MySQL 5.5.24 ???
There are two ways to do this starting on the MySQL 5.1.41 machine:
METHOD #1 : Use pt-show-grants
This Percona Toolkit program move print out the User Permission in Pure SQL. You could run the result output into a Text File. Then, execute the Text File in MySQL 5.5.24. End of Story.
METHOD #2 : Emulate pt-show-grants
I made my own technique for pt-show-grants
Either way, move MySQLUserGrants.sql over to the MySQL 5.5.24 machine and execute the script
I wrote about this before : importing myisam 5.0 database into a 5.5 innodb server
Why should you not move the mysql folder? It has to do with the authentication privileges.
The number of columns in mysql.user is different from version to version
If you run
desc mysql.user- You will see 31 rows for MySQL 4.1
- You will see 37 rows for MySQL 5.0
- You will see 39 rows for MySQL 5.1
- You will see 42 rows for MySQL 5.5
I wrote about this before
- Cannot GRANT privileges as root
- Mysql users deleted
It is OK to move everything else. On the new machine that has MySQL 5.5.24, do this:
mv /var/lib/mysql /var/lib/mysql/mysql55
mkdir /var/lib/mysql
rm -f /var/lib/mysql/mysql/*
cp /var/lib/mysql/mysql55/* /var/lib/mysql/mysql/*
chown -R mysql:mysql /var/lib/mysql
service mysql startSo, the question remains:
How do you move the User Privileges in the old MySQL 5.1.41 to MySQL 5.5.24 ???
There are two ways to do this starting on the MySQL 5.1.41 machine:
METHOD #1 : Use pt-show-grants
This Percona Toolkit program move print out the User Permission in Pure SQL. You could run the result output into a Text File. Then, execute the Text File in MySQL 5.5.24. End of Story.
pt-show-grants ... > MySQLUserGrants.sqlMETHOD #2 : Emulate pt-show-grants
I made my own technique for pt-show-grants
mysql -hhostaddr -umyuserid -pmypassword --skip-column-names -A -e"SELECT CONCAT('SHOW GRANTS FOR ''',user,'''@''',host,''';') FROM mysql.user WHERE user<>''" | mysql -hhostaddr -umyuserid -pmypassword --skip-column-names -A | sed 's/$/;/g' > MySQLUserGrants.sqlEither way, move MySQLUserGrants.sql over to the MySQL 5.5.24 machine and execute the script
I wrote about this before : importing myisam 5.0 database into a 5.5 innodb server
Code Snippets
mv /var/lib/mysql /var/lib/mysql/mysql55
mkdir /var/lib/mysql
<scp or rsync /var/lib/mysql of MySQL 5.1.41 over to /var/lib.mysql of MySQL 5.5.24>
rm -f /var/lib/mysql/mysql/*
cp /var/lib/mysql/mysql55/* /var/lib/mysql/mysql/*
chown -R mysql:mysql /var/lib/mysql
service mysql startpt-show-grants ... > MySQLUserGrants.sqlmysql -hhostaddr -umyuserid -pmypassword --skip-column-names -A -e"SELECT CONCAT('SHOW GRANTS FOR ''',user,'''@''',host,''';') FROM mysql.user WHERE user<>''" | mysql -hhostaddr -umyuserid -pmypassword --skip-column-names -A | sed 's/$/;/g' > MySQLUserGrants.sqlContext
StackExchange Database Administrators Q#19219, answer score: 6
Revisions (0)
No revisions yet.