Antony
Antony

Reputation: 4344

MySQL Azure database with username/password

We are wanting to use the Azure REST API to create Mysql database server instances as listed here: https://learn.microsoft.com/en-us/rest/api/mysql/?view=rest-mysql-singleserver-2017-12-01#flexible-server-rest-operations and here https://learn.microsoft.com/en-us/rest/api/mysql/flexibleserver/databases/create-or-update?view=rest-mysql-flexibleserver-2023-06-30&tabs=HTTP.

The question is, how do you create users and passwords for the database server you've just created?? According to https://learn.microsoft.com/en-us/azure/mysql/how-to-create-users "You provided a server admin username and password when creating your Azure Database for MySQL server" [aka in the panel] but we need to automate the process so we can setup database instances with corresponding connection details. Unless I am missing the obvious, a REST API without this wouldn't be much help!?

Upvotes: 0

Views: 815

Answers (1)

Bhavani
Bhavani

Reputation: 5297

According to this MS document, there is no REST API operation for creating a user in a MySQL Azure database. Instead, you can use the Azure CLI to create a user for the database. Follow the procedure below to create a user for the database with a password:

First, connect to the database with the admin user in Azure CLI using the command below:

mysql -h <serverName>.mysql.database.azure.com -u <adminuser> -p

Next, create a user with the following command:

CREATE USER '<userName>'@'<Host>/<IP>' IDENTIFIED BY 'password';

Then, grant privileges to the database using this command:

GRANT ALL PRIVILEGES ON db.* TO '<userName>'@'<Host>/<IP>' IDENTIFIED BY '<password>';

enter image description here

Now, you will be able to connect to the database with the above user and password, as shown below:

enter image description here

You can use these database instances and corresponding connection details to automate the process. For more information you can refer this.

Upvotes: 0

Related Questions