建立数据库连接时出错:XAMPP WordPress

时间:2017-02-23 08:54:26

标签: mysql wordpress xampp

有很多关于此的文档,但我的故障排除失败了。我安装了适用于Windows的XAMPP,但工作正常,但它不能用于我的Mac OS Sierra。

我的XAMPP版本是5.6.30-0,我的服务器正在运行。

这是我的wp-config.php详情:

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

/** MySQL database username */
define('DB_USER', ‘admin’);

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

/** 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', '');

用户“admin”是我为phpMyAdmin中的“WP”数据库创建的新用户。 WP database exists in phpMyAdmin

我尝试转到http://localhost/wp/,但收到错误“错误建立数据库连接”“

1 个答案:

答案 0 :(得分:2)

我认为这个问题可能会出现两个问题:

1:在您的数据库名称,数据库用户名,数据库密码中添加花括号。将其替换为''单引号。

2:数据库用户名密码不匹配。重新检查数据库的用户名密码重置用户凭据,然后使用默认用户名' root '空密码如下所示:

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

/** MySQL database username */
define('DB_USER', ‘root’);

/** 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', '');

您还可以使用php db connection检查数据库凭据。创建一个名为conn.php的文件,并将以下代码添加到您的文件中:

<?php
$servername = "localhost";
$username = "admin";
$password = "darkall";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
?>

如果浏览器打印“已成功连接”,则wordpress也可以使用此功能。