[英]“Connection refused” error when connecting to local MySQL server?
I am having this error:我有这个错误:
Warning: mysql_connect(): [2002] Connection refused (trying to connect via tcp://127.0.0.1:3306)
I saw a similar question and I tried the solution by changing localhost
to 127.0.0.1
, but it is still not working.我看到了一个类似的问题,我通过将
localhost
更改为127.0.0.1
来尝试解决方案,但它仍然无法正常工作。 I am using Mac OS X Lion.我正在使用 Mac OS X Lion。 Please any help would be appreciated
请任何帮助将不胜感激
This is the PHP code I use to connect:这是我用来连接的 PHP 代码:
<?php
require("constants.php");
// open database
$connect = mysql_connect(DB_SERVER,DB_USER,DB_PASS) or die('error connecting: ' . mysql_error());
// select database
mysql_select_db(DB_NAME) or die('error selecting db: ' . mysql_error());
?>
Try making sure your firewall if open to connections on port 3306.如果对端口 3306 上的连接开放,请尝试确保您的防火墙。
The command should be ipfw set enable 3306
, but if you want you can read more about actually setting the firewall permissions .该命令应该是
ipfw set enable 3306
,但如果您愿意,可以阅读更多关于实际设置防火墙权限的信息。
Another thing could be to make sure MySQL is listening on port 3306, edit the my.ini file and set另一件事可能是确保 MySQL 正在侦听端口 3306,编辑my.ini文件并设置
[client]
port=3306
And then restart MySQL.然后重启 MySQL。
I've had that problem before.我以前也遇到过这个问题。 You can fix it by commenting out "skip-networking" in the configuration.
您可以通过在配置中注释掉“skip-networking”来修复它。 (my.ini or my.cnf, it's /etc/mysql/my.cnf on Linux, not sure about Mac)
(my.ini 或 my.cnf,Linux 上是 /etc/mysql/my.cnf,Mac 不确定)
-- edit - 编辑
Also, you can try typing "netstat" in the Terminal, to make sure that mysql is listed there (should be something like 127.0.0.1:mysql or 127.0.0.1:3306).此外,您可以尝试在终端中键入“netstat”,以确保那里列出了 mysql(应该类似于 127.0.0.1:mysql 或 127.0.0.1:3306)。 If it is not listed, MySQL either hasn't started, or hasn't been able to bind.
如果未列出,则 MySQL 要么尚未启动,要么无法绑定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.