mysql数据库无法与cpanel连接

发布于 2024-12-16 22:03:58 字数 538 浏览 0 评论 0原文

我通过 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
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

最终幸福 2024-12-23 22:03:58

默认情况下,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.

等你爱我 2024-12-23 22:03:58

您应该提供正确的连接代码!

$con1 = mysql_connect("localhost:/tmp/mysql.sock","mysql_username","mysql_user_password");

我希望这应该/必须对你有用。享受!

You should give the correct connection code!

$con1 = mysql_connect("localhost:/tmp/mysql.sock","mysql_username","mysql_user_password");

I hope this should / must work for you. Enjoy!

那伤。 2024-12-23 22:03:58
Warning: mysql_connect() [function.mysql-connect]: 
php_network_getaddresses: getaddrinfo failed: No such host is known 

此错误消息表明 localhost 无法解析,因此“客户端”(您的 php 脚本)不知道将连接请求发送到哪里。

检查您的 DNS 设置或使用可访问 MySQL 服务器的 IP 地址。

Warning: mysql_connect() [function.mysql-connect]: 
php_network_getaddresses: getaddrinfo failed: No such host is known 

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.

糖粟与秋泊 2024-12-23 22:03:58

如果你尝试连接远程ip

  1. Mysql服务器需要接受远程连接
  2. Mysql用户需要有远程访问权限,

如果你没有其中1个它将无法工作。

if your trying to connect remote ip

  1. Mysql server need to accept remote connection
  2. Mysql user need to have remote access previlage

if you dont have 1 of them it wont work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文