从 Dreamhost 迁移到 HostGator 时出现 MySQL 问题

发布于 2024-11-14 00:15:38 字数 1971 浏览 9 评论 0原文

首先,我首先要说的是,该网站在 Dreamhost 上运行得非常好(除了上周出现了可怕的延迟和停机时间 - 但这并不是让我离开他们的原因,请阅读下文)。

我在 Dreamhost 上托管我的网站。由于收入托管所有者的问题,我不得不搬家(他不让我更改面板上的 dns 配置,也不会为我做)。 所以我与 HostGator 签约,现在我陷入了这个 MySQL 问题。这是我到目前为止所做的:

首先,我通过 ftp 将所有文件上传到 HostGator 服务器。然后,我从旧服务器导出数据库并将其导入新服务器。然后我在域名注册商上更改了名称服务器,最后,过了一会儿,在浏览器上按了F5。

然后出现了大量的错误行。所以我搜索了 HostGator 支持门户,发现我必须从这个(我之前使用的代码)更改

<?
date_default_timezone_set('America/Sao_paulo');

if ($_SERVER['HTTP_HOST']=='localhost') {
    $conexao = mysql_connect("localhost");
    $bd = mysql_select_db("tablename");     
} else {
    $conexao = mysql_connect("mysite.phpmyadmin.com","mylogin","mypassword");
    $bd = mysql_select_db("mydatabasename");
}
mysql_query("SET time_zone='-3:00'");
?>

为这样:

<?
define('DB_NAME', 'mydatabasename');
define('DB_USER', 'mylogin');
define('DB_PASSWORD', 'mypassword');
define('DB_HOST', 'localhost');
?>

问题是我不是 PHP 或 MySQL 专家。程序员让我没有支持,所以我只能靠自己了。

当我尝试加载我的网站时,出现以下错误:

Warning: mysql_query() [function.mysql-query]: Access denied for user 'mylogin'@'localhost' (using password: NO) in /home/mylogin/public_html/index.php on line 42

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/mylogin/public_html/index.php on line 42

ERROR 40 >Access denied for user 'mylogin'@'localhost' (using password: NO)

在文件 index.php 上,第 42 行是这样的:

$sqlo = mysql_query("select *, max-buyers as left from offers inner join rel_city on rel_city.id_offer = offers.id  where id_city=$city and startdate <= now() and enddate >= now() order by  priority desc, left desc, enddate asc") or die("ERROR 40 >".mysql_error());

一个重要的细节是我需要这两行才能与新托管一起使用,但每当我尝试插入它们时,它给出了新的错误:

date_default_timezone_set('America/Sao_paulo');
mysql_query("SET time_zone='-3:00'");

关于如何让它工作的任何想法?

First, let me start by saying the website was working perfectly well on Dreamhost (except for the last week with horrible lags and downtime - but it was not what made me move away from them, read below).

I was hosting my website on Dreamhost. I had to move due to a problem with the owner of the revenue hosting (he'd not let me change a dns config on the panel nor would do it for me).
So I signed with HostGator, and now I'm stuck with this MySQL issue. Here's what I've done so far:

First, I uploaded all the files via ftp to the HostGator server. Then, I exported the database from the old server and imported it onto the new one. Then I changed the name server on the domain registrar, and finally, after a while, hit F5 on the browser.

And then there was a huge ammount of error lines. So I searched the HostGator Support Portal and found out that I had to change from this (the code I was using before):

<?
date_default_timezone_set('America/Sao_paulo');

if ($_SERVER['HTTP_HOST']=='localhost') {
    $conexao = mysql_connect("localhost");
    $bd = mysql_select_db("tablename");     
} else {
    $conexao = mysql_connect("mysite.phpmyadmin.com","mylogin","mypassword");
    $bd = mysql_select_db("mydatabasename");
}
mysql_query("SET time_zone='-3:00'");
?>

To something like this:

<?
define('DB_NAME', 'mydatabasename');
define('DB_USER', 'mylogin');
define('DB_PASSWORD', 'mypassword');
define('DB_HOST', 'localhost');
?>

The thing is I'm no PHP or MySQL expert. The programmer let me without support, so I'm on my own.

When I try to load my site, it gives the following errors:

Warning: mysql_query() [function.mysql-query]: Access denied for user 'mylogin'@'localhost' (using password: NO) in /home/mylogin/public_html/index.php on line 42

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/mylogin/public_html/index.php on line 42

ERROR 40 >Access denied for user 'mylogin'@'localhost' (using password: NO)

On the file index.php, line 42 is this:

$sqlo = mysql_query("select *, max-buyers as left from offers inner join rel_city on rel_city.id_offer = offers.id  where id_city=$city and startdate <= now() and enddate >= now() order by  priority desc, left desc, enddate asc") or die("ERROR 40 >".mysql_error());

One important detail is that I need these two lines to work with the new hosting, but whenever I try to insert them, it gives new errors:

date_default_timezone_set('America/Sao_paulo');
mysql_query("SET time_zone='-3:00'");

Any ideas of how I can get this working?

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

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

发布评论

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

评论(4

洛阳烟雨空心柳 2024-11-21 00:15:38

试试这个:

<?
date_default_timezone_set('America/Sao_paulo');
$conexao = mysql_connect("localhost","mylogin","mypassword");
$bd = mysql_select_db("mydatabasename");
mysql_query("SET time_zone='-3:00'");
?>

我所做的是简化原始代码以删除 IF / ELSE 语句,该语句看起来可能是出于开发目的。

如果您遇到其他未发布的错误,请包含它们。

Try this:

<?
date_default_timezone_set('America/Sao_paulo');
$conexao = mysql_connect("localhost","mylogin","mypassword");
$bd = mysql_select_db("mydatabasename");
mysql_query("SET time_zone='-3:00'");
?>

What I've done is simplify the original code to remove the IF / ELSE statement which looks like it might be there for development purposes.

If you're getting other errors not posted, please include them.

以为你会在 2024-11-21 00:15:38

我不熟悉 HostGator 的设置,但问题似乎在于您尝试访问服务器的地址或凭据。

也许 HostGator 在用户名和数据库名称前面添加了前缀? (例如,也许应该是 some_mydatabasename 而不是简单的 mydatabasename)

或者他们的设置可能不支持使用 localhost 作为数据库地址;也许他们有一个定义的隔离地址供您连接。

我会向支持人员喊话,或者仔细检查 cPanel 设置中的地址、用户名和数据库名称。它可能会给你一个良好的开始。

(当然,此建议假设您的数据库用户名和密码正确,但错误表明情况并非如此。)

I'm not familiar with HostGator's setup, but what seems to be the issue is either the address or credentials you are trying to access the server with.

Perhaps HostGator prepends a prefix to usernames and database names? (ex. maybe it should be something_mydatabasename rather than simply mydatabasename)

Or perhaps their setup doesn't support using localhost as the database address; perhaps they have a defined and isolated address for you to connect to.

I'd give support a shout, or double-check the addresses, usernames, and database names in your cPanel settings. It may give you a good start.

(This advice is, of course, assuming that you have the username and password for the database correct, which the error suggests is not the case.)

多情癖 2024-11-21 00:15:38

从错误来看,您似乎没有在 MySQL 中设置数据库用户和密码。

From the errors, it looks like you don't have the DB user and password setup in MySQL.

苏别ゝ 2024-11-21 00:15:38

您的数据库有用户名和密码。确保您已正确指定它们,否则您将无法连接到数据库。

您看到的错误消息是由于您的程序员使用了 PHP die() 函数,这并不是一个好的做法。

请与您的主机核实,并确保您也拥有表的权限。你应该这样做,但你永远不知道。

Your database has a username and password. Make sure that you have specified them correctly, or you won't be able to connect to your database.

The error messages you're seeing are due to your programmer using the PHP die() function, which isn't really good practice.

Check with your host and make sure that you have permissions on your tables, as well. You should, but you never know.

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