Migrating MySQL-PXC Data to MySQL-MGR
TOC
PrerequisitesNotesWorkflowCheck MySQL-PXC Cluster StatusLocate MySQL-PXC Read/Write NodesStop MySQL-PXC from Providing External ServicesCreate MySQL-MGR InstanceCheck MySQL-MGR Cluster StatusLocate MySQL-MGR Read/Write NodesDetermine Which Databases Need to Be Backed Up from MySQL-PXCDeploy MySQL-MGR Container for Backup and RecoveryCreate PVCCreate PVDeploy MySQL-MGR ContainerBackup MySQL-PXC Business DatabasesRestore Business DataBackup MySQL-PXC Business AccountsImport Business Application AccountsAdditional: Using mysqldump Backup Method on the Compute Node (Host)Prerequisites
-
MySQL-PXC nodes must be down.
-
The cluster must have sufficient CPU, memory, storage, and other resources to create a MySQL-MGR cluster with the same specifications as MySQL-PXC.
Notes
-
The application side should update the MySQL driver to the MySQL-MGR version; you can refer to Connectors and APIs.
-
Use
utf8mb4character set.-
The application side should use
utf8mb4. -
On the database side, convert the library and tables to
utf8mb4.
The SQL for character conversion is as follows.
Tip: The larger the amount of data in the table, the longer the conversion time.
-
-
MySQL-MGR enforces that tables must have a primary key.
-
Even if there is no primary key in the table, an
INVISIBLEprimary key will be automatically created during import into MySQL-MGR; it is recommended that business sides use explicit primary keys.Tip: It will appear in
SHOW TABLE, but theSELECTwill hide this field. -
To find tables in the business database that lack a primary key:
-
Add an auto-incrementing primary key:
-
Workflow
Note: When using the example code in this document, please replace with actual instance parameters.
Check MySQL-PXC Cluster Status
The MySQL-PXC cluster status must be normal before backing up data.
-
In the left navigation bar, click MySQL-PXC.
-
Click Namespace Name.
-
Click Instance Name.
-
In the Details tab, Basic Information, Resource Configuration, and ProxySQL status should be Running.
-
In the Topology tab, the status of each ProxySQL and MySQL node should be Normal.
Locate MySQL-PXC Read/Write Nodes
-
Find the IP of ProxySQL.
-
Connect to any ProxySQL Pod to find the read/write nodes.
From the output, determine the name of the MySQL-PXC to which the read/write node demo-pxc-0.demo-pxc.demo-ds1.svc.cluster.local belongs.
Stop MySQL-PXC from Providing External Services
Note: Do not perform write operations on the application side, as this will result in an incomplete backup.
-
In the left navigation bar, click MySQL-PXC.
-
Click Namespace Name.
-
Click Instance Name.
-
Click Actions > Update.
-
Click YAML.
-
Change the value of the
pxc.proxysql.sizeparameter to0. -
Click Update.
Create MySQL-MGR Instance
Note: The resource specifications for the created MySQL-MGR instance should not be lower than those of the MySQL-PXC instance.
Check MySQL-MGR Cluster Status
-
In the left navigation bar, click MySQL-MGR.
-
Click Namespace Name.
-
Click Instance Name.
-
In the Details tab, Basic Information, Resource Configuration, and MySQL Router status should be Running.
-
In the YAML tab, the values of
status.conditions.typeandstatus.stateshould beready.
Locate MySQL-MGR Read/Write Nodes
Nodes with MEMBER_ROLE as PRIMARY are the read/write nodes of MySQL-MGR.
Determine Which Databases Need to Be Backed Up from MySQL-PXC
-
Exclude MySQL system databases:
information_schema,mysql,performance_schema, andsys. -
For business databases: Record the business databases to back up, and when using the
mysqldumpbackup tool, specify the databases with the-Boption.
For example, from the following queried database list, you need to back up the business databases test1, test2, and test3.
Deploy MySQL-MGR Container for Backup and Recovery
Create PVC
-
In the Container Platform view, in the left navigation bar, click Storage > Persistent Volume Claims.
-
Click Create Persistent Volume Claim.
-
Fill in the PVC configuration parameters.
Note: Use TopoLVM as the storage class.
-
Click Create; the PVC status should be Pending Binding.
Create PV
Please contact the Platform Administrator to create a PV based on the following YAML. After creating the PV, check that the PVC status is Bound.
Deploy MySQL-MGR Container
-
Check the MySQL-MGR image address.
-
In the Container Platform view, in the left navigation bar, click Compute Components > Deployments.
-
Click Create Deployment.
-
Select Input method, fill in Image Address, and click OK.
-
In Pods > Volumes, click Add.
-
Fill in the volume configuration, using the PVC created in this document as the storage volume for the MySQL container.
-
Click Add.
-
Fill in the container configuration.
-
Click Create.
Backup MySQL-PXC Business Databases
-
Obtain the IP of the MySQL-PXC read/write Pod.
-
Obtain the root password for MySQL-PXC.
-
Enter the MySQL backup and recovery container created in this document, for example, Pod name is
mgr-backcup-9f87d46c4-kwkps.Tip: The Pod name can be viewed in the container group list of this deployment.
-
Backup the business database.
Parameter explanation:
--password: Root password of MySQL-PXC.--host: Specify the IP address of the read/write Pod of MySQL-PXC.-B: Specify the names of the business databases to back up in MySQL-PXC, separated by spaces. -
Check the size of the logical backup.
Restore Business Data
Backup MySQL-PXC Business Accounts
-
Enter the MySQL-MGR Pod to back up the MySQL-PXC user table.
-
Obtain the SQL statements for the accounts:
INSERT INTO. -
Delete the MySQL-PXC system users, keeping only the business application accounts.
-
Delete system accounts:
('localhost','root'),('localhost','mysql.session'),('localhost','mysql.sys'),('%','root'),('%','operator'),('%','monitor'),('localhost','clustercheck'). -
Retain business application accounts:
test_user_1,test_user_2,test_user_3.
-
Import Business Application Accounts
-
Modify the inserted account records.
Note: Do not import the root account.
MySQL-MGR has added 6 fields to
mysql.usercompared to MySQL-PXC, so when inserting account records, the following 6 fields need to be added:Create_role_priv: Y,Drop_role_priv: Y,Password_reuse_history: NULL,Password_reuse_time: NULL,Password_require_current: NULL,User_attributes: NULL. Thus, appending the following values to each insert record:, 'Y', 'Y', NULL, NULL, NULL, NULL. -
Insert account records into MySQL-MGR.
-
Verify whether the accounts are functioning correctly.
Additional: Using mysqldump Backup Method on the Compute Node (Host)
If the current cluster lacks resources and a same-spec MySQL-MGR cluster has not been deployed, you can use mysqldump on the host machine to perform the backup.
Procedure:
-
Ensure that the MySQL-PXC cluster status is normal.
-
Stop business read/write and set the ProxySQL replicas to 0.
-
Perform a backup of MySQL-PXC.