How to solve "Nosuchfileordirectory" error when connecting PHP to MySQL in Mac
"No such file or directory" error reported when connecting PHP to MySQL in Mac
First, let's give a brief introduction.
[NOTE 1] installation path of MYSQL in MAC:/usr/local/mysql-5.5.28-osx10.6-x86
The database data files are stored in the data folder of the directory;
The command file is in the bin folder.
[NOTE 2] how to open mysql command line via Terminal:/usr/local/mysql-5.5.28-osx10.6-x86/bin/mysql
Next, let's talk about the solution to the error when connecting to the MYSQL database.
1. First, the problem is mysql_connect () and mysql_pconnect (). The fault is that the function returns NULL, while mysql_error () returns "No such file or directory"
2. On the phpinfo page, locate mysql. default_socket, mysqli. default_socket, and pdo_mysql.default_socket.
3. Start mysql (see description 2), execute the command STATUS, and write down the UNIX socket Value
4. If the values of 2 and 3 are different, open php. ini (you can find php. ini location. The default value is/private/etc/php. ini), change the value of the three configuration items mentioned in 2 to the value of 3.
(Note: There are three changes: mysql. default_socket, mysqli. default_socket, and pdo_mysql.default_socket)
5. Restart apache
OK. The error is excluded here.