I recently upgraded my MacPorts-based PHP install to 5.3 and thought I’d try out this new mysqlnd client library. So I did this:
sudo port -f uninstall php5 sudo port install php5 +apache2+macports_snmp+mysqlnd+pear
All appeared to work fine, but trying to connect to my database server from PHP gave me an error:
PHP Warning: mysqli::mysqli():  No such file or directory (trying to connect via unix:///tmp/mysql.sock) in /Users/mike/Sites/database.php on line 13
PHP Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in /Users/mike/Sites/database.php on line 13
By default, any connections to “localhost” are handled through UNIX sockets, which are referred to by file names. In this case, mysqlnd seems to be checking
/tmp/mysql.sock, even though the MacPorts MySQL likes to use
/opt/local/var/run/mysql5/mysqld.sock. The reason this used to work is that the older client library was actually part of MySQL so the defaults for both were the same. Now that the library is part of PHP, things have changed. We’ll fix this problem by telling MySQL to put the socket file somewhere else; you can’t tell mysqlnd where to put it, without recompiling PHP. And if we wanted to compile stuff, we wouldn’t be using MacPorts!
/opt/local/etc/mysql5/my.cnf to add these commands:
[mysqld] socket=/tmp/mysql.sock [client] socket=/tmp/mysql.sock
client section affects all clients, such as
mysqldump; they can also be specified separately if desired.
One Reply to “MacPorts upgrade to mysqlnd”
Comments are closed.