Test migration using MySql data physical way

        Cloud migration, application generally relates to systems and database systems, which migrate database systems are the most troublesome. Migrating applications commonly used to re-deploy or migrate a physical disk mode, but the database migration patterns of many different scenarios have different migration patterns. General database migration patterns have physical, logical migration in two ways, pay attention to the migration of the database service interruption shortest time, zero data loss. Earlier, we talked to mysqldump logical migration, today we try different physical data migration patterns.

Database directory the most savage way, direct copy disk

1, in the database backup is needed mysql lock (and implement the data off the disk memory), to avoid the write operation occurs in a backup.

MariaDB [(none)]> flush tables with read lock;

2, enter the linux directory to save the database, the database file to see if there is

[root@localhost mysql]# cd /var/lib/mysql/mx

[root@localhost mx]# ls

db.opt  mx.frm  mx.MYD  mx.MYI

3, the database directory directly under the root directory to copy

[root@localhost mx]# cd ..

[root@localhost mysql]# cp -r mx /

4, delete the original database directory

[root@localhost mysql]# rm mx -rf

5, the physical data reduction

[root@localhost mysql]# cp /mx ./ -r

6, be sure to set the master database directory mysql

chown -R mysql:mysql /var/lib/mysql/mx

7, mysql database will be unlocked

MariaDB [none]>unlock tables;

8, check whether the data back to normal

MariaDB [mx]> select * from mx;

+------+

| id   |

+------+

|  123 |

+------+

1 row in set (0.00 sec)

 

        Using physical backup mode has advantages: fast data, Cons: only supports MyIsam database engine and must be the same version of the database, business interruption during the backup process.

 

I hope this article can help you.

More real-time updates, visit public number.    

 

Click here to get the highest ¥ 1888 Ali cloud offering universal vouchers

Guess you like

Origin blog.csdn.net/qq_29718979/article/details/90229218