php 如何允许 Windows Server 上的 MySQL 进行外部远程访问?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14295287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to allow MySQL on Windows Server for external remote access?
提问by sami_analyst
i have installed xampp on my windows server 2008 R2. I'm running a script there that stores me data over the day. Now i want to retrieve the data from my own computer or just external by connecting the database via mysql_connect("hostname","username","pw"). after some research i have got told that i have to commend
我已经在 Windows Server 2008 R2 上安装了 xampp。我正在那里运行一个脚本来存储我一天的数据。现在我想通过 mysql_connect("hostname","username","pw") 连接数据库从我自己的计算机或外部检索数据。经过一些研究,我被告知我必须表扬
> [...]
> #bind-address = 127.0.0.1
> #skip-networking
[...]
in /etc/mysql/my.cnf
在 /etc/mysql/my.cnf
didn't find the my.cf file in mysql but found one in xampp/mysql/bin/my.ini . But when i opened the file i found the lines even commented so hadn't got to change anything..... strange.
在 mysql 中没有找到 my.cf 文件,但在 xampp/mysql/bin/my.ini 中找到了一个。但是当我打开文件时,我发现这些行甚至注释了所以没有改变任何东西......奇怪。
then i got told to create a new user with the host setted %. So i did. now i tried to acces the database on my pc (xampp) but when i want to connect the database, i just get the error message, that the connection failured. Where is the mistake ?
然后我被告知要创建一个主机设置为 % 的新用户。所以我做了。现在我试图访问我的电脑(xampp)上的数据库,但是当我想连接数据库时,我只收到错误消息,连接失败。错在哪里?
thanks
谢谢
edit:
编辑:
thats howi exactly connect
这就是我完全连接的方式
$connection=mysql_connect("hostname","usrname","password")or die(mysql_error());
mysql_select_db("dbname")or die(mysql_error());
and the error message i get is german you can trabslate.
我得到的错误信息是德语,你可以翻译。
Warning: mysql_connect(): Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht richtig reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat. in C:\xampp\htdocs\tickerdata\get.php on line 4
警告: mysql_connect(): Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht richtig reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat。在 C:\xampp\htdocs\tickerdata\get.php 第 4 行
just means as much as connection failured because remote didnt react in certain time period or connection was faulty because host didnt react...
只是意味着连接失败,因为远程在特定时间段内没有反应或连接出现故障,因为主机没有反应......
回答by user20232359723568423357842364
If you can't connect to the server remotely, but you can connect locally, you either need to open port 3306 in the firewall, or grant the user permissions from the remote IP.
如果无法远程连接服务器,但可以本地连接,则要么需要在防火墙中打开3306端口,要么从远程IP授予用户权限。
The port should be opened in the windows firewall, as well as the router firewall. Your router will need to forward the port to the 2008R2 server.
该端口应在 windows 防火墙以及路由器防火墙中打开。您的路由器需要将端口转发到 2008R2 服务器。
To open ports in 2008R2 firewall:
在 2008R2 防火墙中打开端口:
To grant user permissions on IP:
要授予用户对 IP 的权限:
GRANT ALL ON foo.* TO bar@'255.255.255.255' IDENTIFIED BY 'PASSWORD';
Keep in mind that it is possible to have duplicate usernames in MySQL, and if you didn't create the new user with a UNIQUE username then you may be getting the privileges of the user jailed to localhost
请记住,在 MySQL 中可能有重复的用户名,如果您没有使用 UNIQUE 用户名创建新用户,那么您可能会获得被监禁到 localhost 的用户的权限

