{"id":48737,"date":"2021-03-18T11:43:34","date_gmt":"2021-03-18T11:43:34","guid":{"rendered":"https:\/\/www.awardspace.com\/?p=48737"},"modified":"2024-02-28T12:14:07","modified_gmt":"2024-02-28T12:14:07","slug":"how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2","status":"publish","type":"post","link":"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/","title":{"rendered":"How to Fix \u201cWarning: mysql_connect(): Can&#8217;t connect to local MySQL server through socket &#8216;\/var\/run\/mysqld\/mysqld.sock&#8217; (2)\u201d"},"content":{"rendered":"<p>The reason for this warning is due to the fact that you are using localhost as the hostname for your database in your script. Please note that localhost is used only when your web and database are located on the same server. On our hosting platform, the database is located on a separate server. In order to connect to your database, you must use the hostname for your database. You can find this information inside the Database Manager of your hosting control panel.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The reason for this warning is due to the fact that you are using localhost as the hostname for your database in your script. Please note that localhost is used only when your web and database are located on the same server. On our hosting platform, the database is located on a separate server. In [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":33819,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[56],"tags":[],"class_list":["post-48737","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-database-management"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Fix \u201cWarning: mysql_connect(): Can&#039;t connect to local MySQL server through socket &#039;\/var\/run\/mysqld\/mysqld.sock&#039; (2)\u201d - AwardSpace.com<\/title>\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.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-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 Fix \u201cWarning: mysql_connect(): Can&#039;t connect to local MySQL server through socket &#039;\/var\/run\/mysqld\/mysqld.sock&#039; (2)\u201d - AwardSpace.com\" \/>\n<meta property=\"og:description\" content=\"The reason for this warning is due to the fact that you are using localhost as the hostname for your database in your script. Please note that localhost is used only when your web and database are located on the same server. On our hosting platform, the database is located on a separate server. In [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/\" \/>\n<meta property=\"og:site_name\" content=\"AwardSpace.com\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/AwardSpace\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-18T11:43:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-28T12:14:07+00:00\" \/>\n<meta name=\"author\" content=\"Lazar Shishmanov, PhD\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@awspace\" \/>\n<meta name=\"twitter:site\" content=\"@awspace\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Lazar Shishmanov, PhD\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/\"},\"author\":{\"name\":\"Lazar Shishmanov, PhD\",\"@id\":\"https:\/\/www.awardspace.com\/#\/schema\/person\/13f0961f1cff18623121a6716f08c58b\"},\"headline\":\"How to Fix \u201cWarning: mysql_connect(): Can&#8217;t connect to local MySQL server through socket &#8216;\/var\/run\/mysqld\/mysqld.sock&#8217; (2)\u201d\",\"datePublished\":\"2021-03-18T11:43:34+00:00\",\"dateModified\":\"2024-02-28T12:14:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/\"},\"wordCount\":103,\"publisher\":{\"@id\":\"https:\/\/www.awardspace.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/#primaryimage\"},\"thumbnailUrl\":\"\",\"articleSection\":[\"Database Management\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/\",\"url\":\"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/\",\"name\":\"How to Fix \u201cWarning: mysql_connect(): Can't connect to local MySQL server through socket '\/var\/run\/mysqld\/mysqld.sock' (2)\u201d - AwardSpace.com\",\"isPartOf\":{\"@id\":\"https:\/\/www.awardspace.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/#primaryimage\"},\"thumbnailUrl\":\"\",\"datePublished\":\"2021-03-18T11:43:34+00:00\",\"dateModified\":\"2024-02-28T12:14:07+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/#primaryimage\",\"url\":\"\",\"contentUrl\":\"\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.awardspace.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Knowledge Base\",\"item\":\"https:\/\/www.awardspace.com\/kb\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"F.A.Q.\",\"item\":\"https:\/\/www.awardspace.com\/kb\/f-a-q\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Database Management\",\"item\":\"https:\/\/www.awardspace.com\/kb\/f-a-q\/database-management\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"How to Fix \u201cWarning: mysql_connect(): Can&#8217;t connect to local MySQL server through socket &#8216;\/var\/run\/mysqld\/mysqld.sock&#8217; (2)\u201d\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.awardspace.com\/#website\",\"url\":\"https:\/\/www.awardspace.com\/\",\"name\":\"AwardSpace.com\",\"description\":\"Free Web Hosting with PHP, MySQL, Email Sending, No Ads\",\"publisher\":{\"@id\":\"https:\/\/www.awardspace.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.awardspace.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.awardspace.com\/#organization\",\"name\":\"AwardSpace.com\",\"url\":\"https:\/\/www.awardspace.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.awardspace.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.awardspace.com\/wp-content\/uploads\/2018\/08\/awardspace_logo.png\",\"contentUrl\":\"https:\/\/www.awardspace.com\/wp-content\/uploads\/2018\/08\/awardspace_logo.png\",\"width\":1759,\"height\":176,\"caption\":\"AwardSpace.com\"},\"image\":{\"@id\":\"https:\/\/www.awardspace.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/AwardSpace\/\",\"https:\/\/x.com\/awspace\",\"https:\/\/www.instagram.com\/awardspace\/\",\"https:\/\/www.quora.com\/profile\/Award-Space\",\"https:\/\/www.linkedin.com\/company\/19214384\/\",\"https:\/\/www.reddit.com\/user\/AwardSpace\",\"https:\/\/www.pinterest.com\/awardspace\/\",\"https:\/\/www.youtube.com\/user\/AwardspaceWebHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.awardspace.com\/#\/schema\/person\/13f0961f1cff18623121a6716f08c58b\",\"name\":\"Lazar Shishmanov, PhD\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.awardspace.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/341ac134090ebf7e8095d20d79485f8652e19c1d00cfef899e40c69ec4ac10cb?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/341ac134090ebf7e8095d20d79485f8652e19c1d00cfef899e40c69ec4ac10cb?s=96&d=mm&r=g\",\"caption\":\"Lazar Shishmanov, PhD\"},\"description\":\"Lazar is a marketing specialist with more than ten years of experience in the field, eight of which as part of the marketing department at AwardSpace. Academically, Lazar holds a Bachelor's degree in Public Relations, a Master's degree in Semiotics, Language and Advertising, and is a PhD candidate in Integrated Marketing Communications. You can learn more about Lazar on his personal website.\",\"url\":\"https:\/\/www.awardspace.com\/author\/lazar\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Fix \u201cWarning: mysql_connect(): Can't connect to local MySQL server through socket '\/var\/run\/mysqld\/mysqld.sock' (2)\u201d - AwardSpace.com","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.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/","og_locale":"en_US","og_type":"article","og_title":"How to Fix \u201cWarning: mysql_connect(): Can't connect to local MySQL server through socket '\/var\/run\/mysqld\/mysqld.sock' (2)\u201d - AwardSpace.com","og_description":"The reason for this warning is due to the fact that you are using localhost as the hostname for your database in your script. Please note that localhost is used only when your web and database are located on the same server. On our hosting platform, the database is located on a separate server. In [&hellip;]","og_url":"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/","og_site_name":"AwardSpace.com","article_publisher":"https:\/\/www.facebook.com\/AwardSpace\/","article_published_time":"2021-03-18T11:43:34+00:00","article_modified_time":"2024-02-28T12:14:07+00:00","author":"Lazar Shishmanov, PhD","twitter_card":"summary_large_image","twitter_creator":"@awspace","twitter_site":"@awspace","twitter_misc":{"Written by":"Lazar Shishmanov, PhD","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/#article","isPartOf":{"@id":"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/"},"author":{"name":"Lazar Shishmanov, PhD","@id":"https:\/\/www.awardspace.com\/#\/schema\/person\/13f0961f1cff18623121a6716f08c58b"},"headline":"How to Fix \u201cWarning: mysql_connect(): Can&#8217;t connect to local MySQL server through socket &#8216;\/var\/run\/mysqld\/mysqld.sock&#8217; (2)\u201d","datePublished":"2021-03-18T11:43:34+00:00","dateModified":"2024-02-28T12:14:07+00:00","mainEntityOfPage":{"@id":"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/"},"wordCount":103,"publisher":{"@id":"https:\/\/www.awardspace.com\/#organization"},"image":{"@id":"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/#primaryimage"},"thumbnailUrl":"","articleSection":["Database Management"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/","url":"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/","name":"How to Fix \u201cWarning: mysql_connect(): Can't connect to local MySQL server through socket '\/var\/run\/mysqld\/mysqld.sock' (2)\u201d - AwardSpace.com","isPartOf":{"@id":"https:\/\/www.awardspace.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/#primaryimage"},"image":{"@id":"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/#primaryimage"},"thumbnailUrl":"","datePublished":"2021-03-18T11:43:34+00:00","dateModified":"2024-02-28T12:14:07+00:00","breadcrumb":{"@id":"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/www.awardspace.com\/kb\/how-to-fix-warning-mysql-connect-cant-connect-to-local-mysql-server-through-socket-var-run-mysqld-mysqld-sock-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.awardspace.com\/"},{"@type":"ListItem","position":2,"name":"Knowledge Base","item":"https:\/\/www.awardspace.com\/kb\/"},{"@type":"ListItem","position":3,"name":"F.A.Q.","item":"https:\/\/www.awardspace.com\/kb\/f-a-q\/"},{"@type":"ListItem","position":4,"name":"Database Management","item":"https:\/\/www.awardspace.com\/kb\/f-a-q\/database-management\/"},{"@type":"ListItem","position":5,"name":"How to Fix \u201cWarning: mysql_connect(): Can&#8217;t connect to local MySQL server through socket &#8216;\/var\/run\/mysqld\/mysqld.sock&#8217; (2)\u201d"}]},{"@type":"WebSite","@id":"https:\/\/www.awardspace.com\/#website","url":"https:\/\/www.awardspace.com\/","name":"AwardSpace.com","description":"Free Web Hosting with PHP, MySQL, Email Sending, No Ads","publisher":{"@id":"https:\/\/www.awardspace.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.awardspace.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.awardspace.com\/#organization","name":"AwardSpace.com","url":"https:\/\/www.awardspace.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.awardspace.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.awardspace.com\/wp-content\/uploads\/2018\/08\/awardspace_logo.png","contentUrl":"https:\/\/www.awardspace.com\/wp-content\/uploads\/2018\/08\/awardspace_logo.png","width":1759,"height":176,"caption":"AwardSpace.com"},"image":{"@id":"https:\/\/www.awardspace.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/AwardSpace\/","https:\/\/x.com\/awspace","https:\/\/www.instagram.com\/awardspace\/","https:\/\/www.quora.com\/profile\/Award-Space","https:\/\/www.linkedin.com\/company\/19214384\/","https:\/\/www.reddit.com\/user\/AwardSpace","https:\/\/www.pinterest.com\/awardspace\/","https:\/\/www.youtube.com\/user\/AwardspaceWebHosting"]},{"@type":"Person","@id":"https:\/\/www.awardspace.com\/#\/schema\/person\/13f0961f1cff18623121a6716f08c58b","name":"Lazar Shishmanov, PhD","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.awardspace.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/341ac134090ebf7e8095d20d79485f8652e19c1d00cfef899e40c69ec4ac10cb?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/341ac134090ebf7e8095d20d79485f8652e19c1d00cfef899e40c69ec4ac10cb?s=96&d=mm&r=g","caption":"Lazar Shishmanov, PhD"},"description":"Lazar is a marketing specialist with more than ten years of experience in the field, eight of which as part of the marketing department at AwardSpace. Academically, Lazar holds a Bachelor's degree in Public Relations, a Master's degree in Semiotics, Language and Advertising, and is a PhD candidate in Integrated Marketing Communications. You can learn more about Lazar on his personal website.","url":"https:\/\/www.awardspace.com\/author\/lazar\/"}]}},"_links":{"self":[{"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/posts\/48737","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/comments?post=48737"}],"version-history":[{"count":0,"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/posts\/48737\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.awardspace.com\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/media?parent=48737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/categories?post=48737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.awardspace.com\/wp-json\/wp\/v2\/tags?post=48737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}