gpt4 book ai didi

mysql - 站点迁移后建立数据库连接时出错?

转载 作者:行者123 更新时间:2023-11-29 18:35:34 25 4
gpt4 key购买 nike

我已将 WordPress 网站移至其他托管服务,并在打开该网站时收到以下错误消息:

Error establishing a database connection
This either means that the username and password information in your wp-
config.php file is incorrect or we can’t contact the database server at
localhost. This could mean your host’s database server is down.

Are you sure you have the correct username and password?
Are you sure that you have typed the correct hostname?
Are you sure that the database server is running?

当我尝试访问 sitedomain.com/wp-admin 时,我收到相同的消息

我导入了数据库,并在 cpanel 中创建了一个新用户并添加了所有权限并将该用户添加到数据库中。在 cpanel 中,我可以通过 phpMyAdmin 毫无问题地访问数据库。

我还可以使用新创建的用户名和密码(使用“sitedomain.com”作为网络地址)通过 MySQL Workbench 连接到数据库。

我的 config.php 文件:

<?php

define( 'WP_DEBUG', true );

define('DB_NAME', 'databaseName');

define('DB_USER', 'userName');

/* MySQL database password */
define('DB_PASSWORD', 'password');

/* MySQL hostname */
define('DB_HOST', 'localhost');

/* Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/* The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

/* WordPress Database Table prefix. */

$table_prefix = 'wp_';

define('WP_DEBUG', false);

/* Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');

/* Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');

其中databaseName是新创建的数据库的名称,userName是在cpanel中新创建的用户及其自己的密码

我尝试使用 ip 而不是 localhost,还尝试将 siteurl 切换为 http://www.sitedomain.com以及 http.sitedomain.com/dir 的主页,其中 dir 是 wordpress 目录。

我在主 WordPress 文件夹中创建了一个 testconnection.php 文件:

<?php
$link = mysql_connect('localhost', 'userName', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

其中 userNamepassword 再次是在 cpanel 中创建的新用户和密码,并以所有权限添加到数据库中。

导航到 sitedomain.com/dir/textconnection.php 显示以下内容:

Could not connect: Access denied for user 'userName'@'localhost' (using password: YES)

我是否忘记更改他们的其他配置详细信息?我该如何解决这个问题?

最佳答案

您的数据库是否在 localhost 上运行?

本地主机可能不在您的主机文件中。将 localhost 更改为 127.0.0.1 (假设它位于您的本地主机),或者更改为数据库计算机的 IP。

关于mysql - 站点迁移后建立数据库连接时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45336301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com