最近在公司搭建了一套lnmp环境,遇到的一些问题,分享一下。
采用lnmp一键安装包(地址:https://lnmp.org/faq/lnmp-software-list.html)的形势,安装了最新的php7.4,mysql8.0 版本
坑一:mysql8.0
1、Authentication type: 用户的 Authentication type 默认为 caching_sha2_password,导致数据库连接错误,抛出如下异常: Illuminate\Database\QueryException : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client 解决方案:修改密码认证方式 ALTER USER 'YOURUSERNAME'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOURPASSWORD';
2、删除了 NO_AUTO_CREATE_USER 模式 在 5.7.* 的日志中提到已废除该模式,在 8.0.11 中删除了,迁移时会抛出如下异常: Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1231 Variable 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER'
解决方案:将 config/database.php 配置文件中 mysql 的 strict 的值改为 false 即可!
参考连接:https://learnku.com/articles/10736/some-craters-in-mysql-8011
坑二、php7.4中废弃了array_key_exists,可以用 property_exists,isset 函数代替