MySQL was successfully connected via phpMyAdmin, but failed to connect to the database via PHP, execute the following PHP statement
?
| 1 |
@mysql_connect("localhost","root","12345") ordie("数据库服务器连接失败");// 连接服务器 |
After that, the browser output database server connection failed with the workaround below.
1, the MySQL installation path for Mac, * for the version number, is the number.
?
| 1 |
/usr/local/mysql_******_osx10.*_x86_64 |
2, enter this folder after the bin to find the MySQL, double-click Open, double-tap does not open the choice of terminal Open, and then enter
?
Find the value of the UNIX socket after carriage return
3. Find PHP.ini, find/etc/php.ini in Finder, copy to desktop, open with document, press and hold command+f, then find pdo_mysql.default_socket, Mysql.default_socket, Mysqli.default_socket These three values, changed to the UNIX socket above the value, modified to copy to just the folder, replace the previous file
4, open the terminal, input sudo apachectl restart restart Apache can, again execute will not error
PHP connection to MySQL database under Mac failure solution