
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Update DEFINER clauses to INVOKER on the MySQL source instance.
/ 10
Create and save a Database Migration Service job without starting the job.
/ 20
Create users on the Cloud SQL destination instance.
/ 10
Start a previously created Database Migration Service job.
/ 10
Confirm the user metadata in Cloud SQL for MySQL
/ 10
Database Migration Service provides a high-fidelity way to migrate MySQL database objects (including schema, data, and metadata) from a source database instance to a destination database instance. When you run a Database Migration Service job, all tables from all databases and schemas are migrated, with the exception of the following system databases: sys, mysql, performance_schema, and information_schema.
MySQL system databases, which are not migrated during Database Migration Service jobs, contain information about users and privileges (additional details available in the Migration fidelity Guide). You can manage users and privileges in the destination Cloud SQL database instance after it is created.
Objects that contain metadata defined with the DEFINER clause can fail when invoked on the destination instance, if the user associated with the DEFINER clause does not already exist in the destination instance (additional details available in the Create and run a MySQL migration job containing metadata with a DEFINER clause Guide).
To prevent errors when these objects are invoked on the destination instance after migration, you can complete one of the following actions before running the migration job:
In this lab, you learn how to ensure that your Cloud SQL for MySQL instance contains the relevant user metadata that was available on the MySQL source instance by completing both of the identified actions before running the migration job. First, you identify the existing MySQL users on the source instance and update DEFINER clauses to INVOKER for database objects on the source instance. Next, you create and save a Database Migration Service job. Before running the migration job, you create the necessary users on the destination database instance. Finally, you start the saved migration job; after the job runs successfully, you check the user metadata in the Cloud SQL for MySQL instance.
In this lab, you learn how to migrate MySQL user data when running Database Migration Service jobs.
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details panel.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details panel.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
This page either shows the status information, or gives you the option to enable the API.
This page either shows the status information, or gives you the option to enable the API.
Similar to other Cloud resources, you can control Cloud SQL project access and permissions on the destination instance using Identity and Access Management (IAM) (details available in the IAM for Cloud SQL Guide).
In this task, you identify database users that are managed through database access control (read more in the About MySQL users Guide); for example, admins and superusers that can test the results of the migration job before others are provided access to the destination Cloud SQL instance via IAM.
In the Google Cloud Console, on the Navigation menu (), click Compute Engine > VM instances.
Locate the line with the instance called dms-mysql-training-vm.
For Connect, click on SSH to open a terminal window.
If prompted, click Authorize.
You can ignore any warnings about upgrades that appear in the SSH window.
Notice the system users named debian-sys-maint, mysql.session, and mysql.sys. These users do not need to be recreated, as they are created by MySQL as needed when the destination instance is created.
host | user |
---|---|
localhost | admin |
% | admin |
localhost | bsmith |
localhost | dwilliams |
localhost | mhill |
localhost | root |
% | root |
In a later task, you create the root user when you run the Database Migration Service job. You also create the other users, after the Cloud SQL destination instance has been created by the migration job.
In the previous task, you identified the existing MySQL users on the source instance. In this task, you identify and update database objects that have DEFINER entries for either root or the other users that do not yet exist in the destination instance.
If you have not or will not create a user in the destination instance, then all DEFINER entries associated with that user need to be updated to INVOKER. Any DEFINER entries for root need to be updated to INVOKER using another user such as admin.
These actions prevent failures when the objects are invoked on the destination instance after migration (review additional documentation in the Create and run a MySQL migration job containing metadata with a DEFINER clause Guide).
To obtain information about DEFINERs in a MySQL instance, you can query the INFORMATION_SCHEMA tables to identify DEFINER entries that require review before migration (for example, DEFINER entries that are not associated with system databases such as mysql and thus will be migrated to the destination instance).
The results indicate that you need to check events, routines, triggers, and views for DEFINER entries.
Note that some of these DEFINER entries may be associated with system users, which do not require additional action. These system users are excluded in the queries to identify DEFINER entries for the various database objects.
There are no instances of DEFINER in events associated with non-system users.
There are no instances of DEFINER in routines associated with non-system users.
There are no instances of DEFINER in triggers associated with non-system users.
definer | security_type | table_schema | table_name |
---|---|---|---|
admin@localhost | DEFINER | customers_data | customers_single |
admin@localhost | DEFINER | sales_data | invoices_storenum_5173 |
bsmith@localhost | DEFINER | customers_data | customers_married |
bsmith@localhost | DEFINER | sales_data | invoices_storenum_3980 |
mhill@localhost | DEFINER | sales_data | invoices_storenum_3656 |
In the next section, you update DEFINER to INVOKER for this view.
Notice that one of the previously identified users (dwilliams) is not associated with any DEFINER entries in views. Additionally, notice that there are no instances of DEFINER for the root user. No action is needed for either dwilliams or root.
In this subtask, you update the DEFINER entries associated with mhill to INVOKER.
Notice that the DEFINER entry associated with mhill has been updated to INVOKER, while the DEFINER entries associated with admin and bsmith remain.
Click Check my progress to verify the objective.
In this task, you create and save a migration job without starting the job. Specifically, you create a one-time migration job using VPC peering as the connectivity option; however, you can create and save any migration job to run at a later time.
This allows you to create the destination Cloud SQL instance without migrating data until you have completed necessary tasks such as creating new users on the destination instance.
In the Google Cloud Console, on the Navigation menu (), click Compute Engine > VM instances.
Locate the line with the instance called dms-mysql-training-vm.
Copy the value for Internal IP (e.g. 10.128.0.2).
In the Google Cloud Console, on the Navigation menu (), click Database Migration > Connection profiles.
Click Create Profile.
For Database engine, select MySQL.
Enter the required information for a connection profile:
Property | Value |
---|---|
Connection profile name | mysql-vm |
Connection profile ID | keep the auto-generated value |
Hostname or IP address | enter the internal IP for the MySQL source instance that you copied in the previous task (e.g. 10.128.0.2) |
Port | 3306 |
Username | admin |
Password | changeme! |
Region |
For the Encryption Type, select None.
Click Create.
A new connection profile named mysql-vm appears in the Connections profile list.
In the Google Cloud Console, on the Navigation menu (), click Database Migration > Migration jobs.
Click Create Migration Job.
For Create a migration job, on the Get Started tab, use the following values:
Property | Value |
---|---|
Migration job name | vm-to-cloudsql |
Migration job ID | keep the auto-generated value |
Source database engine | MySQL |
Destination region | |
Migration job type | One-time |
Leave all other settings as default.
For source connection profile, select mysql-vm.
Leave the defaults for the other settings.
Click Save & Continue.
Property | Value |
---|---|
Destination Instance ID | mysql-cloudsql |
Root password | supersecret! |
Choose a Cloud SQL edition | Enterprise |
Database version | Cloud SQL for MySQL 5.7 |
Zonal availability | Multiple zones (Highly available) |
For Instance connectivity, select Private IP and Public IP.
Select Use an automatically allocated IP range.
Click Allocate & Connect.
Note: This step may take a few minutes. If asked to retry the request, click the Retry button to refresh the Service Networking API.
When this step is complete, an updated message notifies you that the instance will use the existing managed service connection.Property | Value |
---|---|
Machine shapes | 2 vCPU, 8 GB |
Storage type | SSD |
Storage capacity | 10 |
If prompted to confirm, click Create Destination & Continue.
A message states that your destination database instance is being created. Continue to step 1 while you wait.
For Connectivity method, select VPC peering.
For VPC, select default.
VPC peering is configured by Database Migration Service using the information provided for the VPC network (the default network in this example).
When you see an updated message that the destination instance was created, proceed to the next step.
Review the details of the migration job.
Click Create Job.
You do not need to test the migration job. Recall that testing the job now will result in an error message because there are DEFINER entries associated with users that have not yet been created in the destination instance. You create these users in the next task.
The migration job has been created but has not been started. You start the job in a later task, after you create the new users in the Cloud SQL destination instance.
Click Check my progress to verify the objective.
In Cloud SQL, you can create MySQL users, such as admins and superusers, who can test the results of the migration job before others are provided access via IAM. In addition, you want to create users that have DEFINER clauses associated with them, before you run a migration job.
In this task, you create the users named admin, bsmith, and mhill.
In the Google Cloud Console, on the Navigation menu (), click SQL.
Expand the mysql-cloudsql-master instance and click on the instance ID called mysql-cloudsql.
In the Replica Instance menu, click Users.
Click Add User Account.
For User name, enter: admin
For Password, enter: changeme!
For Host name, select Restrict host by IP address or address range.
For Host, enter: localhost
Click Add.
Repeat steps 4-9 to create two more users with localhost access:
User | Password |
---|---|
bsmith | mustchangeasap! |
mhill | update! |
Click Check my progress to verify the objective.
In the Google Cloud Console, on the Navigation menu (), click Database Migration > Migration jobs.
Click the migration job vm-to-cloudsql to see the details page.
Click the Start button to run the migration job.
If prompted to confirm, click Start.
Click Check my progress to verify the objective.
In the Google Cloud Console, on the Navigation menu (), click SQL.
Click on the instance ID called mysql-cloudsql.
In the Primary Instance menu, click Overview.
In Connect to this instance panel, click Open Cloud Shell.
The command to connect to MySQL will pre-populate in Cloud Shell:
If prompted, click Authorize for the API.
You have now activated the MySQL interactive console.
Notice the users that you created in the previous task.
definer | security_type | table_schema | table_name |
---|---|---|---|
admin@localhost | DEFINER | customers_data | customers_single |
admin@localhost | DEFINER | sales_data | invoices_storenum_5173 |
bsmith@localhost | DEFINER | customers_data | customers_married |
bsmith@localhost | DEFINER | sales_data | invoices_storenum_3980 |
mhill@localhost | INVOKER | sales_data | invoices_storenum_3656 |
Click Check my progress to verify the objective.
You learned how to migrate MySQL user data when running Database Migration Service jobs.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated October 17, 2023
Lab Last Tested October 17, 2023
Copyright 2024 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one