Error establishing a database connection
来源:6-1 根据前面所学部署一个wordpress
Louis0o
2019-04-11
19年再用最新的wordpress和mysql版本,按本节课的步骤来操作,访问8080时会报:Error establishing a database connection?
[root@VM_32_232_centos docker-nginx]# docker run -d --name mysql -v mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -e
MYSQL_DATABASE=wordpress mysql
aeabc3324eede6b37e2edabfa50cf5e5f1af12a8458117389979694e140cc395
[root@VM_32_232_centos docker-nginx]# docker exec -it mysql /bin/sh
# env
HOSTNAME=aeabc3324eed
MYSQL_MAJOR=8.0
HOME=/root
MYSQL_ROOT_PASSWORD=root
TERM=xterm
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
MYSQL_VERSION=8.0.15-1debian9
GOSU_VERSION=1.7
PWD=/
MYSQL_DATABASE=wordpress
# exit
[root@VM_32_232_centos docker-nginx]# docker run -d -p 8080:80 -e WORDPRESS_DB_HOST=mysql:3306 --link mysql wordpress
89db9318f1fbcdabeca9083e190eff9b39220194a2cc7976248efe75bfca05f7
[root@VM_32_232_centos docker-nginx]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89db9318f1fb wordpress "docker-entrypoint.s…" 21 seconds ago Up 20 seconds 0.0.0.0:8080->80/tcp serene_chandrasekhar
aeabc3324eed mysql "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 3306/tcp, 33060/tcp mysql
[root@VM_32_232_centos docker-nginx]# docker exec -it 89db9318f1fb /bin/sh
# env
MYSQL_PORT_33060_TCP=tcp://172.17.0.2:33060
PHP_EXTRA_CONFIGURE_ARGS=--with-apxs2 --disable-cgi
APACHE_CONFDIR=/etc/apache2
HOSTNAME=89db9318f1fb
PHP_INI_DIR=/usr/local/etc/php
PHP_EXTRA_BUILD_DEPS=apache2-dev
HOME=/root
MYSQL_ENV_MYSQL_DATABASE=wordpress
PHP_LDFLAGS=-Wl,-O1 -Wl,--hash-style=both -pie
PHP_CFLAGS=-fstack-protector-strong -fpic -fpie -O2
PHP_MD5=
PHP_VERSION=7.2.17
WORDPRESS_SHA1=f1bff89cc360bf5ef7086594e8a9b68b4cbf2192
MYSQL_ENV_MYSQL_MAJOR=8.0
GPG_KEYS=1729F83938DA44E27BA0F4D3DBDB397470D12172 B1B44D8F021E4E2D6021E995DC9FF8D3EE5AF27F
PHP_CPPFLAGS=-fstack-protector-strong -fpic -fpie -O2
PHP_ASC_URL=https://www.php.net/get/php-7.2.17.tar.xz.asc/from/this/mirror
WORDPRESS_DB_HOST=mysql:3306
PHP_URL=https://www.php.net/get/php-7.2.17.tar.xz/from/this/mirror
TERM=xterm
MYSQL_PORT_3306_TCP_ADDR=172.17.0.2
MYSQL_ENV_MYSQL_ROOT_PASSWORD=root
WORDPRESS_VERSION=5.1.1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
MYSQL_ENV_GOSU_VERSION=1.7
MYSQL_PORT_3306_TCP_PORT=3306
MYSQL_PORT_3306_TCP_PROTO=tcp
MYSQL_PORT_33060_TCP_ADDR=172.17.0.2
MYSQL_PORT=tcp://172.17.0.2:3306
MYSQL_PORT_3306_TCP=tcp://172.17.0.2:3306
MYSQL_PORT_33060_TCP_PORT=33060
MYSQL_ENV_MYSQL_VERSION=8.0.15-1debian9
MYSQL_PORT_33060_TCP_PROTO=tcp
MYSQL_NAME=/serene_chandrasekhar/mysql
PHPIZE_DEPS=autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c
PWD=/var/www/html
PHP_SHA256=a3e5f51a9ae08813b3925bea3a4de02cd4906fcccf75646e267a213bb63bcf84
APACHE_ENVVARS=/etc/apache2/envvars
# exit
写回答
1回答
-
Louis0o
提问者
2019-04-11
docker run -d --name mysql -v mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=wordpress mysql:5.7
看到yml文件里的mysql是5.7版本的就尝试了一下,看最新版本的mysql可能配置的参数不一样。
老师,我的问题解决了。
20
相似问题