Skip to content

Commit 8e52fec

Browse files
Revise MySQL discovery tutorial and add user creation script
Updated the tutorial to clarify the process of discovering MySQL database instances, including a new script for creating a least-privilege user.
1 parent 5b428e6 commit 8e52fec

1 file changed

Lines changed: 51 additions & 2 deletions

File tree

articles/migrate/tutorial-discover-mysql-database-instances.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ monikerRange:
1111
# Customer intent: As a database administrator, I want to discover MySQL database instances in my datacenter using an agentless solution, so that I can assess and manage my databases efficiently before migrating to the cloud.
1212
---
1313

14-
# Tutorial: Discover MySQL database instances running in your datacenter (preview)
14+
# Discover MySQL database instances running in your datacenter (preview)
1515

1616

1717
This article describes how to discover MySQL database instances running on servers in your datacenter, using **Azure Migrate appliance**. The discovery process is agentless; no agents are installed on the target servers.
@@ -53,7 +53,7 @@ The following table lists the regions that support MySQL Discovery and Assessmen
5353

5454
1. Open the appliance configuration manager, complete the prerequisite checks and registration of the appliance.
5555
2. Navigate to the Manage credentials and discovery sources panel.
56-
1. In Step 3: Select **MySQL authentication** credential type, provide a friendly name, input the MySQL username, and password and select **Save**.
56+
3. In Step 3: Select **MySQL authentication** credential type, provide a friendly name, input the MySQL username, and password and select **Save**.
5757

5858
> [!NOTE]
5959
> - Ensure that the user corresponding to the added MySQL credentials have the following privileges:
@@ -69,6 +69,55 @@ The following table lists the regions that support MySQL Discovery and Assessmen
6969
> GRANT SELECT ON information_schema.* TO 'username'@'ip';
7070
> GRANT SELECT ON performance_schema.* TO 'username'@'ip';
7171
72+
To create a custom MySQL user account with the minimum permissions required for Discovery and Assessment in Azure Migrate with access from the appliance machine you can use the following script. The account running the script needs following privileges. This script has to be executed on the servers with MySQL instances.
73+
- CREATE USER privilege → to create the new user.
74+
- GRANT OPTION privilege → to grant privileges to the new user.
75+
- SELECT on mysql.user → required for the existence check.
76+
- PROCESS privilege → if you want to verify process-related grants after creation.
77+
78+
```
79+
80+
-- MySQL Script to Create a Least-Privilege User for Azure Migrate
81+
-- Replace @username, @password, and @ip with actual values before execution.
82+
83+
SET @username = 'your_username';
84+
SET @password = 'your_password';
85+
SET @ip = 'your_appliance_ip';
86+
87+
-- Check if the user already exists
88+
SELECT CASE
89+
WHEN EXISTS (SELECT 1 FROM mysql.user WHERE user = @username AND host = @ip)
90+
THEN CONCAT('User ', @username, '@', @ip, ' already exists, skipping creation')
91+
ELSE
92+
CONCAT('User ', @username, '@', @ip, ' does not exist, proceeding with creation')
93+
END AS user_check;
94+
95+
-- Create the user if not exists
96+
CREATE USER IF NOT EXISTS @username@'@ip' IDENTIFIED BY @password;
97+
98+
-- Grant minimal required privileges
99+
GRANT USAGE ON *.* TO @username@'@ip';
100+
GRANT PROCESS ON *.* TO @username@'@ip';
101+
102+
-- Grant SELECT on specific columns in mysql.user
103+
GRANT SELECT (User, Host, Super_priv, File_priv, Create_tablespace_priv, Shutdown_priv)
104+
ON mysql.user TO @username@'@ip';
105+
106+
-- Grant SELECT on information_schema and performance_schema
107+
GRANT SELECT ON information_schema.* TO @username@'@ip';
108+
GRANT SELECT ON performance_schema.* TO @username@'@ip';
109+
110+
-- Apply changes
111+
FLUSH PRIVILEGES;
112+
113+
-- Log success
114+
SELECT CONCAT('Azure Migrate user ', @username, '@', @ip, ' created successfully with least privileges.') AS result;
115+
```
116+
Execute the script using the following command through your MySQL client.
117+
```
118+
mysql -u root -p -e "SET @username='myuser'; SET @password='mypassword'; SET @ip='appliance_ip'; SOURCE CreateUser.sql;"
119+
```
120+
72121
You can review the discovered MySQL databases after around 24 hours of discovery initiation, through the **Discovered servers** view. To expedite the discovery of your MySQL instances follow the steps:
73122
74123
- After adding the MySQL credentials on the appliance configuration manager restart the discovery services on appliance.

0 commit comments

Comments
 (0)