Database migration is a problem we often encounter. For a small amount of data, migration will basically not be a problem. In the production environment, migration work is required in the following situations:
There are three common methods for MySQL migration: 1. Export the database directly, copy the file to the new server, and import it on the new server. 2. Use third-party migration tools. 3. Copy the data files and library table structure files directly to the new server and mount them to the MySQL service with the same configuration. The advantages of the first solution are: it will rebuild the data files, reduce the space occupied by the data files, has the best compatibility, rarely has problems with exporting and importing, and is flexible in requirements. Disadvantages: Traditional export and import takes a long time. Advantages of the second solution: After the settings are completed, the transmission is unattended and completed automatically. Disadvantages: Not flexible enough, complicated to set up, long transmission time, and it is difficult to continue transmission from the abnormal location after an abnormality occurs. The advantages of the third solution: less time, files can be transferred at breakpoints, and fewer operation steps. Disadvantages: The MySQL version and configuration in the new and old servers must be the same, which may cause unknown problems. If the database migration is due to business bottlenecks or project transformation, which requires changes to the data table structure (such as partitions and tables), we can only use the first method. Use MySQL's SELECT INTO OUTFILE and LOAD DATA INFILE to quickly export and import data The When you use The following is an example of a project where MySQL is migrated from Windows to Linux with a total data volume of 12G. Export data on Windows platform: Tables.txt is a file that stores the names of data tables. By reading the names of data tables from the file, all tables are exported in a loop. If sub-tables are involved in the process, the exported SQL statements and batch codes can be modified according to the sub-table rules, which is very flexible. @echo off & setlocal enabledelayedexpansion for /f %%i in (tables.txt) do ( set table=%%i echo "dump table -- !table! --" mysql -uroot -p12345678 codetc_old -e "SELECT * INTO OUTFILE 'F:/MySQL/Uploads/!table!.txt' FIELDS TERMINATED BY ',' FROM !table!" ) pause Import data on Linux platform: #!/bin/bash while read line do mysql -uroot -p12345678 codetc_new -e "LOAD DATA INFILE '/var/lib/mysql-files/$line.txt' INTO TABLE $line FIELDS TERMINATED BY ','" done < tables.txt Before importing data, you need to create a table structure on the new machine. It takes about 3 minutes to export 12G of data and about 4 minutes to import it (the execution time will vary depending on the configuration of the machine and is not of reference value) Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links You may also be interested in:
|
<<: Implementation of CentOS8.0 network configuration
>>: How to capture exceptions gracefully in React
1. Preparation before installation 1. Download th...
This article shares the specific code of JavaScri...
Detailed example of getting the maximum value of ...
Sometimes the code is lost and you need to recove...
1. Purchase a server In the example, the server p...
Detailed example of removing duplicate data in My...
This article example shares the specific code of ...
The HTTP status code is a 3-digit code used to in...
1. Command Introduction The stat command is used ...
An absolute URL is used to represent all the conte...
Table of contents 1.parseInt(string, radix) 2. Nu...
Preface Because computer numbers are floating poi...
The specific code for implementing skinning with ...
IE has had problems for a long time. When everyone...
Docker runs multiple Springboot First: Port mappi...