简体   繁体   English

连接到本地 MySQL 服务器时出现“连接被拒绝”错误?

[英]“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.

相关问题 在 XAMPP(MacOS)中使用 php 连接 MySQL 服务器的连接被拒绝 - Connection refused for connecting with MySQL server using php in XAMPP(MacOS) 错误 2002 连接在 PHP 上被拒绝连接到在 MAMP 上运行的 MySQL - Error 2002 Connection refused on PHP connecting to MySQL running on MAMP WAMP服务器错误:ERR_CONNECTION_REFUSED(本地Wordpress网站) - WAMP server Error: ERR_CONNECTION_REFUSED (local Wordpress site) 连接被拒绝,无法连接到 XAMPP 上的单独 MySQL - Connection refused, trouble connecting to separate MySQL on XAMPP 连接被拒绝 docker、laravel 和 mysql 服务器 - Connection refused docker, laravel and mysql server 卷曲错误:无法连接到 <url> 端口8444:连接被拒绝,只能在本地运行,但不能在服务器上运行 - Curl Error : Failed to connect to <url> port 8444: Connection refused, works in local but not in server 连接到本地数据库服务器时出错 - Error connecting to local db server 从 Web 服务器连接到远程 MySQL 数据库服务器时出错 - Error when connecting from a web server to a remote MySQL DB Server 连接到另一个运行MariaDB的Docker容器时,MYSQLI连接被拒绝 - MYSQLI Connection refused when connecting to another docker container running MariaDB 尝试发送IOS推送通知时出现错误“ 111连接被拒绝”(在我的本地环境中有效,但不在线) - Getting error “111 Connection refused” when try to send IOS push notification (works at my local environment but not online)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM