简体   繁体   English

从本地计算机连接到 GoDaddy 服务器数据库

[英]Connect to GoDaddy server database from localhost computer

I programmed a website in PHP that uses a MySQL Server through GoDaddy.我用 PHP 编写了一个网站,该网站通过 GoDaddy 使用 MySQL 服务器。 I have the same code saved on my local computer and sync it with the directory on GoDaddy through an app.我在本地计算机上保存了相同的代码,并通过应用程序将其与 GoDaddy 上的目录同步。 I also use XAMPP on my computer to test any changes I make to the website before I make the changes public.在公开更改之前,我还在计算机上使用 XAMPP 来测试我对网站所做的任何更改。 However, the localhost server is different and in no way connected with the cPanel GoDaddy server.但是, localhost服务器是不同的,并且与 cPanel GoDaddy 服务器没有任何连接。 Therefore, if something new is added to the database on the public server, I would have to因此,如果在公共服务器上的数据库中添加了一些新内容,我将不得不

  1. Download the sql file on the remote phpmyadmin下载远程phpmyadmin上的sql文件
  2. Upload this file on the localhost phpmyadmin在本地主机上上传这个文件 phpmyadmin

This is an inefficient process, so now I want to use PHP to connect to the GoDaddy server.这是一个低效的过程,所以现在我想使用PHP连接到GoDaddy服务器。 To do this, I put the IP Address given to me in the GoDaddy hosting page as the host parameter of the mysqli_connect() function.为此,我将提供给我的 IP 地址放在 GoDaddy 托管页面中作为mysqli_connect()函数的主机参数。

// Set the database access information as constants
define('DB_USER', 'libuc6kfb0jg');
define('DB_PASSWORD', 'MY PASSWORD');
define('DB_HOST', 'MY IP ADDRESS');
define('DB_NAME', 'firstborumdatabase');

This user has all privileges on both the remote and the localhost.该用户拥有远程和本地主机的所有权限。 On cPanel - Remote MySQL® I have added the IP Address of my computer's localhost server.cPanel - Remote MySQL® 上,我添加了计算机本地主机服务器的 IP 地址。

// Make the connection
$dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die('Could not connect to MySQL: ' . mysqli_connect_error());

When I put this code in, instead of having 'localhost' as my host, which connects to the local MySQL server of XAMPP, it gives the following error当我把这段代码放进去时,而不是将“localhost”作为我的主机,它连接到 XAMPP 的本地 MySQL 服务器,它给出了以下错误

Could not connect to MySQL: Access denied for user 'libuc6kfb0jg'@'[Sensitive Info]' (using password: YES)无法连接到 MySQL:用户 'libuc6kfb0jg'@'[敏感信息]' 的访问被拒绝(使用密码:是)

Since I know it is not a permissions problem, the next thing I did was use the PORT parameter.因为我知道这不是权限问题,所以我做的下一件事是使用 PORT 参数。 So, I added 3306 to the end to no avail, for it gave me the same error.所以,我在最后添加了 3306 无济于事,因为它给了我同样的错误。 Lastly, I put in this code as a mysql command into the mysql client from the XAMPP Control Panel, and this gave me the same exact error.最后,我将此代码作为mysql命令从 XAMPP 控制面板放入 mysql 客户端,这给了我完全相同的错误。

Stack Overflow Research堆栈溢出研究

Any help would be greatly appreciated.任何帮助将不胜感激。


Edit编辑

I found a flaw: In cPanel, Remote MySQL Database, I added the IP Address that my localhost server is, not my computer's IP Address, if that makes sense.我发现了一个缺陷:在 cPanel,远程 MySQL 数据库中,如果有意义的话,我添加了我的本地主机服务器的 IP 地址,而不是我计算机的 IP 地址。 I am now changing the IP Address that I had added in this tool.我现在正在更改我在此工具中添加的 IP 地址。

While giving the user all permissions is crucial for it to have the necessary access to your database that only affects the ability for him to manipulate the database.虽然授予用户所有权限对于它拥有对您的数据库的必要访问权限至关重要,但这只会影响他操作数据库的能力。 You need to also whitelist your computers IP with the Servers firewall or you will not be allowed to connect to the remote server.您还需要使用服务器防火墙将您的计算机 IP 列入白名单,否则您将无法连接到远程服务器。

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

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