【问题标题】:Connection to database could not be established无法建立与数据库的连接
【发布时间】:2019-02-12 09:09:45
【问题描述】:

我在 Centos 6 上使用 cake 官方文档配置了 cakephp3。下面是 php 和 mysql 版本的详细信息,

php -v
PHP 5.6.40 (cli) (built: Jan 12 2019 09:19:57)

mysql
Server version: 5.7.25 MySQL Community Server

我按照以下文档进行配置: https://book.cakephp.org/3.0/en/quickstart.html

现在运行开发服务器时出现以下错误。

CakePHP 无法连接到数据库。 无法建立与数据库的连接:SQLSTATE[HY000] [2019] Can't initialize character set utf8mb4 (path: /usr/share/mysql/charsets/)

【问题讨论】:

  • 能否提供您的代码,以便我们审核并找出可能的错误?
  • 嗨@Gaurav,在您链接的站点示例中,表定义指定CHARSET=utf8mb4'encoding' => 'utf8mb4'。我建议您阅读有关 MySQL 字符集的信息。第一步,将“utf8mb4”更改为“utf8”。

标签: php mysql cakephp


【解决方案1】:

替换

<charset name = "utf8"> in /usr/share/mysql/charsets/Index.xml with <charset name = "utf8mb4">.

它对我有用。

【讨论】:

  • 最好不要替换,而是将更改添加为 yml 中的新条目
猜你喜欢
  • 1970-01-01
  • 2015-02-15
  • 1970-01-01
  • 1970-01-01
  • 2016-03-11
  • 1970-01-01
  • 1970-01-01
  • 2016-07-08
  • 1970-01-01
相关资源
最近更新 更多