Sometimes the website needs to be migrated, and database migration is inevitable. However, there are usually few servers that only run a website. We need to do this without stopping the database [...]
Sometimes you need to migrate the website, and database migration is inevitable. However, there are usually few servers that only run a website. We need to do this without stopping the database and copying the data, here, you can use MySQL's built-in tools mysqldump and mysqlhotcopy
Mysqldump uses an SQL-level backup mechanism to export data tables into SQL script files. When a database is large, it occupies a large amount of system resources and supports commonly used MyISAM and InnoDB
Mysqlhotcopy is only a simple process of cache writing and file copying. It consumes much faster resources and backups than mysqldump. It is particularly suitable for large databases, but note that mysqlhotcopy only supports the MyISAM engine.
Mysqldump can be directly used after MySQL is installed.
To use mysqlhotcopy, Perl support must be installed because mysqlhotcopy is written in prel,
1 installation. MySQL has been installed, in the/usr/local/MySQL directory
Yum-y install Perl-DBI
Wget http://down1.chinaunix.net/distfiles/DBD-mysql-3.0002.tar.gz
Tar zxvf DBD-mysql-3.0002.tar.gz
CD DBD-mysql-3.0002
Perl makefile. pl-mysql_config =/usr/local/MySQL/bin/mysql_config
Make
Make Test
Make install
2. Back up a database
Mkdir-P/data/word/
/Usr/local/MySQL/bin/mysqlhotcopy-user = root-Password = 123456 word/data/Word
You can pack it, for example, word.tar.gz.
3. Recovery
Stop a MySQL database
Tar zxvf word.tar.gz
Modify permissions. Start MySQL