【发布时间】:2021-01-02 08:38:25
【问题描述】:
实际上我只是将我的数据库移动到 Docker 容器中。
这是我的 MySQL docker-compose 配置:
version: '3.1'
services:
db:
image: mysql:5.7
command: --default-authentication-plugin=mysql_native_password
restart: always
volumes:
- ./data:/var/lib/mysql
ports:
- 336:3306
environment:
MYSQL_ROOT_PASSWORD: password
WordPress 配置(非 Docker):
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );
/** MySQL database username */
define( 'DB_USER', 'root' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost:336' );
/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );
/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
我可以在主机上使用命令mysql -u root -P 336 -h localhost -p 连接到 MySQL,但 WordPress 显示:
警告:mysqli_real_connect(): (HY000/1698): 第 1626 行 /var/www/dev/wp-includes/wp-db.php 中用户 'root'@'localhost' 的访问被拒绝
Access denied for user 'root'@'localhost'
请帮忙,谢谢!
【问题讨论】:
-
如果将 mysql 端口 docker-compose 更改为
3306:3306和define( 'DB_HOST', 'localhost:3306' );,你会得到什么?
标签: php mysql wordpress docker