在安装到ApacheVirtualHost文档根目录时,会出现数据库连接错误。为什么会发生这种事?

时间:2014-02-17 作者:cbalos

我已经安装了apache virtualhosts并确认其工作正常。我想为其中一个vhost安装wordpress,所以我解压缩了该vhost文档根目录中的所有wordpress文件。我继续按照WordPress安装说明进行操作。现在,我在转到安装时遇到数据库连接错误。php。我从phpMyAdmin创建了DB和WordPress用户。这是我的wp配置。php:

<?php
/**
 * The base configurations of the WordPress.
 *
 * This file has the following configurations: MySQL settings, Table Prefix,
 * Secret Keys, WordPress Language, and ABSPATH. You can find more information
 * by visiting {@link http://codex.wordpress.org/Editing_wp-config.php Editing
 * wp-config.php} Codex page. You can get the MySQL settings from your web host.
 *
 * This file is used by the wp-config.php creation script during the
 * installation. You don\'t have to use the web site, you can just copy this file
 * to "wp-config.php" and fill in the values.
 *
 * @package WordPress
 */

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define(\'DB_NAME\', \'notmyrealDBname\');

/** MySQL database username */
define(\'DB_USER\', \'l*******e\');

/** MySQL database password */
define(\'DB_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\', \'\');

/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define(\'AUTH_KEY\',         \'put your unique phrase here\');
define(\'SECURE_AUTH_KEY\',  \'put your unique phrase here\');
define(\'LOGGED_IN_KEY\',    \'put your unique phrase here\');
define(\'NONCE_KEY\',        \'put your unique phrase here\');
define(\'AUTH_SALT\',        \'put your unique phrase here\');
define(\'SECURE_AUTH_SALT\', \'put your unique phrase here\');
define(\'LOGGED_IN_SALT\',   \'put your unique phrase here\');
define(\'NONCE_SALT\',       \'put your unique phrase here\');

/**#@-*/

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = \'wp_\';

/**
 * WordPress Localized Language, defaults to English.
 *
 * Change this to localize WordPress. A corresponding MO file for the chosen
 * language must be installed to wp-content/languages. For example, install
 * de_DE.mo to wp-content/languages and set WPLANG to \'de_DE\' to enable German
 * language support.
 */
define(\'WPLANG\', \'\');

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 */
define(\'WP_DEBUG\', false);

/* That\'s all, stop editing! Happy blogging. */

/** 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\');
所以我是MySql新手,但我尽可能多地排除了故障。我使用SET为我的Wordpress DB用户创建了一个新密码。还是没有骰子。我确认mysql正在运行。我仔细检查了密码和拼写。我试图使用Wordpress DB用户登录mysql,但我得到了:

 ERROR 1045 (28000): Access denied for user \'l********e\'@\'localhost\' (using password: YES)
我想这可能是因为我的Wordpress DB用户没有全局权限,但我真的不知道,因为今天基本上是我使用mysql的第一天。

我唯一能想到的是,由于apache vhosts的原因,“localhost”不是正确的DB主机名,但每个人都说它仍然应该是正确的。哦,值得注意的是,在phpMyAdmin中,我的Wordpress用户在用户概述中的“主机”是“%”,直到我将其更改为“localhost”(在更改之前,我尝试将wp-config.php DB host设置为“%”。

还尝试在我的所有网站所在的/var/www/*中打开权限,但没有帮助。chown到www数据也没什么

更新我通过重新开始并通过命令行执行所有操作来修复它。但现在我想知道为什么会这样。

1 个回复
SO网友:Hasan

您也需要设置这些:

define(\'AUTH_KEY\',         \'put your unique phrase here\');
define(\'SECURE_AUTH_KEY\',  \'put your unique phrase here\');
define(\'LOGGED_IN_KEY\',    \'put your unique phrase here\');
define(\'NONCE_KEY\',        \'put your unique phrase here\');
define(\'AUTH_SALT\',        \'put your unique phrase here\');
define(\'SECURE_AUTH_SALT\', \'put your unique phrase here\');
define(\'LOGGED_IN_SALT\',   \'put your unique phrase here\');
define(\'NONCE_SALT\',       \'put your unique phrase here\');
请从此处生成并复制,然后再次检查:https://api.wordpress.org/secret-key/1.1/salt/

还要仔细检查数据库名称、用户名和密码是否正确。

结束

相关推荐

Accessing two databases

我的服务器上有两个数据库,我想知道有没有办法从wordpress访问这两个数据库?我的想法是将第二组凭据添加到wp-config.php.