Search code examples
h2keycloak

Invalid username/password when accessing Keycloak's H2 database


I am attempting to follow the guide here to view my H2 database directly.

When executing the command: java -cp $jar org.h2.tools.Console -url "$url" -user sa -password sa

I get the following exception Exception in thread "main" org.h2.jdbc.JdbcSQLException: Wrong user name or password [28000-193]

This seems relatively straightforward, but I cannot seem to figure out my credentials. I am running keycloak 7.0.0 locally through a docker image and I have not knowingly modified anything about the database. So far I have tried permutations of sa, empty, and my keycloak credentials with no success.

Is there any way to get/set/create a set of credentials for this database?


Solution

  • I think the default password for an off-the-shelf h2 database is "" (empty).

    Nevertheless you can also find or configure your datasource from the subsystem configuration files.

    You should find something like this.

      <subsystem xmlns="urn:jboss:domain:datasources:5.0">
         <datasources>
           ​<drivers>
             ​<driver name="h2" module="com.h2database.h2">
               ​<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
             ​</driver>
           ​</drivers>
           ...
           <datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true">
               <driver>h2</driver>
               <connection-url>jdbc:h2:${jboss.server.data.dir}/keycloak;AUTO_SERVER=TRUE</connection-url>
               <security>
                   <user-name>sa</user-name>
                   <password>?</password>
               </security>
           </datasource>
            ...
         </datasources>
    

    Keycloak rely on Widlfly, which documentation gives more info about database configuration.