{"id":113,"date":"2019-07-18T19:36:03","date_gmt":"2019-07-18T14:06:03","guid":{"rendered":"https:\/\/www.onlinenote.in\/linux\/?p=113"},"modified":"2019-07-18T19:40:05","modified_gmt":"2019-07-18T14:10:05","slug":"how-to-troubleshoot-socket-errors-in-mysql-ubuntu","status":"publish","type":"post","link":"https:\/\/www.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/","title":{"rendered":"How To Troubleshoot Socket Errors in MySQL &#8211; Ubuntu"},"content":{"rendered":"<p>MySQL manages connections to the database server through the use of a\u00a0<em>socket file<\/em>, a special kind of file that facilitates communications between different processes. The MySQL server&#8217;s socket file is named\u00a0<code>mysqld.sock<\/code>\u00a0and on Ubuntu systems it&#8217;s usually stored in the\u00a0<code>\/var\/run\/mysqld\/<\/code>\u00a0directory. This file is created by the MySQL service automatically.<\/p>\n<p>Sometimes, changes to your system or your MySQL configuration can result in MySQL being unable to read the socket file, preventing you from gaining access to your databases. The most common socket error looks like this:<\/p>\n<p><code>ERROR 2002 (HY000): Can't connect to local MySQL server through socket '\/var\/run\/mysqld\/mysqld.sock' (2)<\/code><\/p>\n<p>One common cause of this error is that the MySQL service is stopped or did not start to begin with, meaning that it was unable to create the socket file in the first place. To find out if this is the reason you&#8217;re seeing this error, try starting the service with\u00a0<code>systemctl<\/code>:<\/p>\n<pre class=\"lang:default decode:true \">sudo systemctl start mysql<\/pre>\n<p>Then try accessing the MySQL prompt again. If you still receive the socket error, double check the location where your MySQL installation is looking for the socket file. This information can be found in the\u00a0<code>mysqld.cnf<\/code> file.<\/p>\n<pre class=\"lang:default decode:true\">sudo nano \/etc\/mysql\/mysql.conf.d\/mysqld.cnf<\/pre>\n<p>Look for the\u00a0<code>socket<\/code>\u00a0parameter in the\u00a0<code>[mysqld]<\/code>\u00a0section of this file. It will look like this:<\/p>\n<pre class=\"lang:default decode:true \" title=\"\/etc\/mysql\/mysql.conf.d\/mysqld.cnf\">. . .\r\n[mysqld]\r\nuser            = mysql\r\npid-file        = \/var\/run\/mysqld\/mysqld.pid\r\nsocket          = \/var\/run\/mysqld\/mysqld.sock\r\nport            = 3306\r\n. . .<\/pre>\n<p>Close this file, then ensure that the\u00a0<code>mysqld.sock<\/code>\u00a0file exists by running an\u00a0<code>ls<\/code>\u00a0command on the directory where MySQL expects to find it:<\/p>\n<pre class=\"lang:default decode:true \">ls -a \/var\/run\/mysqld\/<\/pre>\n<p><code>Output<br \/>\n.  ..  mysqld.pid  mysqld.sock  mysqld.sock.lock<\/code><\/p>\n<p>If the file does not exist, the reason may be that MySQL is trying to create it, but does not have adequate permissions to do so. You can ensure that the correct permissions are in place by changing the directory&#8217;s ownership to the\u00a0<strong>mysql<\/strong> user (user as in mysqld.cnf file shows above) and group:<\/p>\n<pre class=\"lang:default decode:true \">sudo chown mysql:mysql \/var\/run\/mysqld\/<\/pre>\n<p>Then ensure that the\u00a0<strong>mysql<\/strong>\u00a0user has the appropriate permissions over the directory. Setting these to\u00a0<code>775<\/code>\u00a0will work in most cases:<\/p>\n<pre class=\"lang:default decode:true \">sudo chmod -R 755 \/var\/run\/mysqld\/<\/pre>\n<p>Finally, restart the MySQL service so it can attempt to create the socket file again:<\/p>\n<pre class=\"lang:default decode:true \">sudo systemctl restart mysql<\/pre>\n<p>Then try accessing the MySQL prompt once again. If you still encounter the socket error, there&#8217;s likely a deeper issue with your MySQL instance, in which case you should review the error log.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL manages connections to the database server through the use of a\u00a0socket file, a special kind of file that facilitates communications between different processes. The MySQL server&#8217;s socket file is named\u00a0mysqld.sock\u00a0and on Ubuntu systems it&#8217;s usually stored in the\u00a0\/var\/run\/mysqld\/\u00a0directory. This file is created by the MySQL service automatically. Sometimes, changes to your system or your [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[10],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.10 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Troubleshoot Socket Errors in MySQL - Ubuntu - linux<\/title>\n<meta name=\"description\" content=\"ERROR 2002 (HY000): Can&#039;t connect to local MySQL server through socket &#039;\/var\/run\/mysqld\/mysqld.sock&#039; error in mysql ubuntu apache server.\" \/>\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.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Troubleshoot Socket Errors in MySQL - Ubuntu - linux\" \/>\n<meta property=\"og:description\" content=\"ERROR 2002 (HY000): Can&#039;t connect to local MySQL server through socket &#039;\/var\/run\/mysqld\/mysqld.sock&#039; error in mysql ubuntu apache server.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/\" \/>\n<meta property=\"og:site_name\" content=\"linux\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-18T14:06:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-07-18T14:10:05+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/\",\"url\":\"https:\/\/www.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/\",\"name\":\"How To Troubleshoot Socket Errors in MySQL - Ubuntu - linux\",\"isPartOf\":{\"@id\":\"https:\/\/www.onlinenote.in\/linux\/#website\"},\"datePublished\":\"2019-07-18T14:06:03+00:00\",\"dateModified\":\"2019-07-18T14:10:05+00:00\",\"author\":{\"@id\":\"\"},\"description\":\"ERROR 2002 (HY000): Can't connect to local MySQL server through socket '\/var\/run\/mysqld\/mysqld.sock' error in mysql ubuntu apache server.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.onlinenote.in\/linux\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Troubleshoot Socket Errors in MySQL &#8211; Ubuntu\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.onlinenote.in\/linux\/#website\",\"url\":\"https:\/\/www.onlinenote.in\/linux\/\",\"name\":\"linux\",\"description\":\"Code Snippets\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.onlinenote.in\/linux\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Troubleshoot Socket Errors in MySQL - Ubuntu - linux","description":"ERROR 2002 (HY000): Can't connect to local MySQL server through socket '\/var\/run\/mysqld\/mysqld.sock' error in mysql ubuntu apache server.","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.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/","og_locale":"en_US","og_type":"article","og_title":"How To Troubleshoot Socket Errors in MySQL - Ubuntu - linux","og_description":"ERROR 2002 (HY000): Can't connect to local MySQL server through socket '\/var\/run\/mysqld\/mysqld.sock' error in mysql ubuntu apache server.","og_url":"https:\/\/www.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/","og_site_name":"linux","article_published_time":"2019-07-18T14:06:03+00:00","article_modified_time":"2019-07-18T14:10:05+00:00","twitter_card":"summary_large_image","twitter_misc":{"Written by":"","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/","url":"https:\/\/www.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/","name":"How To Troubleshoot Socket Errors in MySQL - Ubuntu - linux","isPartOf":{"@id":"https:\/\/www.onlinenote.in\/linux\/#website"},"datePublished":"2019-07-18T14:06:03+00:00","dateModified":"2019-07-18T14:10:05+00:00","author":{"@id":""},"description":"ERROR 2002 (HY000): Can't connect to local MySQL server through socket '\/var\/run\/mysqld\/mysqld.sock' error in mysql ubuntu apache server.","breadcrumb":{"@id":"https:\/\/www.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.onlinenote.in\/linux\/how-to-troubleshoot-socket-errors-in-mysql-ubuntu\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.onlinenote.in\/linux\/"},{"@type":"ListItem","position":2,"name":"How To Troubleshoot Socket Errors in MySQL &#8211; Ubuntu"}]},{"@type":"WebSite","@id":"https:\/\/www.onlinenote.in\/linux\/#website","url":"https:\/\/www.onlinenote.in\/linux\/","name":"linux","description":"Code Snippets","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.onlinenote.in\/linux\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":""}]}},"_links":{"self":[{"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/posts\/113"}],"collection":[{"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/comments?post=113"}],"version-history":[{"count":2,"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/posts\/113\/revisions"}],"predecessor-version":[{"id":115,"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/posts\/113\/revisions\/115"}],"wp:attachment":[{"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/media?parent=113"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/categories?post=113"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.onlinenote.in\/linux\/wp-json\/wp\/v2\/tags?post=113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}