HY 我在设置中有一个 docker 容器,我得到一个错误,系统无法连接到数据库,我不知道这是怎么回事。
我尝试连接到本地主机、127.0.0.1 和 mysql,但出现相同的错误:
CakePHP 无法连接到数据库。无法建立与 Mysql 的连接:SQLSTATE[HY000] [2002] 没有这样的文件或目录
似乎无法在日志文件(apache 和 cake)中找到任何内容,我缺少什么?
PHP代码:
'default' => [
//'className' =>'Cake\Database\Connection',
'className' => Connection::class,
'driver' => Mysql::class,
//'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'timezone' => 'UTC',
'encoding' => 'utf8',
'host' => 'mysql',
'username' => 'myusername',
'password' => 'mypassword',
'database' => 'myadatabase',
'flags' => [],
'cacheMetadata' => true,
'log' => false,
'quoteIdentifiers' => false,
],
docker-compose.yml
#File version 2.1
version: "3"
services:
webserver:
build:
context: ./bin/webserver
container_name: '7.3.x-webserver'
restart: 'always'
ports:
- "${HOST_MACHINE_UNSECURE_HOST_PORT}:80"
- "${HOST_MACHINE_SECURE_HOST_PORT}:443"
links:
- mysql
volumes:
- ${DOCUMENT_ROOT-./www}:/var/www/html
- ${PHP_INI-./config/php/php.ini}:/usr/local/etc/php/php.ini
- ${VHOSTS_DIR-./config/vhosts}:/etc/apache2/sites-enabled
- ${LOG_DIR-./logs/apache2}:/var/log/apache2
mysql:
build:
context: "./bin/${DATABASE}"
container_name: '5.7-mysql'
restart: 'always'
ports:
- "${HOST_MACHINE_MYSQL_PORT}:3306"
volumes:
- ${MYSQL_DATA_DIR-./data/mysql}:/var/lib/mysql
- ${MYSQL_LOG_DIR-./logs/mysql}:/var/log/mysql
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: 'sc-phpmyadmin'
米脂
动漫人物