{"id":17876,"date":"2024-11-28T11:56:56","date_gmt":"2024-11-28T11:56:56","guid":{"rendered":"https:\/\/truehost.com\/support\/?post_type=docs&#038;p=17876"},"modified":"2024-11-28T11:57:59","modified_gmt":"2024-11-28T11:57:59","password":"","slug":"how-to-fix-access-denied-for-user-rootlocalhost-error","status":"publish","type":"docs","link":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-fix-access-denied-for-user-rootlocalhost-error\/","title":{"rendered":"How to fix Access denied for user &#8216;root&#8217;@&#8217;localhost&#8217; error"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>At times you try to access the database via the terminal and you run into the error<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)<br><br>Even using a password for the root user still returns the same error.<br><br>This guide will take you through how to address the issue for a <strong>mariadb database server<\/strong><br><\/pre>\n\n\n\n<p>Login to the server as root user.<\/p>\n\n\n\n<p>Shutdown or stop the mariadb database server.<\/p>\n\n\n\n<p><code><strong>systemctl stop mariadb.service<\/strong><\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"229\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-690-1024x229.png\" alt=\"\" class=\"wp-image-17877\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-690-1024x229.png 1024w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-690-300x67.png 300w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-690-768x172.png 768w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-690.png 1089w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Confirm the status that the db is offline.<\/p>\n\n\n\n<p><strong><code>systemctl status mariadb.service<\/code><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"243\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-691-1024x243.png\" alt=\"\" class=\"wp-image-17878\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-691-1024x243.png 1024w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-691-300x71.png 300w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-691-768x182.png 768w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-691.png 1352w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Restart the database in safe mode by typing the command below.<\/p>\n\n\n\n<p><strong><code>sudo mysqld_safe --skip-grant-tables --skip-networking &amp;<\/code><\/strong><\/p>\n\n\n\n<p>You will see an output as shown below<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"182\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-692-1024x182.png\" alt=\"\" class=\"wp-image-17879\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-692-1024x182.png 1024w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-692-300x53.png 300w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-692-768x136.png 768w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-692.png 1358w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Access the database using the command below.<\/p>\n\n\n\n<p><code><strong>mysql -u root<\/strong><\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"288\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-693-1024x288.png\" alt=\"\" class=\"wp-image-17880\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-693-1024x288.png 1024w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-693-300x84.png 300w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-693-768x216.png 768w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-693.png 1262w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Use the mysql database<\/p>\n\n\n\n<p><code><strong>use mysql <\/strong><\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"188\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-694-1024x188.png\" alt=\"\" class=\"wp-image-17881\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-694-1024x188.png 1024w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-694-300x55.png 300w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-694-768x141.png 768w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-694.png 1290w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Update root password.<\/p>\n\n\n\n<p><code><strong>UPDATE user SET password=PASSWORD('new-password-here') WHERE user='root';<\/strong><\/code><\/p>\n\n\n\n<p>or <\/p>\n\n\n\n<p><code><strong>ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password-here';<\/strong><\/code><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Stop MariaDB Safe Mode<\/p>\n\n\n\n<p><strong><code>pkill -f mysqld_safe<br>pkill -f mysqld<\/code><\/strong><\/p>\n\n\n\n<p>Restart the database in normal mode.<\/p>\n\n\n\n<p><strong><code>sudo systemctl start mariadb<\/code><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"932\" height=\"124\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-695.png\" alt=\"\" class=\"wp-image-17882\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-695.png 932w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-695-300x40.png 300w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-695-768x102.png 768w\" sizes=\"auto, (max-width: 932px) 100vw, 932px\" \/><\/figure>\n\n\n\n<p>Done.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>At times you try to access the database via the terminal and you run into the error ERROR 1045 (28000): Access denied for user &#8216;root&#8217;@&#8217;localhost&#8217; (using password: YES)Even using a password for the root user still returns the same error.This guide will take you through how to address the issue for a mariadb database server [&hellip;]<\/p>\n","protected":false},"author":24,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"_eb_attr":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"doc_category":[1833,1879],"doc_tag":[],"class_list":["post-17876","docs","type-docs","status-publish","hentry","doc_category-mysql","doc_category-servers"],"year_month":"2026-06","word_count":168,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"Kibera","author_nicename":"dan-k","author_url":"https:\/\/truehost.com\/support\/author\/dan-k\/"},"doc_category_info":[{"term_name":"MySQL","term_url":"https:\/\/truehost.com\/support\/docs-category\/mysql\/"},{"term_name":"Servers","term_url":"https:\/\/truehost.com\/support\/docs-category\/servers\/"}],"doc_tag_info":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to fix Access denied for user &#039;root&#039;@&#039;localhost&#039; error -<\/title>\n<meta name=\"description\" content=\"This guide will take you through how to reset the root password for a mariadb database server in safe mode.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-fix-access-denied-for-user-rootlocalhost-error\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to fix Access denied for user &#039;root&#039;@&#039;localhost&#039; error -\" \/>\n<meta property=\"og:description\" content=\"This guide will take you through how to reset the root password for a mariadb database server in safe mode.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-fix-access-denied-for-user-rootlocalhost-error\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-28T11:57:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-690-1024x229.png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-fix-access-denied-for-user-rootlocalhost-error\\\/\",\"url\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-fix-access-denied-for-user-rootlocalhost-error\\\/\",\"name\":\"How to fix Access denied for user 'root'@'localhost' error -\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-fix-access-denied-for-user-rootlocalhost-error\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-fix-access-denied-for-user-rootlocalhost-error\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/image-690-1024x229.png\",\"datePublished\":\"2024-11-28T11:56:56+00:00\",\"dateModified\":\"2024-11-28T11:57:59+00:00\",\"description\":\"This guide will take you through how to reset the root password for a mariadb database server in safe mode.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-fix-access-denied-for-user-rootlocalhost-error\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-fix-access-denied-for-user-rootlocalhost-error\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-fix-access-denied-for-user-rootlocalhost-error\\\/#primaryimage\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/image-690-1024x229.png\",\"contentUrl\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/image-690-1024x229.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.truehost.com\\\/support\\\/knowledge-base\\\/how-to-fix-access-denied-for-user-rootlocalhost-error\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/truehost.com\\\/support\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to fix Access denied for user &#8216;root&#8217;@&#8217;localhost&#8217; error\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/#website\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/\",\"name\":\"\",\"description\":\"Help In a Click\",\"publisher\":{\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/truehost.com\\\/support\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/#organization\",\"name\":\"Truehost Kenya\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/cropped-image_2026-04-16_174808866.png\",\"contentUrl\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/cropped-image_2026-04-16_174808866.png\",\"width\":240,\"height\":48,\"caption\":\"Truehost Kenya\"},\"image\":{\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/#\\\/schema\\\/logo\\\/image\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to fix Access denied for user 'root'@'localhost' error -","description":"This guide will take you through how to reset the root password for a mariadb database server in safe mode.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-fix-access-denied-for-user-rootlocalhost-error\/","og_locale":"en_US","og_type":"article","og_title":"How to fix Access denied for user 'root'@'localhost' error -","og_description":"This guide will take you through how to reset the root password for a mariadb database server in safe mode.","og_url":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-fix-access-denied-for-user-rootlocalhost-error\/","article_modified_time":"2024-11-28T11:57:59+00:00","og_image":[{"url":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-690-1024x229.png","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-fix-access-denied-for-user-rootlocalhost-error\/","url":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-fix-access-denied-for-user-rootlocalhost-error\/","name":"How to fix Access denied for user 'root'@'localhost' error -","isPartOf":{"@id":"https:\/\/truehost.com\/support\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-fix-access-denied-for-user-rootlocalhost-error\/#primaryimage"},"image":{"@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-fix-access-denied-for-user-rootlocalhost-error\/#primaryimage"},"thumbnailUrl":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-690-1024x229.png","datePublished":"2024-11-28T11:56:56+00:00","dateModified":"2024-11-28T11:57:59+00:00","description":"This guide will take you through how to reset the root password for a mariadb database server in safe mode.","breadcrumb":{"@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-fix-access-denied-for-user-rootlocalhost-error\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-fix-access-denied-for-user-rootlocalhost-error\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-fix-access-denied-for-user-rootlocalhost-error\/#primaryimage","url":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-690-1024x229.png","contentUrl":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/11\/image-690-1024x229.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.truehost.com\/support\/knowledge-base\/how-to-fix-access-denied-for-user-rootlocalhost-error\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/truehost.com\/support\/"},{"@type":"ListItem","position":2,"name":"How to fix Access denied for user &#8216;root&#8217;@&#8217;localhost&#8217; error"}]},{"@type":"WebSite","@id":"https:\/\/truehost.com\/support\/#website","url":"https:\/\/truehost.com\/support\/","name":"","description":"Help In a Click","publisher":{"@id":"https:\/\/truehost.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/truehost.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/truehost.com\/support\/#organization","name":"Truehost Kenya","url":"https:\/\/truehost.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/truehost.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2026\/04\/cropped-image_2026-04-16_174808866.png","contentUrl":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2026\/04\/cropped-image_2026-04-16_174808866.png","width":240,"height":48,"caption":"Truehost Kenya"},"image":{"@id":"https:\/\/truehost.com\/support\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs\/17876","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/users\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/comments?post=17876"}],"version-history":[{"count":1,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs\/17876\/revisions"}],"predecessor-version":[{"id":17883,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs\/17876\/revisions\/17883"}],"wp:attachment":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/media?parent=17876"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/doc_category?post=17876"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/doc_tag?post=17876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}