mysql数据库无法与cpanel连接
我通过 cpanel 有 mysql 数据库,我想通过本地主机页面访问。
<?php
$con1 = mysql_connect("mywebsiteip","mysql_username","mysql_user_password");
if(!$con1)
{
die ("Could not connect " . mysql_error());
}
else
{
echo "Good connection";
}
mysql_close($con1);
?>
当我运行它时,它无法通过 cpanel 连接到 mysql 数据库。我什至尝试过
$con1 = mysql_connect("mywebsiteip:portnumber","mysql_username","mysql_user_password");
任何人都可以告诉我哪一个是好方法。下面是图像或错误
i have mysql database over cpanel, i want to access through my localhost page..
<?php
$con1 = mysql_connect("mywebsiteip","mysql_username","mysql_user_password");
if(!$con1)
{
die ("Could not connect " . mysql_error());
}
else
{
echo "Good connection";
}
mysql_close($con1);
?>
When i run it, it cannot connect to mysql database over cpanel. and i even tried up
$con1 = mysql_connect("mywebsiteip:portnumber","mysql_username","mysql_user_password");
Can any let me know, which one is good way. Below is the image or error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
默认情况下,cPanel 安装的 mysql 数据库仅允许来自本地主机的连接(即安装了 cpanel/mysql 的服务器)。要添加其他主机,请登录 cPanel 并转到“远程数据库访问主机”(根据版本的不同,其名称可能略有不同)。
您可以添加您的 IP 地址、主机名或
%
以允许来自任何计算机的连接。不过,指定%
存在很大的安全风险,因此请谨慎使用。仅供参考,这个问题确实属于 webmasters.stackexchange.com,因为它涉及管理而不是编程。
By default, cPanel-installed mysql databases only allow connections from the localhost (ie the server cpanel/mysql is installed on). To add other hosts, log in to cPanel and go to 'Remote Database Access Hosts' (this may be called something slightly different depending on version).
You can add your IP address, hostname or
%
to allow connections from any computer. However, specifying%
is a big security risk, so use it with caution.FYI, this question really belongs on webmasters.stackexchange.com, as it involves administration more than programming.
您应该提供正确的连接代码!
我希望这应该/必须对你有用。享受!
You should give the correct connection code!
I hope this should / must work for you. Enjoy!
此错误消息表明
localhost
无法解析,因此“客户端”(您的 php 脚本)不知道将连接请求发送到哪里。检查您的 DNS 设置或使用可访问 MySQL 服务器的 IP 地址。
This error messages suggests that
localhost
can't be resolved, therefore the "client" (your php script) doesn't know where to send the connect request to.Either check your DNS settings or use an IP adress instead, where your MySQL server is accessible.
如果你尝试连接远程ip
如果你没有其中1个它将无法工作。
if your trying to connect remote ip
if you dont have 1 of them it wont work.