PHP & MySQL on Leopard: mysql.sock 的位置

One thing I noticed setting up PHP and MySQL on Leopard, is that the default PHP build looks for the MySQL socket in /var/mysql/mysql.sock which doesn’t exist and isn’t the location that MySQL would use if it did (by default anyway). By default the MySQL socket is: /tmp/mysql.sock.

There are four ways to fix this:

  1. Create the /var/mysql directory (sudo mkdir /var/mysql) and then create a symbolic link from/tmp/mysql.sock to /var/mysql/mysql.sock (with: sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock).
  2. Edit the /etc/php.ini file (it may not exist in which case just sudo cp /etc/php.ini.default /etc/php.ini) so that the mysql.default_socket = /tmp/mysql.sock (by default line 760) andmysqli.default_socket = /tmp/mysql.sock (by default line 795).
  3. Edit /etc/my.cnf adding the following lines:
    [mysqld]
    socket=/var/mysql/mysql.sock
    [client]
    socket=/var/mysql/mysql.sock

    This will tell MySQL to create its socket where Leopard’s default PHP is looking for it. Next, you also need to create the /var/mysql directory and sudo chown mysql /var/mysql it or MySQL won’t start since it wont be able to create the socket.
  4. Recompile php for your version of MySQL (a PIA, but not a terrible idea at all).

Of these #1 is easiest, but a bit of a hack. #2 is the easiest real way. #3 isn’t to bad, but could cause issues with other MySQL clients that look for the socket in /tmp/mysql.sock. #4 is ultimately the best fix, but is clearly neither very fast nor particularly easy

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值