无法通过(IP或域名)连接到MySQL服务器 [英] Can't connect to MySQL server on (ip or domain name)

查看:554
本文介绍了无法通过(IP或域名)连接到MySQL服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置Web服务器(Debian 7).我遵循了教程. 我要租用我的服务器,这要归功于gandi.net服务.我现在已经安装并运行了apache2,mysql,php5. 我在终端上使用以下命令连接到它:ssh username@domainname.com

I'm trying to configure a web server (Debian 7). I followed this tutorial. I'm renting my server thanks to gandi.net service. And i have now apache2, mysql, php5 up and running. I connect to it using following command on terminal : ssh username@domainname.com

下一步是通过sequel pro创建我的数据库,我不知道该怎么做,文档还不清楚... 这就是我在说的:

Next step is to create my database through sequel pro and I don't know how to do it and documentation is not so clear... Here is what I'm talking about :

我尝试连接:

  • Nom:有些名字,我发现很清楚. (我想我可以在这里放任何东西,对吗?)
  • 主机:IP或域名
  • 用户:我在ssh连接中使用的用户名(请参见上文)
  • 密码:我同时用于ssh连接(参见cf)和mysql连接的密码

对于其他情况,我照原样离开,并且收到了此错误消息:

For the rest, I left like it was and I received this error message :

无法连接到主机domainname.com,或者请求超时.

Unable to connect to host domainname.com, or the request timed out.

请确保地址正确并且您具有必需的特权,或者尝试增加连接超时(当前为10秒).

Be sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently 10 seconds).

MySQL说:无法连接到"domainename.com"(61)"(2)上的MySQL服务器

MySQL said: Can't connect to MySQL server on 'domainename.com' (61)' (2)

知道我该怎么做吗?

推荐答案

如果在Debian上正常安装MySQL,它将配置为阻止与数据库的外部连接.

If you do a normal install of MySQL on Debian, it will be configured to block external connections to the database.

这意味着您仍然需要告诉MySQL外部访问是可以的.为此,您需要更新MySQL的绑定地址.这是在my.cnf中配置的,在基于Debian的系统上,该文件位于/etc/mysql/my.cnf.

This means that you still need to tell MySQL that external access is OK. To do this, you need to update the bind address for MySQL. This is configured in my.cnf, which, on Debian based systems, is located in /etc/mysql/my.cnf.

在其中找到显示以下内容的部分

In there, find the section that says

[mysqld]

在那里,您必须确保

  • skip-networking行被注释(注释以'#'开头)或不存在,并且
  • 绑定地址设置为0.0.0.0(如果没有行绑定地址,则设置为该地址)或服务器的IP地址.
  • the line skip-networking is either commented (comments start with a '#') or not there, and
  • Bind-address is set to either 0.0.0.0 (which it is if there is no line bind-address) or to your server's IP-address.

这样做之后,您应该重新启动MySQL服务.然后,您需要创建一个允许远程访问的用户.这可以通过SQL查询来完成:

After doing this, you should restart your MySQL service. Then you need to create a user that is allowed remote access. This can be done with a SQL query:

GRANT ALL ON yourdatabase.* TO youruser@'*' IDENTIFIED BY 'yourpassword';

如果每次连接的IP地址都相同,则可以将星号切换为要连接的IP地址.

You can switch out the asterisk for the IP-address you will connect from, if it's the same every time.

最后,您需要在防火墙上打开端口3306(MySQL使用的端口).通常它不是必需的,因为它已经在大多数系统上打开了,但是可以使用以下iptables命令来完成.

Finally , you need to open port 3306 (the port MySQL uses) on your firewall. This usually isn't neccesary as it is already open on most systems, but it can be done using the following iptables command.

/sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 3306 -j ACCEPT
service iptables save

来源: 1

这篇关于无法通过(IP或域名)连接到MySQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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