简体   繁体   English

从本地主机连接到在线MySQL数据库

[英]Connecting to online MySQL database from localhost

How can I connect to MySQL database online from localhost using php? 如何使用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. 我通读了从本地主机连接到在线MySQL数据库,从本地主机 连接到服务器数据库,从本地主机 连接到服务器数据库以及其他一些信息,但是它们都没有帮助。

I tried 我试过了

$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();
}

But this error was generated: 但是产生了这个错误:

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 警告:mysqli :: mysqli():(HY000 / 1045):在C:\\ wamp64 \\ www \\ COSTMI \\ includes \\ liveconnect.php中,对用户'info1_senetorial'@'41.58.56.26'(使用密码:是)的访问被拒绝第10行

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. 我认为这可能是由于我没有向远程MySQL添加IP,所以我做了,但是仍然没有任何变化。

In the database, I tried to grant privileges 在数据库中,我试图授予特权

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

but this error was displayed: 但显示此错误:

MySQL said: MySQL说:

1044 - Access denied for user 'infon10'@'localhost' to database 'mysql' 1044-拒绝用户'infon10'@'localhost'访问数据库'mysql'

How can I go about it? 我该怎么办呢?

Try to replace the host name with the Host IP address and check again. 尝试用主机IP地址替换主机名,然后再次检查。 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以理解与apache.conf文件中关联的域名。

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

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