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

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

问题描述

我正在尝试通过本地主机上的PHP连接到在线服务器上的MySQL数据库.

I am trying to connect to my MySQL database on my online server via PHP on my localhost.

$con = mysql_connect("$hostname", "$username", "$password");
if (!$con) {die('Could not connect: ' . mysql_error());}
mysql_select_db($databasename, $con);

当我将脚本上载到服务器时,它可以很好地连接到数据库.但是,当我在本地主机上加载脚本时,它将无法连接到在线数据库.我关闭了防火墙,以确保它没有阻止它.

When I upload the script to the server it connects to the database fine. However, when I load the script on my localhost it will not connect to the online database. I shut off my firewall to make sure it was not blocking it.

以上连接是否正确格式化才能执行此操作?还有其他建议吗?

Is the connection above formatted correctly to do this? Any other suggestions?

推荐答案

您的MySQL服务器需要在允许的主机中指定您的IP地址(或%作为通配符).

Your MySQL server needs to have your IP address (or % as wild card) specified in the allowed hosts.

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

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