how to change the keycloak database to MySQL from h24 min read
In this document, we will check how to change the keycloak database to MySQL from h2.
Keycloak comes with its own embedded Java-based relational database called H2. This is the default database that Keycloak will use to persist data and really only exists so that you can run the authentication server out of the box. It’s fine for development purposes, but for the production, it is recommended to replace it with a more production-ready external database.
* Keycloak server, if not check this link
* Running MySQL server, if you don’t have please check this link.
Step 1: Create a database for keycloak
Step 2: Login to keycloak server and download the MySQL connector.
Step 3: Now configure the Mysql Connector module in Keycloak server.
Step 4: Now add the module configuration to module.xml file.
Step 5: Now add the Mysql driver. Edit the file /opt/keycloak/standalone/configuration/standalone.xml, Add the below section in drivers section.
Step 6: Now add the data source configuration to change from h2 database to MySQL.
comment the h2 datasource configuration with <!– –>
My Sample configuration looks like this.
NOTE: make sure that you changed the database server IP, Username and Password for the database server as per your configurations.
Step 7: Now restart the keycloak application