Mysql_connect (): [2002] No such file or directory

Source: Internet
Author: User
Tags fpm zend

Build PHP's development environment in Mac

1. Apach----recommended with Mamp. Just put your PHP file/project into the Htdocs (/applications/mamp/htdocs) directory, start MAMP, enter localhost to see all the files in your directory directly. -because of this relatively simple, here no longer repeat, if any problem, welcome to contact the exchange.

2. Nginx----Because there is no integrated tool, the configuration of Nginx relative Apach is relatively complex. For example, you need to download MySQL, download php-fpm, and even use homebrew to install it. (My instructions below are based on the homebrew installation scenario) Here I briefly explain a few things that require special attention:

Configuration of 2.1 Nginx

What needs to be explained is the configuration of conf file server under/usr/local/etc/nginx, fastcgi_param option, note when adding $document_root, as shown below: Actually, the following $document_root$ Fastcgi_script_name is consistent with the values inside the fastcgi.conf.

Server {Listen the; server_name localhost; //Specify your domain name#charset koi8-S; #access_log logs/Host.access.log Main; Location/{root/users/megan/www/;//specify the path to your projectindex index.html index.htm; } #error_page404/404. html; # REDIRECT Server error pages to theStaticPage/50x.html # Error_page - 502 503 504/50x.html; Location= /50x.html {root html; } # Proxy The PHP scripts to Apache listening on127.0.0.1: the# #location~\.php$ {# Proxy_pass;#} # Pass the PHP scripts to FastCGI server listening on127.0.0.1:9000# Location~\.php$ {root html; Fastcgi_pass127.0.0.1:9000;            Fastcgi_index index.php;            Fastcgi_param script_filename $document _root$fastcgi_script_name;        Include Fastcgi_params; } # Deny access to. htaccess files,ifApache's Document Root# concurs with Nginx'S One# #location~ /\.ht {# deny all; #}    }

2.2 MySQL Configuration

This article is caused by MySQL, here is simple to talk about the simple MySQL command.

Start--Mysql.server start

Close--Mysql.server stop

Restart--Mysql.server restart

Connect--Mysql-uroot or mysql-uroot-p (here is the password)

Import data--Source: /*.sql

Configuration of the 2.3 php-fpm

The most depressing thing about this stuff is that I didn't find a good reboot and shutdown command. For example Nginx start with sudo nginx, close with sudo nginx-s-stop re-enable sudo nginx-s reload. But php-fpm I only use sudo php-fpm to start. The way off is simply rude.

I first use PS aux|grep php to see which PHP processes are running and then execute the kill PHP-FPM related process. For example, the following results are executed (sudo) kill 3870 3871 3872. Once again, you will see that these processes are gone. (If any colleague has a better approach and can show the way, than the woman will be greatly appreciated)

[Email protected]:~] $ps aux|grep Phpmegan1338   4.6  7.4  1824760 389504?? STen: 51AM at:40.56/applications/zend-eclipse-php/ MACOSX-WS Cocoa-arch x86- Launcher/applications/zend-eclipse-php/ Zend Eclipse forPHP Developers--launcher.library/applications/zend-eclipse-php/ /.. /.. /plugins/org.eclipse.equinox.launcher.cocoa.macosx_1.1.200.v20120522-1813/ /zend-eclipse-php/ /.. /.. /plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar--launcher.overridevmargs-showlocation-launcher/ applications/zend-eclipse-php/ Megan/www-launcher/applications/zend-eclipse-php/ Showlocation-keyring/users/megan/.eclipse_keyring-showlocation-vm/system/library/frameworks/javavm.framework- Vmargs-xms128m-xmx512m-djava.awt.headless=true-xstartonfirstthread-dorg.eclipse.swt.internal.carbon.smallfonts -xdock:icon=. /resources/eclipse.icns-xx:maxpermsize=256mMegan3981   0.4  0.0  2442000    628s001 s+6: 48PM0:00.01grep phpnobody3872   0.0  0.2  2481552  12008?? S5: 57PM0:05.74php-Fpmnobody3871   0.0  0.2  2481552  12748?? S5: 57PM0:01.09php-Fpmroot3870   0.0  0.0  2464912    592?? Ss5: 57PM0:00.23php-fpm

back to the question

In fact, the problem is very simple, just need to find your mysql.sock and then go back to your php.ini to modify a configuration just fine. The main is the following three lines of code.

// If you are using zendframework, this needs to be configured

// The following two items are configured if you are using OpenCart, etc. and do not use PDO. mysql.default_socket =/tmp/=/tmp/mysql.sock

The only thing that's actually done is to configure the Mysql.sock to Default_socket.

In fact, the main problem here is how you find your mysql.sock, how to find your php.ini. Play so on the Mac, in addition to doing iOS development, whether it is playing Java or PHP or other, the most depressing thing is to find the relevant configuration file. What Whereis,locate,which and so on have used all over, often still can't find document, that kind of pain, don't want to say more.

The easiest way to find php.ini--to build a file, Phpinfo () will make the world a wonderful place.

Find Mysql.sock-You might use Mysqladmin viriables to see all of MySQL's parameters, and you may find that Mysql.sock's path points to/tmp/ Mysql.sock, but you can't find the file, even though you can't see the file in all the hidden files.

Directive Local Value Master Value
Pdo_mysql.default_socket /var/mysql/mysql.sock /var/mysql/mysql.sock

Then you can execute sudo find/-name mysql.sock It will tell you that in fact your mysql.sock is here in Private/tmp/mysql.sock. Then you might want to use this line of code to build a shortcut.


Ok, yes, maybe it will remind you that the file already exists. It doesn't matter, ignore it, although you still can't see Mysql.sock in/tmp. You just have to use it. I don't know which corner I can't see anymore. In short, there is a mysql.sock shortcut under/tmp for you to use.


Mysql_connect (): [2002] No such file or directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.