docker wordpress 连接数据库失败

将wordpress.tar.gz解压直/usr/local/nginx/html/下, 使用浏览器访问121.37.166.201:8081/wp-admin/install.php,输入数据库信息,报错:

问题排查步骤:

1、查看数据库IP地址

[root@master-1 ~]# docker inspect zabbix-mysql | grep "IPAddress"
            "SecondaryIPAddresses": null,
            "IPAddress": "",
                    "IPAddress": "172.17.201.1",

进入 /usr/local/nginx/html/wp_config.php配置文件,修改数据库信息:

/** WordPress数据库的名称 */
define('DB_NAME', 'wordpress');

/** MySQL数据库用户名 */
define('DB_USER', 'wordpress');

/** MySQL数据库密码 */
define('DB_PASSWORD', 'wordpress');

/** MySQL主机 */
define('DB_HOST', '172.17.0.1');

 重新在浏览器打开wordpress, 问题还是没有解决,依然提示数据库连接失败,,,

2、登录容器数据库,查看密码账号是否正确, -------没有报错信息,继续排查

[root@master-1 ~]# docker exec -it zabbix-mysql /bin/bash
root@0bffe1016a51:/# mysql -uwordpress -pwordpress
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 465
Server version: 8.0.28 MySQL Community Server - GPL

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

3、在宿主机登录数据库看是否登录成功 --------宿主机无法连接数据库容器

[root@master-1 ~]# mysql -h 121.37.166.201 -P 3306 -uwordpress -pwordpress
ERROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: The specified module could not be found.(this error comes when I try to lo...

   原因:此为8.0新版本的MySQL新特性导致,老版本里机密方式为mysql_native_password,导致认证方式有问题。

   解决方法: 登录容器数据库,修改加密方式

    1>进入数据库容器: docker exec -it zabbix-mysql /bin/bash

    2>登录数据库: mysql -uwordpress -pwordpress

    3>修改加密方式:alter user wordpress@'%' identified  with mysql_native_password by 'wordpress';

    4> 刷新: flush privileges;

    5> 退出数据库容器

重新打开wordpress 验证, 可以连到数据库,问题解决。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值