Which SQL client should I use to Reset admin password

I lost my admin password for my SonarQube server.
To reset it I would like to execute the recommended command:
update users set crypted_password = ‘$2a$12$uCkkXmhW5ThVK8mpBvnXOOJRLd64LJeHTeCkSuB3lfaR2N0AYBaSi’, salt=null, hash_method=‘BCRYPT’ where login = ‘admin’;

But I don’t have a SQL client to do this yet.
Which SQL client should I choose and how are the steps to execute the command?

(I already tried psql but this is also asking for a password when trying to connect.)

Hey there.

You will need to have access to the database to run the command (hence why psql is asking for a password). There’s nothing specific to SonarQube going on here.

Who set up the database connected to your SonarQube server (a DBA, yourself)?

I’m not using a separate database. I assume SonarQube is coming with its own database because this command (update users set …) looks for me like an SQL command.
I just wanted to know how I can execute that command.

Hey there.

Against the internal database, where you get this big warning at the bottom in the footer of your instance when you use it? :smiley:

As noted in the Install the Server documentation, several external database engines are supported.

You may be able to find a client that can interact with the embedded H2 database (H2 will be your keyword there), but we’ve never tried it. You need to move to an external database (PostgreSQL, Oracle, or Microsoft SQL Server) for any usage of SonarQube beyond evaluation.

This way I was able to solve the problem:

Here is how to reset password to “admin” for connection to server. (JDK 11 & Sonar 8.7)

  • go in C:\sonarqube\lib\jdbc\h2

  • open cmd console from there

  • enter java -cp h2-1.4.199.jar org.h2.tools.Shell

  • You will be prompted to fill the following:
    URL jdbc:h2:tcp://localhost:9092/sonar
    Driver org.h2.Driver
    User (live it empty)
    Password (live it empty)

  • then a “sql>” is prompt, entre the following query:
    update users set crypted_password = ‘$2a$12$uCkkXmhW5ThVK8mpBvnXOOJRLd64LJeHTeCkSuB3lfaR2N0AYBaSi’, salt=null, hash_method=‘BCRYPT’ where login = ‘admin’;

then password is reseted to “admin”.