This topic describes how to migrate data from VMware Tanzu SQL with MySQL for VMs on Tanzu Application Service (TAS) for VMs to VMware SQL with MySQL for Kubernetes.
The migration process involves backing up the MySQL for VMs instances using the utility mysqldump, and restoring them under MySQL for Kubernetes.
Note: Currently MySQL for VMs supports MySQL 5.7, while MySQL for Kubernetes supports MySQL 8
Before following the migration steps, you must:
mysqldump 5.7, to connect to MySQL service instances externally, take a logical backup, and store the backup. Refer to How to install & run mysqldump for an example installation procedure. Install the utility relevant to your local machine operating system.mysql 8, to connect to MySQL on Kubernetes externally, and load the backup.service_instance_db. For details on schemas and databases to backup and restore, refer to Create a Tanzu SQL for VMs Logical Backup.Review the following important points before starting the backup process: - The MySQL service instance must be configured for external access (either using service gateway or CF SSH). - mysqldump 5.7 should be used against a MySQL service instance. - Take care to backup routines, triggers, events, and other objects as needed. - You may wish to shut down applications connecting to the MySQL service instance that may continue to change the data.
For each MySQL for VMs service instance, use mysqldump to create a logical backup. For details on how to manually create a logical backup with mysqldump, refer to create a logical backup
Log in to TAS, and list the service keys for the MySQL service instance:
cf service-keys <SERVICE_INSTANCE_NAME>
where:
SERVICE_INSTANCE_NAME is the name of the MySQL service instanceFetch the database, username, and password for each service key:
cf service-key <SERVICE_INSTANCE_NAME> <SERVICE_KEY_NAME> | tail -n +3 | jq '{database: .name, username: .username, password: .password}'
where:
SERVICE_INSTANCE_NAME is the name of the MySQL service instanceSERVICE_KEY_NAME is the name of the MySQL service keyAn example output could be:
cf service-key test-single-node key | tail -n +3 | jq '{database: .name, username: .username, password: .password}'
{
"database": "service_instance_db",
"username": "c67a09469fd349b5ac600893dff4cee0",
"password": "apv1wll5zzv470w1"
}
Note which users have read-only access instead of the default write access.
Create the MySQL instances. For details, refer to Creating and Deleting MySQL Instances.
Access the mysql container on the Kubernetes cluster:
kubectl exec -it <POD_NAME> -c mysql -- bash
where:
POD_NAME is the name of the MySQL podLog in as root in order to create objects as needed:
mysql -u root -p$(cat $MYSQL_ROOT_PASSWORD_FILE)
Create all necessary databases, and a user for each:
CREATE DATABASE <DATABASE_NAME>;
CREATE USER '<USERNAME>'@'%' IDENTIFIED BY '<PASSWORD>';
GRANT ALL PRIVILEGES ON <DATABASE_NAME>.* TO '<USERNAME>'@'%';
FLUSH PRIVILEGES;
where:
DATABASE_NAME is the name of the databaseUSERNAME is the mysql usernamePASSWORD is the password for the userExample:
CREATE DATABASE service_instance_db;
CREATE USER 'c67a09469fd349b5ac600893dff4cee0'@'%' IDENTIFIED BY 'apv1wll5zzv470w1';
GRANT ALL PRIVILEGES ON service_instance_db.* to 'c67a09469fd349b5ac600893dff4cee0'@'%';
FLUSH PRIVILEGES;
For more information on creating a user for the associated database refer to Create a Database and Privileged MySQL User for the App.
Use a mysql 8.0 client and ensure the MySQL server can be accessed, and you can connect with the newly created user.
There are several methods to connect to the MySQL server in order to load the backup:
kubectl copy to copy the backup onto a pod that has the mysql 8 client. This method also requires kubectl exec permissions to get a shell for running a container on that pod.mysql client.Connect to the MySQL instance and load the backup file for each database, using the appropriate credentials:
mysql -h <HOSTNAME> -u <USERNAME> -P 3306 -p<PASSWORD> < <BACKUP_FILE>
where:
HOSTNAME is the address of the MySQL serviceUSERNAME is the mysql usernamePASSWORD is the password for the userBACKUP_FILE is the backup taken for the specific databaseExample:
mysql -h a4dc8de1biefe13112-17761231.us-west-2.elb.amazonaws.com -u 'c67a09469fd349b5ac600893dff4cee0' -P 3306 -papv1wll5zzv470w1 < dump.sql
When the restore completes, confirm that the schemas and data are loaded correctly, and remove external access to the MySQL instances.