{"id":13812,"date":"2024-08-28T05:59:21","date_gmt":"2024-08-28T05:59:21","guid":{"rendered":"https:\/\/truehost.com\/support\/?post_type=docs&#038;p=13812"},"modified":"2024-08-28T05:59:41","modified_gmt":"2024-08-28T05:59:41","password":"","slug":"how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2","status":"publish","type":"docs","link":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\/","title":{"rendered":"How to resolve &#8211; Can&#8217;t connect to local server through socket &#8216;\/run\/mysqld\/mysqld.sock&#8217; (2)"},"content":{"rendered":"\n<p>For some reason you try to access your database and get the error <strong>Can&#8217;t connect to local server through socket &#8216;\/run\/mysqld\/mysqld.sock&#8217; (2)<\/strong><\/p>\n\n\n\n<p><code>mysql <\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"769\" height=\"298\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-13.png\" alt=\"\" class=\"wp-image-13814\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-13.png 769w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-13-300x116.png 300w\" sizes=\"auto, (max-width: 769px) 100vw, 769px\" \/><\/figure>\n\n\n\n<ol class=\"wp-block-list\">\n<li>In my case, the issue seems to be related to service unit file. So we reload this configuration.<\/li>\n<\/ol>\n\n\n\n<p><code>systemctl daemon-reload<\/code><\/p>\n\n\n\n<p>2. Then enable the service <\/p>\n\n\n\n<p><code>systemctl enable mariadb.service <\/code><\/p>\n\n\n\n<p>However I got the error below.<\/p>\n\n\n\n<p>Failed to enable unit: Unit file \/etc\/systemd\/system\/mariadb.service is masked.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"769\" height=\"105\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-14.png\" alt=\"\" class=\"wp-image-13815\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-14.png 769w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-14-300x41.png 300w\" sizes=\"auto, (max-width: 769px) 100vw, 769px\" \/><\/figure>\n\n\n\n<p>3. Run the command below to address the issue and enable the service.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><code>systemctl unmask mariadb.service<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"769\" height=\"101\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-15.png\" alt=\"\" class=\"wp-image-13816\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-15.png 769w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-15-300x39.png 300w\" sizes=\"auto, (max-width: 769px) 100vw, 769px\" \/><\/figure>\n\n\n\n<p>4. Then we try to restart the service, which also fails due to an error below.<\/p>\n\n\n\n<p><code>systemctl restart mariadb<\/code><\/p>\n\n\n\n<p><code>systemctl status mariadb<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"242\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-16-1024x242.png\" alt=\"\" class=\"wp-image-13817\" style=\"width:779px;height:auto\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-16-1024x242.png 1024w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-16-300x71.png 300w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-16-768x182.png 768w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-16.png 1108w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>5. From the error it seems there are some packages missing needed to start the service, so we install the packages.<\/p>\n\n\n\n<p>Confirm you have the database is installed. <\/p>\n\n\n\n<p><code>mariadb --version or mysql --version <\/code><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Then, <\/p>\n\n\n\n<p><code>sudo apt -y update<\/code><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Then, <\/p>\n\n\n\n<p><code>sudo apt install mariadb-client mariadb-server<\/code><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Start the database server and confirm the status. All should be good.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"746\" height=\"328\" src=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-17.png\" alt=\"\" class=\"wp-image-13818\" srcset=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-17.png 746w, https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-17-300x132.png 300w\" sizes=\"auto, (max-width: 746px) 100vw, 746px\" \/><\/figure>\n\n\n\n<p>Done. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>For some reason you try to access your database and get the error Can&#8217;t connect to local server through socket &#8216;\/run\/mysqld\/mysqld.sock&#8217; (2) mysql systemctl daemon-reload 2. Then enable the service systemctl enable mariadb.service However I got the error below. Failed to enable unit: Unit file \/etc\/systemd\/system\/mariadb.service is masked. 3. Run the command below to address [&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":[1879],"doc_tag":[],"class_list":["post-13812","docs","type-docs","status-publish","hentry","doc_category-servers"],"year_month":"2026-06","word_count":166,"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":"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.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to resolve - Can&#039;t connect to local server through socket &#039;\/run\/mysqld\/mysqld.sock&#039; (2) -<\/title>\n<meta name=\"description\" content=\"For some reason you try to access your database and get the error Can&#039;t connect to local server through socket &#039;\/run\/mysqld\/mysqld.sock&#039; (2).\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/truehost.com\/support\/knowledge-base\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to resolve - Can&#039;t connect to local server through socket &#039;\/run\/mysqld\/mysqld.sock&#039; (2) -\" \/>\n<meta property=\"og:description\" content=\"For some reason you try to access your database and get the error Can&#039;t connect to local server through socket &#039;\/run\/mysqld\/mysqld.sock&#039; (2).\" \/>\n<meta property=\"og:url\" content=\"https:\/\/truehost.com\/support\/knowledge-base\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-28T05:59:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-13.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:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\\\/\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\\\/\",\"name\":\"How to resolve - Can't connect to local server through socket '\\\/run\\\/mysqld\\\/mysqld.sock' (2) -\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/image-13.png\",\"datePublished\":\"2024-08-28T05:59:21+00:00\",\"dateModified\":\"2024-08-28T05:59:41+00:00\",\"description\":\"For some reason you try to access your database and get the error Can't connect to local server through socket '\\\/run\\\/mysqld\\\/mysqld.sock' (2).\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\\\/#primaryimage\",\"url\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/image-13.png\",\"contentUrl\":\"https:\\\/\\\/truehost.com\\\/support\\\/wp-content\\\/uploads\\\/2024\\\/08\\\/image-13.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/truehost.com\\\/support\\\/knowledge-base\\\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/truehost.com\\\/support\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to resolve &#8211; Can&#8217;t connect to local server through socket &#8216;\\\/run\\\/mysqld\\\/mysqld.sock&#8217; (2)\"}]},{\"@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 resolve - Can't connect to local server through socket '\/run\/mysqld\/mysqld.sock' (2) -","description":"For some reason you try to access your database and get the error Can't connect to local server through socket '\/run\/mysqld\/mysqld.sock' (2).","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:\/\/truehost.com\/support\/knowledge-base\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\/","og_locale":"en_US","og_type":"article","og_title":"How to resolve - Can't connect to local server through socket '\/run\/mysqld\/mysqld.sock' (2) -","og_description":"For some reason you try to access your database and get the error Can't connect to local server through socket '\/run\/mysqld\/mysqld.sock' (2).","og_url":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\/","article_modified_time":"2024-08-28T05:59:41+00:00","og_image":[{"url":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-13.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:\/\/truehost.com\/support\/knowledge-base\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\/","url":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\/","name":"How to resolve - Can't connect to local server through socket '\/run\/mysqld\/mysqld.sock' (2) -","isPartOf":{"@id":"https:\/\/truehost.com\/support\/#website"},"primaryImageOfPage":{"@id":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\/#primaryimage"},"image":{"@id":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\/#primaryimage"},"thumbnailUrl":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-13.png","datePublished":"2024-08-28T05:59:21+00:00","dateModified":"2024-08-28T05:59:41+00:00","description":"For some reason you try to access your database and get the error Can't connect to local server through socket '\/run\/mysqld\/mysqld.sock' (2).","breadcrumb":{"@id":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/truehost.com\/support\/knowledge-base\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\/#primaryimage","url":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-13.png","contentUrl":"https:\/\/truehost.com\/support\/wp-content\/uploads\/2024\/08\/image-13.png"},{"@type":"BreadcrumbList","@id":"https:\/\/truehost.com\/support\/knowledge-base\/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/truehost.com\/support\/"},{"@type":"ListItem","position":2,"name":"How to resolve &#8211; Can&#8217;t connect to local server through socket &#8216;\/run\/mysqld\/mysqld.sock&#8217; (2)"}]},{"@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\/13812","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=13812"}],"version-history":[{"count":1,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs\/13812\/revisions"}],"predecessor-version":[{"id":13819,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/docs\/13812\/revisions\/13819"}],"wp:attachment":[{"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/media?parent=13812"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/doc_category?post=13812"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/truehost.com\/support\/wp-json\/wp\/v2\/doc_tag?post=13812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}