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

标签 mysql wordpress database-migration

我已将 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/

相关文章:

mysql - 在mysql中插入两次之间的持续时间

Python编码与mysql

c# - Migratordotnet 创建初始迁移

mysql - 如何使用 SQL 删除给定表中的冗余记录

mysql - Sequelize : not able to login via localhost?

iphone - 设置 wordpress iOS 的教程

wordpress 高级自定义字段 google map api key

css - 当使用 AJAX 请求获取内容时,Gutenberg block 的内联样式不呈现

sql-server - 在 T-SQL 中划分日期值

postgresql - Dbup(.net 库)和 Powershell for Postgresql