You may have faced scenarios when you need to change the password of your Azure SQL database. In this article, we will explain various ways to change the administrator password of your SQL database.
- Reset admin password Azure SQL database from Azure portal
- Reset admin password Azure SQL database using powershell
- Change Azure SQL database admin password using Azure CLI
- Change password Azure database user
Reset password Azure SQL database from Azure portal
Using the Azure portal for managing Azure resources is very convenient. You can easily change the password of your Azure SQL database from the Azure portal by following the below steps:
- Open the Azure portal and sign in to your Azure account.
- Navigate to your database whose password you want to change.
- Click on Server Name. Because you have to change the password of your server on which the database is running. Look at the below image for reference:
- You will see the option Reset Password. Click on it to reset the password.
- Now you can specify a new admin password for your Azure SQL server.
- While entering the new password, you have to follow the password policy of Azure SQL. You have to follow all the rules, only then your password will be accepted. The rules are shown below in the image:
- Once your new password is accpeted, you have to re-enter the new password.
- After the password is matched, the Save button will be enabled. Click on Save button to change the password.
- Now you can login into your Azure SQL database using the new password.
In this way, you can change password of your Azure SQL database from the Azure portal.
Reset password Azure SQL database using Powershell
Microsoft Azure has created a module called Az module which you can use to manage the Azure resources from the PowerShell.
You can either use the Azure PowerShell from the portal where the necessary modules are already installed or you can use the Windows PowerShell. If you want to use Windows PowerShell, you have to install this Az module.
Once you have installed the Az module, you can follow the below steps to change the administrator password of your Azure SQL database:
- Run the Windows PowerShell as an administrator.
Note: Open the link shell.azure.com and switch the terminal to PowerShell to use the Azure PowerShell.
- Write the below command to connect your Windows PowerShell to your Azure account:
- You will see a sign in prompt for signing in to the Microsoft account. Sign in to your Microsoft account. Once you have signed in, you will see an output like in the image below:
- Now write the below script to change the Azure SQL database password:
$password = ConvertTo-SecureString -AsPlainText -Force '*********'
Set-AzSqlServer -ResourceGroupName GroupAzure -ServerName mysql1000 -SqlAdministratorPassword $password
- In the above script, the $password is a variable into which we are storing our new password in the form of a secure string.
- Set-AzSQLServer is a command line utility to set the Azure SQL server properties. We are using this utility to change the password.
- GroupAzure is the resource group name and mysql1000 is the server name on which the database is running.
- Once you execute the above query, your password will be changed and you will see an output like in the below image:
Thus, you might have learned how to change the Azure SQL database password from PowerShell.
Change Azure SQL database password using Azure CLI
In this section, we will discuss how to change the Azure SQL database password using Azure CLI. You can follow the below steps to change the Azure SQL database password:
- Open the link shell.azure.com in your browser and sign in to your Azure account.
- Make sure the terminal is in bash mode. Look at the below image for reference:
- Now execute the below command in the terminal to change the Azure SQL database administrator password:
az sql server update --resource-group GroupAzure --name mysql1000 --admin-password Kushal@123
- In the above command, we have used the az module that is used to manage the Azure resources from the command line. GroupAzure is the name of the resource group, mysql1000 is the name of the SQL server instance and Kushal@007 is the new admininsrator password for the database.
- You will see an output like in the below image after executing this command and your password will be changed.
Hence, in this way you can use the Azure CLI to reset the administrator password of your Aure SQL database.
Thus, you might have learned how you can change the administrator password of your Azure SQL database in multiple ways.
Change password Azure database user
In the above sections, we explained how you can change the administrator password of your Azure SQL database. Now we will explain how you can change the password of a user in the Azure SQL database.
For the demonstration purpose, we have created a user in our Azure SQL database. The username is TestUser and the password for this user is User@123.
CREATE USER [TestUser] WITH PASSWORD = 'User@123';
ALTER ROLE [db_datareader] ADD MEMBER [TestUser];
Now suppose you want to change your password. You can use the ALTER USER statement to alter the various information about the user like username, password, schema, etc.
If you are logged in as the user TestUser, you can change the password for the user TestUser, by executing the ALTER USER statement as:
ALTER USER [TestUser] WITH PASSWORD = 'Password@123' OLD_PASSWORD= 'User@123'
Now the new password will be Password@123.
You may like:
- How to rename a database in Azure SQL
- SQL Server stored procedure if exists update else insert
- SQL Server check user permissions on table
- How to execute stored procedure in SQL Server
- Azure sql password validation failed
- How to check if SQL Server is running
- Read only replica Azure SQL
Watch my YouTube video for a better understanding of the topic.
In this way, you can change password of an Azure SQL database user.
- Reset password Azure SQL database from Azure portal
- Reset password Azure SQL database using powershell
- Change Azure SQL database password using Azure CLI
- Change password Azure database user
I am Bijay having more than 15 years of experience in the Software Industry. During this time, I have worked on MariaDB and used it in a lot of projects. Most of our readers are from the United States, Canada, United Kingdom, Australia, New Zealand, etc.
Want to learn MariaDB? Check out all the articles and tutorials that I wrote on MariaDB. Also, I am a Microsoft MVP.