{"id":3278,"date":"2025-10-01T05:29:47","date_gmt":"2025-10-01T05:29:47","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=3278"},"modified":"2025-10-01T05:29:48","modified_gmt":"2025-10-01T05:29:48","slug":"how-to-set-up-a-database-for-keycloak-step-by-step","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/how-to-set-up-a-database-for-keycloak-step-by-step\/","title":{"rendered":"How to Set Up a Database for Keycloak (Step-by-Step)"},"content":{"rendered":"\n<p>Setting up a database for <strong>Keycloak<\/strong> may sound complex, but it\u2019s actually very simple once you know the right steps. In this blog, we\u2019ll walk through the process of configuring a database for Keycloak and running it for the first time. This guide is tailored for beginners who want to quickly get started with Keycloak using its built-in configuration files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Navigate to the Configuration File<\/h2>\n\n\n\n<p>When you download and extract Keycloak (for example, version <strong>26.3.4<\/strong>), you\u2019ll find a folder structure like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>keycloak-26.3.4\/\n   \u251c\u2500\u2500 bin\/\n   \u251c\u2500\u2500 conf\/\n   \u251c\u2500\u2500 lib\/\n   \u2514\u2500\u2500 ...\n<\/code><\/pre>\n\n\n\n<p>Inside the <strong>conf<\/strong> folder, you\u2019ll find a file named <strong><code>keycloak.conf<\/code><\/strong>.<\/p>\n\n\n\n<p>This file is where Keycloak reads its database configuration details.<\/p>\n\n\n\n<p>The path looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\\keycloak-26.3.4\\conf\\keycloak.conf\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Open and Edit <code>keycloak.conf<\/code><\/h2>\n\n\n\n<p>Open the <code>keycloak.conf<\/code> file in your preferred text editor (Notepad, VS Code, or any IDE).<\/p>\n\n\n\n<p>Here, you can specify database details if you\u2019re connecting to an external database (like PostgreSQL or MySQL). But if you\u2019re just starting out and want Keycloak to <strong>automatically create its database<\/strong>, you don\u2019t need to make changes. Keycloak will use the default configuration and set it up for you.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Run the Start Command<\/h2>\n\n\n\n<p>Now, it\u2019s time to launch Keycloak.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open <strong>Command Prompt (CMD)<\/strong>.<\/li>\n\n\n\n<li>Navigate to the <strong>bin<\/strong> folder inside your Keycloak directory:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>cd keycloak-26.3.4\\bin\n<\/code><\/pre>\n\n\n\n<p>Run the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/kc.sh start-dev\n<\/code><\/pre>\n\n\n\n<p>This tells Keycloak to start in <strong>development mode<\/strong>. In this mode, Keycloak automatically sets up the necessary database tables for you.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: Database Creation Happens Automatically<\/h2>\n\n\n\n<p>When you run the <code>.\/kc.sh start-dev<\/code> command:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keycloak connects to the default database (by default, it uses an embedded H2 database).<\/li>\n\n\n\n<li>It <strong>automatically creates all required tables<\/strong> needed for users, roles, clients, sessions, and tokens.<\/li>\n\n\n\n<li>You don\u2019t have to manually create the schema or run SQL scripts.<\/li>\n<\/ul>\n\n\n\n<p>This makes it perfect for testing, learning, or experimenting with Keycloak.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Verify Setup<\/h2>\n\n\n\n<p>Once Keycloak starts, you should see logs in the terminal indicating that the server is running on <strong><a href=\"http:\/\/localhost:8080\/\">http:\/\/localhost:8080\/<\/a><\/strong>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Open your browser and go to <code>http:\/\/localhost:8080<\/code>. <\/li>\n\n\n\n<li>You\u2019ll see the Keycloak welcome page.<\/li>\n\n\n\n<li>From here, you can log in, configure realms, and start managing authentication and authorization.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Setting up a database for Keycloak may sound complex, but it\u2019s actually very simple once you know the right steps. In this blog, we\u2019ll walk through the&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2833],"tags":[2836,2840,2834,2776,2842,2830,2820,2841,2837,2824,2816,2839,2818,2817,2821,2827,2835,2838,2815],"class_list":["post-3278","post","type-post","status-publish","format-standard","hentry","category-keycloak","tag-jdbc-connection","tag-jdbc-mariadb-keycloak","tag-kc-sh-start-dev","tag-keycloak","tag-keycloak-connection-error","tag-keycloak-database-configuration","tag-keycloak-database-setup","tag-keycloak-database-user","tag-keycloak-docker-setup","tag-keycloak-environment-variables","tag-keycloak-error-1049","tag-keycloak-installation","tag-keycloak-mariadb","tag-keycloak-mysql","tag-keycloak-quarkus","tag-keycloak-troubleshooting","tag-mariadb-jdbc-url","tag-sql-error-1049","tag-unknown-database-keycloak"],"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3278","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/comments?post=3278"}],"version-history":[{"count":1,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3278\/revisions"}],"predecessor-version":[{"id":3279,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3278\/revisions\/3279"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=3278"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=3278"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=3278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}