奇怪的MySQL Python mod_wsgi无法连接到'localhost'(49)问题的MySQL服务器 [英] Weird MySQL Python mod_wsgi Can't connect to MySQL server on 'localhost' (49) problem
问题描述
在StackOverflow上有类似的问题,但我没有发现完全相同的情况。这是在使用MySQL的OS X Leopard机器上
There have been similar questions on StackOverflow about this, but I haven't found quite the same situation. This is on a OS X Leopard machine using MySQL
一些开始信息:
MySQL Server version 5.1.30
Apache/2.2.13 (Unix)
Python 2.5.1
mod_wsgi 3
mysqladmin也有跳过网络列为OFF
mysqladmin also has skip-networking listed as OFF
我可以从python命令行连接到mysql 。但是当我尝试通过mod_wsgi使用复制和粘贴的代码,或通过Django我接收到通用连接拒绝
I am able to connect to mysql from the python command line. But when I try to do it through mod_wsgi using code that is copy and pasted or via Django I receive the generic connection refusal
OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (49)")
我查看了mysql手册,并尝试了其故障排除提示,如
I've looked at the mysql manual and tried its troubleshooting tips such as
telnet localhost 3306
,我 do 获取连接。
我是不尝试以root用户身份连接。
I am not trying to connect as root, either.
有什么想法可以检查吗?
提前感谢!
Any ideas on what else I could check? Thanks in advance!
推荐答案
我遇到这个错误,这是由于SELinux拒绝。 / usr / bin / httpd没有连接到端口3306的权限。我更正了以下问题:
I came across this error and it was due to an SELinux denial. /usr/bin/httpd didn't have permission to connect to port 3306. I corrected the issue with:
setsebool httpd_can_network_connect_db on
似乎工作得很好,应该比只禁用SELinux更安全。正如Avinash Meetoo指出的,您可以使用:
Seems to work great and should be more secure than just disabling SELinux. As Avinash Meetoo points out below, you can use:
setsebool -P httpd_can_network_connect_db
使selinux更改在重新启动之间保持不变。
To make the selinux change persist across reboots.
这篇关于奇怪的MySQL Python mod_wsgi无法连接到'localhost'(49)问题的MySQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!