无法在Mac上连接到MySQL-缺少mysql.sock文件 [英] Can't connect to MySQL on Mac -- missing mysql.sock file

查看:998
本文介绍了无法在Mac上连接到MySQL-缺少mysql.sock文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大约一周前,我在Mac OS 10.6上安装了MySQL,经过反复试验后,它可以正常工作.它与python MySQLdb集成在一起,我也让Sequel Pro连接到数据库.但是,php无法访问服务器.即使在我将php.ini文件添加到/etc/之后,也将其定向到Sequel Pro正在使用的同一袜子上:/tmp/mysql.sock.

I installed MySQL on my Mac OS 10.6 about a week ago, and, after some playing around, got it to work just fine. It integrated with python MySQLdb and I also got Sequel Pro to connect to the database. However, php wouldn't access the server. Even after I added a php.ini file to /etc/ and directed it toward the same sock that Sequel Pro was using: /tmp/mysql.sock.

但是现在我根本无法访问本地服务器.据我所知,在我的计算机上的任何地方都没有mysql.sock文件,在/tmp/或其他任何地方都没有.

But now I can't access the local server at all. As far as I can tell, there is no mysql.sock file anywhere on my computer, not in /tmp/ or anywhere else.

我可以从终端启动mysql服务器,但是一分钟后它会自动注销我:

I can start the mysql server from Terminal, but it logs me out automatically after a minute:

110425 17:36:18 mysqld_safe Logging to '/usr/local/mysql/data/dn0a208bf7.sunet.err'.
110425 17:36:18 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
110425 17:37:58 mysqld_safe mysqld from pid file /usr/local/mysql/data/dn0a208bf7.sunet.pid ended

如果我尝试从命令行调用"mysql"(今天早些时候运行良好):

If I try to call "mysql" from the command line (which worked perfectly earlier today):

ERROR 2002 (HY000): Can\'t connect to local MySQL server through socket '/tmp/mysql.sock' (2)

PHP错误当然是类似的:

The PHP error is of course similar:

PHP Warning:  mysql_real_escape_string(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock)

此外,我的mysql安装目录中没有"my.cnf"文件:/usr/local/mysql. XAMPP附带有用于mysql安装的my.cnf文件.那些也有默认的套接字列为"/tmp/mysql.sock",但是我不得不手动更改它们.

Also, there is no "my.cnf" file in my mysql installation directory: /usr/local/mysql. There are my.cnf files for the mysql installations that come along with XAMPP. Those also have the default socket listed as '/tmp/mysql.sock', but I had to change them manually.

有什么想法吗?为什么修改php.ini文件也会对Sequel Pro产生变化?

Any ideas what's going on? Why would modifying the php.ini file have produced a change for Sequel Pro as well?

推荐答案

首先,我建议您使用自制软件在Mac上安装任何第三方库或工具.看看: http://mxcl.github.com/homebrew/

First of all I suggest you to use homebrew to install any third part libraries or tools on your mac. Have a look to : http://mxcl.github.com/homebrew/

否则,对于您的问题,您可以搜索Mac上的mysql套接字在哪里,然后将其符号链接到/tmp.

Otherwise for your problem you can search where is the mysql socket on your mac and then symlink it to /tmp.

在您的终端中尝试类似:

In your terminal try something like :

locate mysql | grep sock

您会得到类似的东西:

/the/path/to/mysql.sock

然后做:

ln -s /the/path/to/mysql.sock /tmp/mysql.sock

这应该可行.

您还可以编辑php.ini文件以设置mysql套接字的正确路径.

Also you can edit your php.ini file to set the correct path for the mysql socket.

希望获得帮助.

这篇关于无法在Mac上连接到MySQL-缺少mysql.sock文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆