How to allow MySQL on Windows Server for external

2019-05-10 19:23发布

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

> [...]
> #bind-address = 127.0.0.1
> #skip-networking 
  [...]

in /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.

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 ?

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

just means as much as connection failured because remote didnt react in certain time period or connection was faulty because host didnt react...

1条回答
贼婆χ
2楼-- · 2019-05-10 20:02

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.

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.

To open ports in 2008R2 firewall:

http://www.2x.com/blog/2010/04/tech/configuring-the-windows-server-2008-r2-firewall-to-open-ports-for-2x-solutions/

To grant user permissions on 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

查看更多
登录 后发表回答