从本地主机连接到在线 MySQL 数据库 [英] Connecting to online MySQL database from localhost

查看:81
本文介绍了从本地主机连接到在线 MySQL 数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 php 从本地主机联机连接到 MySQL 数据库?

How can I connect to MySQL database online from localhost using php?

我已经通读了所有我能想到的东西,但无济于事.我通读了从本地主机连接到在线 MySQL 数据库从本地主机连接服务器数据库, 从本地主机连接到服务器数据库 还有一些,但都没有帮助.

I have read through all I could laid my hands on but to no avail. I read through Connect to an online MySQL database from localhost, Connect to server database from localhost, Connect to server database from localhost and some as well but none of them helped.

我试过了

$dbhost = 'infonetemonitor.com'; //$db['host'];
$dbuser = '****';//$db['user'];
$dbpass = '****';//$db['pass'];
$dbname = 'info1_quiz';//$db['dbname'];

//Mysqli
$mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if (mysqli_connect_errno()) {
    printf("MySQLi connection failed: ", mysqli_connect_error());
    exit();
}

但是产生了这个错误:

警告: mysqli::mysqli(): (HY000/1045): 用户访问被拒绝'info1_senetorial'@'41.58.56.26'(使用密码:YES)在C:\wamp64\www\COSTMI\includes\liveconnect.php 第 10 行

Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'info1_senetorial'@'41.58.56.26' (using password: YES) in C:\wamp64\www\COSTMI\includes\liveconnect.php on line 10

我认为可能是因为我没有向远程 MySQL 添加 ip,所以我添加了但仍然没有任何变化.

I thought it could be due to the fact that I didn't add an ip to Remote MySQL so I did but still nothing change.

在数据库中,我尝试授予权限

In the database, I tried to grant privileges

GRANT ALL PRIVILEGES ON info1_quiz.* TO 'info1_senetorial'@'41.58.56.26' WITH GRANT OPTION;

但是显示了这个错误:

MySQL 说:

我该怎么办?

推荐答案

尝试用主机 IP 地址替换主机名并再次检查.这应该允许您连接到数据库.如果你想用域名连接,那么你应该配置 MySQL 来理解与 apache.conf 文件中关联的域名.

Try to replace the host name with the Host IP address and check again. this should allow you to connect to the DB. If you want to connect with the domain name then you should configure MySQL to understand with the domain name associated in the apache.conf file.

这篇关于从本地主机连接到在线 MySQL 数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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