{"id":10381,"date":"2026-06-19T19:59:43","date_gmt":"2026-06-19T14:29:43","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=10381"},"modified":"2026-06-19T20:00:48","modified_gmt":"2026-06-19T14:30:48","slug":"how-to-add-a-database-to-metabase-via-cli-using-the-rest-api","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/how-to-add-a-database-to-metabase-via-cli-using-the-rest-api\/","title":{"rendered":"How to Add a Database to Metabase via CLI Using the REST API"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Metabase is a popular open-source business intelligence platform that allows users to connect various databases and create dashboards and reports. While databases are typically added through the Metabase web interface, administrators can automate the process using the Metabase REST API and command-line tools such as <code>curl<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This article explains how to add a database to Metabase from the command line.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before proceeding, ensure the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Metabase is installed and running.<\/li>\n\n\n\n<li>Administrator access to Metabase.<\/li>\n\n\n\n<li>API key or username and password for authentication.<\/li>\n\n\n\n<li>Database connection details (host, port, database name, username, and password).<\/li>\n\n\n\n<li><code>curl<\/code> installed on the server.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Implementation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 1: Generate an API Key<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Navigate to:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Admin Settings \u2192 Authentication \u2192 API Keys<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Generate an API key and note it for use in API requests.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 2: Create the Database Connection<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Execute the following command to add a MySQL database:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -X POST http:\/\/metabase.example.com\/api\/database \\\n-H \"Content-Type: application\/json\" \\\n-H \"x-api-key: YOUR_API_KEY\" \\\n-d '{\n  \"engine\": \"mysql\",\n  \"name\": \"Production MySQL\",\n  \"details\": {\n    \"host\": \"IP ADDRESS\",\n    \"port\": 3306,\n    \"dbname\": \"employees\",\n    \"user\": \"dbuser\",\n    \"password\": \"dbpassword\"\n  }\n}'\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 3: Verify the Database<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Retrieve the list of databases configured in Metabase:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -X GET http:\/\/metabase.example.com\/api\/database \\\n-H \"x-api-key: YOUR_API_KEY\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The output will display all configured databases.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 4: Update an Existing Database<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To modify an existing database configuration:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -X PUT http:\/\/metabase.example.com\/api\/database\/2 \\\n-H \"Content-Type: application\/json\" \\\n-H \"x-api-key: YOUR_API_KEY\" \\\n-d '{\n  \"name\": \"Updated MySQL Database\"\n}'\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <code>2<\/code> with the database ID.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Although Metabase does not provide a dedicated CLI command for adding databases, administrators can automate the process using the REST API and command-line tools such as <code>curl<\/code>. This approach is particularly useful for scripting, infrastructure automation, and managing multiple Metabase instances.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Metabase is a popular open-source business intelligence platform that allows users to connect various databases and create dashboards and [&hellip;]<\/p>\n","protected":false},"author":496,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[],"class_list":["post-10381","post","type-post","status-publish","format-standard","hentry","category-web-architecture","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-2Hr","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/10381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/496"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=10381"}],"version-history":[{"count":3,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/10381\/revisions"}],"predecessor-version":[{"id":10389,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/10381\/revisions\/10389"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=10381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=10381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=10381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}