运行报如下错误是因为docker安装的php-fpm是没有带pdo_mysql扩展的,需要自行安装
~~~
could not find driver
~~~
<span style='color:#009688;'>解决方法:</span>
~~~
#进入myphp容器,安装扩展
docker exec -it myphp /bin/bash
cd /usr/local/bin/
docker-php-ext-install pdo_mysql
#退出myphp容器,重启容器
Ctrl+p+q
docker restart myphp
docker restart mynginx
~~~
* * * * *
运行报如下错误是因为docker默认安装mysql是8.0以上最新版本,需要修改mysql密码验证规则
~~~
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
~~~
<span style='color:#009688;'>解决方法:</span>
~~~
#进入mysql容器
docker exec -it mysql /bin/bash
#登陆数据库
mysql -u root -p
use mysql;
#开启root远程访问权限
grant all on *.* to 'root'@'%';
#修改加密规则
alter user 'root'@'localhost' identified by '123456' password expire never;
#更新密码
alter user 'root'@'%' identified with mysql_native_password by '123456';
#刷新权限
flush privileges;
~~~
<span style='color:#FF5722;'>问题描述:</span>thinkphp连接mysql,报如下错误
~~~
QLSTATE[HY000] [2054] The server requested authentication method unknown to the client
~~~
<span style='color:#009688;'>解决方法:</span>首先参照[mysql8修改加密规则](https://www.kancloud.cn/fuhualiang/fuhualiang/664140),然后在mysql服务器配置文件的[mysqld]下面添加
~~~
default_authentication_plugin=mysql_native_password
~~~
<hr style="border:none;border-top:4px dotted #1E9FFF;">
<span style='color:#FF5722;'>问题描述:</span>thinkphp数据库配置'charset' =>'utf8mb4'连接mysql,报如下错误
~~~
SQLSTATE[HY000] [2054] Server sent charset unknown to the client. Please, report to the developers
~~~
<span style='color:#009688;'>解决方法:</span>在mysql服务器配置文件中[mysqld]的下面添加
~~~
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
~~~