{"id":2156,"date":"2011-12-21T15:48:06","date_gmt":"2011-12-21T21:48:06","guid":{"rendered":"http:\/\/icesquare.com\/wordpress\/?p=2156"},"modified":"2012-08-14T18:04:21","modified_gmt":"2012-08-14T23:04:21","slug":"cant-connect-to-local-mysql-server-through-socket-varlibmysqlmysql-sock-2","status":"publish","type":"post","link":"https:\/\/icesquare.com\/wordpress\/cant-connect-to-local-mysql-server-through-socket-varlibmysqlmysql-sock-2\/","title":{"rendered":"Can&#8217;t connect to local MySQL server through socket &#8216;\/var\/lib\/mysql\/mysql.sock&#8217; (2)"},"content":{"rendered":"<p><img decoding=\"async\" src=\"\/wordpress\/wp-content\/uploads\/2011\/12\/computer_problem-150x150.jpg\" alt=\"\" title=\"Computer Problem\" width=\"150\" class=\"alignleft size-thumbnail wp-image-2158\" \/><\/p>\n<p>\nWhen I tried to connect to the MySQL server through PHP, I got the following error: <strong>Can&#8217;t connect to local MySQL server through socket &#8216;\/var\/lib\/mysql\/mysql.sock&#8217; (2)<\/strong>\n<\/p>\n<p>\nTo give you some background, here is my situation. My Fedora Linux is a 64-bit machine, and I have installed a 32-bit version of XAMPP (i.e., 32-bit PHP, 32-bit MySQL) for the web server. Also, I have some PHP scripts that will be run in background. These scripts are run using 64-bit PHP. Both 32-bit and 64-bit PHP need to access the MySQL database. Long story short. I got the MySQL error message when I tried to execute using the 64-bit PHP, while the 32-bit PHP has no complain.\n<\/p>\n<div class=\"alignright\"><\/div>\n<p style=\"margin-top:20px;\">When PHP talks to MySQL, it needs to talk to the MySQL representative, i.e., <strong>mysql.sock<\/strong>. If it cannot talk to the mysql.sock, then PHP will be unable to access the MySQL database.<\/p>\n<p>The reason why my 64-bit PHP could not talk to MySQL because of a wrong location of mysql.sock. To solve this problem, simply do the following:<\/p>\n<p style=\"margin-top:80px;\">First, let&#8217;s find out where is the PHP.ini of the 64-bit PHP:<\/p>\n<pre>\r\nsudo find \/ -name \"php.ini\"\r\n<\/pre>\n<p>In Fedora Linux, it is:<\/p>\n<pre>\r\n\/etc\/php.ini\r\n<\/pre>\n<p>Then, we need to find out where is the mysql.sock:<\/p>\n<pre>\r\nsudo find \/ -name \"mysql.sock\"\r\n<\/pre>\n<p>In my case, it is:<\/p>\n<pre>\r\n\/opt\/lampp\/var\/mysql\/mysql.sock\r\n<\/pre>\n<p>Now, let&#8217;s tell PHP the location of the mysql.sock:<\/p>\n<pre>\r\nsudo nano \/etc\/php.ini\r\n<\/pre>\n<p>And change the following line from:<\/p>\n<pre>\r\nmysql.default_socket =\r\n<\/pre>\n<p>to:<\/p>\n<pre>\r\nmysql.default_socket = \/opt\/lampp\/var\/mysql\/mysql.sock\r\n<\/pre>\n<p>Now, try to run your script again. The problem should be gone.<\/p>\n<p>Have fun with MySQL.<\/p>\n<p>&#8211;Derrick<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I tried to connect to the MySQL server through PHP, I got the following error: Can&#8217;t connect to local MySQL server through socket &#8216;\/var\/lib\/mysql\/mysql.sock&#8217; (2) To give you some <a class=\"more-link\" href=\"https:\/\/icesquare.com\/wordpress\/cant-connect-to-local-mysql-server-through-socket-varlibmysqlmysql-sock-2\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_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":[94,10,144,6,69],"tags":[9,172],"class_list":["post-2156","post","type-post","status-publish","format-standard","hentry","category-computer-problems-computer-help-pc-support","category-php","category-sever-problem","category-technology","category-troubleshooting-technology","tag-mysql","tag-php"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p1sqzr-yM","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":41,"url":"https:\/\/icesquare.com\/wordpress\/installing-apache-php-mysql-and-memcached-on-os-x\/","url_meta":{"origin":2156,"position":0},"title":"Installing Apache, PHP, MySQL and MemCached on OS X","author":"Derrick","date":"May 19, 2009","format":false,"excerpt":"This is my note on how to to install Apache, PHP and MySQL on a an OS X box. Although some of these applications are come with the operating systems, it is always good to know how to upgrade them to the latest version. 1. Apple Developer Tools and Mac\u2026","rel":"","context":"In &quot;Server Problems&quot;","block_context":{"text":"Server Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/sever-problem\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":603,"url":"https:\/\/icesquare.com\/wordpress\/weird-php-error-after-freebsd-port-upgrade\/","url_meta":{"origin":2156,"position":1},"title":"Weird PHP Error after FreeBSD port upgrade (PHP Warning:  PHP Startup: Unable to load dynamic library)","author":"Derrick","date":"April 6, 2010","format":false,"excerpt":"Today I upgraded the port on my FreeBSD box using portmaster tools: portmaster -Dai After that, I found that the PHP gave the following weird error: php -v PHP Warning: PHP Startup: Unable to load dynamic library '\/usr\/local\/lib\/php\/20060613\/memcached.so' - \/usr\/local\/lib\/php\/20060613\/memcached.so: Undefined symbol \" php_session_create_id\" in Unknown on line 0 PHP\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":31,"url":"https:\/\/icesquare.com\/wordpress\/installing-apache-php-mysql-and-memcached-on-freebsd\/","url_meta":{"origin":2156,"position":2},"title":"Installing Apache, PHP, MySQL and MemCached on FreeBSD","author":"Derrick","date":"May 19, 2009","format":false,"excerpt":"This is my note on how to to install Apache, PHP, MySQL and MemCached on a FreeBSD 7 Box. 1. MySQL Go to the mysql52-server port directory by typing the command: cd \/usr\/ports\/databases\/mysql51-server Build the port by typing: make BUILD_OPTIMIZED=yes BUILD_STATIC=yes Using these two options will speed up the execution\u2026","rel":"","context":"In &quot;FreeBSD&quot;","block_context":{"text":"FreeBSD","link":"https:\/\/icesquare.com\/wordpress\/category\/sever-problem\/freebsd\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1028,"url":"https:\/\/icesquare.com\/wordpress\/mysql-starting-mysql-error-the-server-quit-without-updating-pid-file\/","url_meta":{"origin":2156,"position":3},"title":"MySQL: Starting MySQL&#8230;.. ERROR! The server quit without updating PID file","author":"Derrick","date":"November 12, 2010","format":false,"excerpt":"This step-by-step guide is mainly for FreeBSD, however the idea is the same for Linux. Every once a while, when I update my FreeBSD box, the system likes to shutdown my MySQL server. Therefore, I need to start it again after the update is done. Unfortunately, the upgrade process is\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3495,"url":"https:\/\/icesquare.com\/wordpress\/xampp-php-fatal-error-class-ziparchive-not-found\/","url_meta":{"origin":2156,"position":4},"title":"XAMPP &#8211; PHP Fatal error:  Class &#8216;ZipArchive&#8217; not found","author":"Derrick","date":"March 11, 2014","format":false,"excerpt":"I just finished writing a program written in PHP today. When I moved to the another environment, I found that the script didn't work. After some investigations, I found that the program stopped running because of the following error: PHP Fatal error: Class 'ZipArchive' not found in ... The error\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/icesquare.com\/wordpress\/wp-content\/uploads\/2014\/03\/xampp-logo.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":305,"url":"https:\/\/icesquare.com\/wordpress\/installing-xampp-on-fedora-12-64-bit\/","url_meta":{"origin":2156,"position":5},"title":"Installing XAMPP on Fedora 12 64-bit system","author":"Derrick","date":"December 8, 2009","format":false,"excerpt":"I was installing XAMPP on Fedora 11 64-bit today, and I saw this famous message: sudo \/opt\/lampp\/lampp startapache XAMPP is currently only availably as 32 bit application. Please use a 32 bit compatibility library for your system. The message is very clear that XAMPP doesn't like 32-bit system. So, we\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts\/2156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/comments?post=2156"}],"version-history":[{"count":21,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts\/2156\/revisions"}],"predecessor-version":[{"id":2855,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts\/2156\/revisions\/2855"}],"wp:attachment":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/media?parent=2156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/categories?post=2156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/tags?post=2156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}