简体   繁体   English

无法打开与远程数据库的连接

[英]Can't open connection to remote database

I have php script running on XAMPP on my local PC and I want to access some databse other than one on my localhost. 我在本地PC上的XAMPP上运行了php脚本,我想访问一些数据库,而不是在本地主机上。 Even if I call script with my own IP address I can't connect to the database. 即使我使用自己的IP地址调用脚本,也无法连接到数据库。

PHP script looks like: PHP脚本如下所示:

<?php

$host = $_GET['host'];
$username = $_GET['username'];
$pass = $_GET['pass'];
$database = $_GET['database'];

$con = mysql_connect($host,$username,$pass);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("performance_schema", $con);
$zavrsni = "zavrsni";

$result = mysql_query("SELECT `OBJECT_NAME`,`COUNT_INSERT`,`AVG_TIMER_INSERT`,`COUNT_UPDATE`,`AVG_TIMER_UPDATE`,`COUNT_DELETE`,`AVG_TIMER_DELETE` FROM `table_io_waits_summary_by_table` where `OBJECT_SCHEMA` =\"".$database."\"");

while($row = mysql_fetch_assoc($result))
{
$output[]=$row;
}

print(json_encode($output));

mysql_close($con);


?>

I call this script as: 我将此脚本称为:

http://zavrsni.noip.me/dohvat.php?username=root&pass=ficko1&database=zavrsni&host=zavrsni.noip.me

And then I get error: 然后我得到错误:

Warning: mysql_connect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\xampp\htdocs\dohvat.php on line 8
Could not connect: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

I know that this is not the most secure way of connecting the database, but I'm new to PHP so don't judge the terrible code. 我知道这不是连接数据库的最安全方法,但是我是PHP新手,所以请不要判断糟糕的代码。

Your database is not open for connections from outside. 您的数据库未打开以进行外部连接。 Log in to the server on which the database resides, log in to your database as root and then enter: 登录到数据库所在的服务器,以root用户身份登录到数据库,然后输入:

USE zavrsni;
GRANT ALL PRIVILEGES ON * to root@% identified by 'ficko1';

or better 或更好

GRANT SELECT ON * to root@% identified by 'ficko1';

Please note that it global grants are highly unsure. 请注意,它的全球补助金非常不确定。 Learn how to use the privilege system and later grant only those privileges which are actually needed. 了解如何使用特权系统,以后再只授予那些实际需要的特权。

If this still does not work, your mysql server is not permitting connections from outside. 如果仍然无法使用,则说明您的mysql服务器不允许外部连接。 Have a look at http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html 看看http://www.cyberciti.biz/tips/how-do-i-enable-remote-access-to-mysql-database-server.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM