Forgot Your SonarQube Password? No Database, No Problem!
We've all been there. You're working on your local development environment, excited to start analyzing your code with SonarQube, and then...you realize you can't remember your password. What do you do when you're using SonarQube without a database and you're the only user?
This article will guide you through the process of resetting your SonarQube password, even when you're running it without a database.
Understanding the Problem:
SonarQube stores user credentials and other data in its internal database. When you don't have an external database, SonarQube uses an embedded H2 database. The lack of a separate database makes the password reset process a bit different.
The Solution: Manual Password Reset
Luckily, resetting your password in this scenario is a relatively simple process. Here's how to do it:
-
Stop SonarQube: Locate your SonarQube installation directory. For most installations, this will be
C:\SonarQube
. Inside the directory, find thebin
folder and then thewindows-x86-64
orwindows-x86-32
subfolder (depending on your operating system). Run theSonarQube.bat
file with thestop
parameter:C:\SonarQube\bin\windows-x86-64\SonarQube.bat stop
-
Navigate to the Data Directory: Within your SonarQube installation directory, find the
data
folder. This is where the embedded database files reside. -
Locate the
sonar.properties
file: Inside thedata
folder, you'll find a subfolder namedconfig
. Navigate to this folder and locate thesonar.properties
file. -
Modify the
sonar.properties
file: Open thesonar.properties
file using a text editor. Locate the following line:sonar.jdbc.password=
-
Set a new password: Replace the existing password with your desired new password. For example:
sonar.jdbc.password=yourNewPassword
Important: This is NOT your SonarQube login password. This is the password used to access the embedded database, which is also used for SonarQube authentication.
-
Restart SonarQube: Return to your SonarQube installation directory and start the server using the
SonarQube.bat
file:C:\SonarQube\bin\windows-x86-64\SonarQube.bat start
-
Login with your new password: Open your browser and go to
http://localhost:9000
. Log in using your new password.
Additional Notes:
- Security: This method directly modifies the embedded database and should only be used when you are the sole user and administrator. For production environments with multiple users, utilize SonarQube's built-in password recovery feature or use a dedicated database.
- Backups: Always create a backup of your
data
directory before making any modifications. This will help you restore your environment if something goes wrong.
Further Resources:
- SonarQube Documentation: https://docs.sonarsource.com/
Let me know if you have any other questions. Happy coding!