【问题标题】:Error establishing a database connection: XAMPP WordPress建立数据库连接时出错:XAMPP WordPress
【发布时间】:2017-07-13 15:42:24
【问题描述】:

有很多关于此的文档,但我的故障排除失败了。我安装了适用于 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/,但收到错误“建立数据库连接时出错”

【问题讨论】:

  • 能否用单引号替换 WP、admin、darkall 之间的花引号,看看是否是问题所在?
  • 您好 Cyto,非常感谢您的回复。有效。显然,我的 Mac 键盘默认为我提供了这些花引号。如果可能的话,我应该改变它。非常感谢您及时回复/** 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 wordpress xampp


【解决方案1】:

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

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 也应该可以使用它。

【讨论】:

  • 那么,问题出在大引号上吗?
  • 是的大引号。它是固定的。干杯!
  • 刚才提到了我之前在本地开发过程中遇到的一个连接问题,我需要使用 127.0.0.1 而不是 localhost 作为 DB_HOST。
猜你喜欢
  • 2017-07-05
  • 2020-07-26
  • 2021-05-28
  • 1970-01-01
  • 2015-08-11
  • 2012-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多