MySQL Migration to MySQL
UDTS supports MySQL as a data transfer source/target, supporting versions including MySQL (including Percona) 5.5/5.6/5.7/8.0; MariaDB 10.1.2 and above, as well as PolarDB (MySQL-compatible version).
Migration Content
Full and incremental migration of the following content:
- Database, Table structures, and data
- Views
- Functions, Stored Procedures
During full migration, to ensure data consistency and prevent data conflicts, the data in the target database is cleaned before migration. The contents corresponding to this migration, including Database and Table, are specifically cleaned as follows:
Database Name Setting | Table Name Setting | Content to be Cleaned |
---|---|---|
* | Cleans databases in the source, excluding built-in databases (see Note 1) | |
db1,db2,db3 | Cleans multiple DBs as specified by the task (see Note 2) | |
db1 | Cleans a single DB as specified by the task | |
db1 | table1,table2,table3 | Cleans specified multiple tables under a single DB (see Note 3) |
db1 | table1 | Cleans a single table under a single DB as specified by the task |
Notes:
-
- Suppose the output of SHOW DATABASES on the source is:
> SHOW databases;
INFORMATION_SCHEMA
PERFORMANCE_SCHEMA
mysql
sys
mydb1
mydb2
The current built-in databases are mysql
, sys
, INFORMATION_SCHEMA
, PERFORMANCE_SCHEMA
. Excluding these DBs, remaining mydb1
and mydb2
will have the following executed on the target database during migration:
DROP DATABASE IF EXISTS `mydb1`;
DROP DATABASE IF EXISTS `mydb2`;
-
- If the migration task is configured with the
Database Name
as db1,db2,db3, the following will be executed on the target database:
- If the migration task is configured with the
DROP DATABASE IF EXISTS `db1`;
DROP DATABASE IF EXISTS `db2`;
DROP DATABASE IF EXISTS `db3`;
-
- If the migration task is configured with the
Database Name
as db1, and migratingTable Name
is table1,table2,table3, the following will be executed on the target database:
- If the migration task is configured with the
DROP TABLE IF EXISTS `db1`.`table1`;
DROP TABLE IF EXISTS `db1`.`table2`;
DROP TABLE IF EXISTS `db1`.`table3`;
Preconditions
When migrating with UDTS, the Pre-check
can be used to inspect necessary conditions, including:
- Connectivity check, ensuring the accuracy of information such as host address, port, username, and password.
- Permission check, verifying the permissions required for migration.
- Configuration check, such as sql_mode, binlog format, unique key check, etc.
Connectivity Check
Connectivity checks involve verifying the host address
, port
, username
, and password
provided.
-
Host connectivity check: If an incorrect
host address
orport
is entered, a connectivity check failure will occur:Project OR IP:10.19.37.212 OR Vpc:uvnet-u0ecvp, Subnet:subnet-2slodr error, please check again
. Please ensure that the currenthost address
,port
, selectedVPC ID
,subnet
, andproject
are correct. -
Username and password check: If an incorrect username or password is entered, a connectivity check failure will occur:
Error 1045: Access denied for user 'root1'@'10.42.255.213' (using password: YES)
. Please ensure the username and password are correct. -
Firewall and whitelist: If the host address, port, username, and password are correct:
- For a self-hosted MySQL, check the host’s iptables rule.
- If a whitelist is set, contact technical support to obtain the whitelist address.
Permission Check
By default, migration requires the source database account to have SUPER privileges. If SUPER privileges are not available, select the “NoLocks” mode.
If users wish to use the NoBinlog mode during the full stage, SUPER privileges are required on the target database.
Type/Permission | Source Database Permissions (NoLocks Enabled) | Source Database Permissions (NoLocks Disabled) | Target Database Permissions |
---|---|---|---|
Full | ”SELECT”, “REPLICATION SLAVE”, “REPLICATION CLIENT”, “SHOW VIEW”, “PROCESS" | "SELECT”, “REPLICATION SLAVE”, “REPLICATION CLIENT”, “SHOW VIEW”, “RELOAD”, “LOCK TABLES”, “PROCESS" | "SELECT”, “INSERT”, “UPDATE”, “CREATE”, “DROP”, “ALTER”, “DELETE”, “INDEX”, “CREATE VIEW”, “CREATE ROUTINE” |
Incremental | ”SELECT”, “REPLICATION SLAVE”, “REPLICATION CLIENT”, “SHOW VIEW" | "SELECT”, “REPLICATION SLAVE”, “REPLICATION CLIENT”, “SHOW VIEW" | "SELECT”, “INSERT”, “UPDATE”, “CREATE”, “DROP”, “ALTER”, “DELETE”, “INDEX”, “CREATE VIEW”, “CREATE ROUTINE”, “ALTER ROUTINE” |
Full + Incremental | ”SELECT”, “REPLICATION SLAVE”, “REPLICATION CLIENT”, “SHOW VIEW”, “PROCESS" | "SELECT”, “REPLICATION SLAVE”, “REPLICATION CLIENT”, “SHOW VIEW”, “RELOAD”, “LOCK TABLES”, “PROCESS" | "SELECT”, “INSERT”, “UPDATE”, “CREATE”, “DROP”, “ALTER”, “DELETE”, “INDEX”, “CREATE VIEW”, “CREATE ROUTINE”, “ALTER ROUTINE” |
sql_mode Check
To ensure migrations proceed correctly, it is best to keep the sql_mode the same for both the source and target databases. The sql_mode can be queried using the following command:
select @@sql_mode;
--- or
show variables like "sql_mode";
If the sql_mode of the target database and the source database are not consistent, they can be modified using the following command:
SET GLOBAL sql_mode='xxxx';
The specific value can be queried by connecting to the source database.
binlog Format Check
If the migration task type is Incremental
, Full + Incremental
, or a full task that later requires incremental migration, the source database needs binlog to be enabled with the format set to ROW and the image set to FULL.
binlog_format must be ROW
binlog_row_image must be FULL
Query method:
show global variables like 'binlog_format';
show global variables like 'binlog_row_image';
Setting method:
set global binlog_format = "ROW" ;
set global binlog_row_image = "FULL" ;
Note: For MySQL 5.5, there is no binlog_row_image variable, so no setting is needed.
MyISAM Engine Table Check
If the table to be migrated in the source database includes a MyISAM engine table and the target database has GTID enabled, it may lead to MySQL 1785 errors, with an error message such as:
When @@GLOBAL.ENFORCE_GTID_CONSISTENCY = 1, updates to non-transactional tables can only be done in either autocommitted statements or single-statement transactions, and never in the same statement as updates to transactional tables
It is recommended to convert MyISAM engine tables to InnoDB engine tables or turn off GTID mode on the target database. Query method:
# Query in source database if there are MyISAM tables in database db1
select table_schema, table_name
from information_schema.tables
where engine = 'MyISAM'
and table_type = 'BASE TABLE'
and table_schema in (db1);
# Query in target database whether GTID is enabled
show global variables like 'gtid_mode';
Setting method:
# Option 1: Modify the source database
# Change the engine of MyISAM table table1 to InnoDB
alter table table1 ENGINE = InnoDB;
# Option 2: Modify the target database
# Turn off the GTID mode on the target database
set global gtid_mode = "ON_PERMISSIVE";
set global gtid_mode = "OFF_PERMISSIVE";
set global gtid_mode = "OFF";
Character Set Check When Migrating from MySQL to TiDB
TiDB currently supports character sets including ascii/latin1/binary/utf8/utf8mb4
. If a table or a specific field in the source database to be migrated uses character sets outside these supported ones, migration will not be possible.
Query method:
show create table table1;
Setting method:
# Change the character set of table table1 to utf8
alter table task character set utf8;
# Change the character set of column1 in table table1 to utf8
alter table table1 change column1 column1 varchar(200) character set utf8;
Feature Limitations
MyISAM Engine Tables
UDTS supports full migration and incremental synchronization of MyISAM engine tables, but there are limitations:
- Exporting data locks MyISAM tables (reading is not affected) until all data is exported. This might impact services.
- Transactions cannot update both MyISAM and InnoDB tables simultaneously.
- Damaged tables must be repaired before migration.
It is recommended to convert MyISAM engine tables to InnoDB engine tables before using UDTS for migration.
Data Volume
It is recommended that a single full migration task does not exceed 200G in data size, with a maximum support of 500G. If the data to be migrated exceeds 500G, consider splitting the task into multiple parts. UDTS offers multi-dimensional migration methods by database, table, multiple databases, or multiple tables.
If the migration task exceeds 500G and cannot be divided into multiple tasks, please contact technical support.
Other Limitations
- Built-in databases other than ‘test’ are not migrated.
- If DDL statements are executed on the database to be migrated during the dump process, the UDTS task will fail. Users can restart the task at a time when no DDL statements are executed.
- Event and trigger are temporarily unsupported during full and incremental stages.
- Before starting incremental synchronization, event must be turned off.
-- Stop all events SET GLOBAL event_scheduler = OFF; -- If migrating by database, only stop the event of the specified database -- Find the corresponding event and stop it SHOW EVENTS; ALTER EVENT hello DISABLE;
- If the source is Alibaba Cloud MySQL RDS, all tables must have explicit primary keys; otherwise, incremental synchronization is not supported.
- When database names contain special characters like ’$’, only single-database migration is supported.
- During incremental migration, DDL statements only support character sets
ascii/latin1/binary/utf8/utf8mb4
.
Attention
Storage Space
If binlog is enabled on the MySQL target database, the binlog generated by the target database will occupy storage space. When the data volume is large (over 200G), it is recommended to enable the NoBinlog option. In this way, no binlog will be generated during the full migration process, reducing disk demand and accelerating migration speed. If binlog must be enabled during the migration process, please create a larger storage space for the target database or regularly clean up unneeded binlog files to prevent task failure due to insufficient storage space (it is generally estimated that migrating 3TB data generates about 3TB binlog files, meaning 3TB storage for source, 6TB for target).
UDB MySQL supports a binlog auto-cleaning policy based on retention time and disk usage percentage. Refer to UDB documentation for details. If the target database is highly available UDB, an HA alert will be triggered when NoBinlog is enabled. You can ignore this alert and reimplement HA once the full task completes.
If a task fails, you can restart it after adjusting the target database configuration, and the task will be restarted.
Master-Slave Switching
If the source MySQL database is in a master-slave setup, switching impacts UDTS as follows:
- Occurs during full migration, leading to full migration failure, requiring task reboot.
- Occurs during incremental synchronization. No impact if GTID synchronization is used; failure occurs if not, requiring full + incremental setup again.
SSL Secure Connection
To improve link security, SSL certification is supported for database connections. SSL encrypts data on the transport layer, enhancing communication security, though it adds some network response time.
UDTS supports certificates in pem format. If your certificates are in another format, convert them to pem. SSL Secure Connection
can be set in source or target.
How to Use
In either source or target, enable the SSL Secure Connection
option and upload the ca certificate.
Cross-Version Migration
When performing cross-version migration, be aware of any incompatibilities between the source and target databases, such as:
- The default collation
utf8mb4_0900_ai_ci
of MySQL 8.0 is incompatible with MySQL 5.x. To migrate from MySQL 8.0 to 5.x, change collation to a MySQL 5.x compatible type, such asutf8mb4_general_ci
. - MySQL 5.6 supports the
geometry
data type field as an empty string, while MySQL 5.7 and later do not. Ensure thegeometry
field in MySQL 5.6 is not an empty string before migrating to a higher version.
MySQL Form Filling
Data Source Form
Parameter | Description |
---|---|
Address Type | Supports three types: internal, external, and dedicated addresses. Internal addresses require VPC and subnet info; external addresses support both IP and domain names; dedicated addresses support both IP and domains, requiring external network output if a domain is used. |
Port | MySQL connection port |
Username | MySQL connection username |
Password | Password for the connecting MySQL database |
Database Name | MySQL database name. Enter * for all; enter database name for a specific database; for multiple databases input names separated by commas. Note: Incremental migration is unavailable if the database name contains spaces. |
Table Name | MySQL transmission table name. Effective only when “Database Name” is a specific database. Defaults to all tables if left blank; for multiple tables, input names separated by commas. |
Maximum Rate | External/dedicated rate range is 1-56 MB/s; internal rate range is 1-1024 MB/s |
Nolocks | Default is off. Enable if SUPER privileges are unavailable on external RDS services. Check FAQ for obtaining SUPER privileges for UDB. |
SSL Secure Connection | Default is off. Enable if connecting to the database with certificates. See SSL Secure Connection |
Transfer Target Form
Parameter | Description |
---|---|
Address Type | Currently only internal is supported |
Port | MySQL connection port |
Username | MySQL connection username |
Password | Password for the connecting MySQL database |
Maximum Rate | Internal rate range is 1-1024 MB/s |
NoBinlog | When the data source and target both are MySQL, it is possible to set not to write binlog files at the target side during the full phase, default is not disabled. Enabling NoBinlog requires the current user to have SUPER privileges. |
SSL Secure Connection | Default is off. Enable if connecting to the database with certificates. See SSL Secure Connection |
Suggested Rate Configuration Table
Reference values for source speed limit configuration
Database Available Memory Size (G) | Suggested Internal Rate (MB/s) | Suggested External/Dedicated Rate (MB/s) |
---|---|---|
(0, 2) | 10 | 10 |
[2, 4) | 15 | 15 |
[4, 6) | 20 | 20 |
[6, 8) | 30 | 30 |
[8, 10) | 40 | 40 |
[10, 20) | 50 | 50 |
[20, 40) | 60 | 56 |
[40, 60) | 70 | 56 |
[60, 80) | 80 | 56 |
[80, 100) | 90 | 56 |
>=100 | 100 | 56 |
Reference values for target speed limit configuration
Database Available Memory Size (G) | Suggested Internal Rate (MB/s) |
---|---|
(0, 1) | 1 |
[1, 2) | 2 |
[2, 4) | 5 |
[4, 6) | 10 |
[6, 8) | 20 |
[8, 10) | 30 |
[10, 20) | 50 |
[20, 40) | 60 |
[40, 60) | 70 |
[60, 80) | 80 |
[80, 100) | 90 |
>=100 | 100 |