Joomla 安装 EasyBlog 插件后,博客页面报错无法打开

更新日期: 2024-07-10 阅读次数: 2088 字数: 501 分类: PHP

Joomla 迁移到新服务器后,EasyBlog 相关的页面,报 500 错误无法打开。但是非 EasyBlog 的页面,例如产品介绍相关的页面,是可以正常显示的。

报错信息

Variable 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER'

系统环境

  • MySQL 8.0.37
  • PHP 8.2

NO_AUTO_CREATE_USER 是什么

要解决问题,首先要明白问题是什么。如果不了解具体错误,很容易被网上的解决方案误导。

Previously, before NO_AUTO_CREATE_USER was deprecated, one reason not to enable it was that it was not replication safe. Now it can be enabled and replication-safe user management performed with CREATE USER IF NOT EXISTS, DROP USER IF EXISTS, and ALTER USER IF EXISTS rather than GRANT. These statements enable safe replication when replicas may have different grants than those on the source.

https://stackoverflow.com/questions/71110454/no-auto-create-user-in-mysql-8-0

The setting NO_AUTO_CREATE_USER does not exist anymore in 8.0.

处理方法

参考:

https://www.interactivetools.com/forum/forum-posts.php?MySQL-Error-Variable-sql_mode-can-t-be-set-to-the-value-of-NO_AUTO_CREATE_USER-82674

只需要把 sql_mode 中的 NO_AUTO_CREATE_USER 参数去掉即可。 但是,由于我是将 php 部署在 docker 镜像中。每次修改都去重新 build 镜像非常麻烦,而且耗时。我是能避开这种方式,尽量避开。

而之前在使用 Laravel 时,也遇到过这个问题。

MySQL 由 5.7 升级为 8.0 之后,Laravel 的配置改动

只需要修改一个 laravel 配置即可,即, strict 值修改成 false。并不需要全局修改 PHP 的配置。而,今天 Joomla 的问题,只出现在 EasyBlog 相关的页面,说明 Joomla 的全局配置应该是没问题的,问题只出在 EasyBlog 的代码上。

但是搜索 sql_mode 和 strict 都没有找到配置的地方,终于靠 NO_AUTO_CREATE_USER 搜索到:

grep NO_AUTO_CREATE_USER -r .
./administrator/components/com_easyblog/includes/utils.php: 'NO_AUTO_CREATE_USER',

注释掉 NO_AUTO_CREATE_USER 这行即可。

然后,joomla 相关的网页就能正常打开了。

干扰项

官方说明

https://docs.joomla.org/Joomla_and_MySQL_8

If you don't have access to your config file, you can update your user:

ALTER USER 'username'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

实际上,这个并不是今天问题的原因。

参考

  • https://stackoverflow.com/questions/71110454/no-auto-create-user-in-mysql-8-0

微信关注我哦 👍

大象工具微信公众号

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式

tags: joomla