mysqli_connect(): (HY000/2002): Connection timed out on hosting

混江龙づ霸主 提交于 2019-11-28 09:39:53

问题


I am trying to connect mysql database using php. But it is running fine on local machine but not when hosted online and error appeared as mysqli_connect(): (HY000/2002): Connection timed out

<?php

$link = mysqli_connect('sql6.freesqldatabase.com','user_name','password','database_name');
if(mysqli_connect_error())
    die("couldn't connect to database");
?>

回答1:


Your MySQL server is probably not configured to accept requests from the host you're trying to access it from.

Check the configuration for the server. Since you say the local machine can access it check where you permitted this and do the same for the ip of the online host.




回答2:


If your website and MySQL database are hosted on separate servers, make sure that you've mentioned correct MySQL hostname (resolvable) in connection string.

In case you've specified the correct username, most probably your MySQL server isn't allowing remote MySQL connections from web server where you site resides. Contact your web hosting provider for the exact MySQL hostname and to allow your web server IP address for remote MySQL connections.




回答3:


In my case, AWS firewall was blocking my web server.

Adding the web servers IP address to the firewall exceptions fixed this for me.



来源:https://stackoverflow.com/questions/42051976/mysqli-connect-hy000-2002-connection-timed-out-on-hosting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!