Laradock - SQLSTATE[HY000] [2002] Connection refused (SQL: select count(*) as aggregate from `users` where `email` =
Laradock - SQLSTATE[HY000] [2002] Connection refused (SQL: select count(*) as aggregate from `users` where `email` =
设置 laradock 后尝试迁移时出现此错误:
我按照主文档设置了 laradock,一切正常,但当我从浏览器创建新用户时却没有。
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known (SQL: select * from information_schema.tables where table_schema = cd_eloquent and table_name = migrations and table_type = 'BASE TABLE')
at /Users/cristian/development/laravel/cd_eloquent/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
665| // If an exception occurs when attempting to run a query, we'll format the error
666| // message to include the bindings with SQL, which will make this exception a
667| // lot more helpful to the developer instead of just the database's errors.
668| catch (Exception $e) {
> 669| throw new QueryException(
670| $query, $this->prepareBindings($bindings), $e
671| );
672| }
673|
Exception trace:
1 PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known")
/Users/cristian/development/laravel/cd_eloquent/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=mysql;port=3306;dbname=cd_eloquent", "cristian", "cristian", [])
/Users/cristian/development/laravel/cd_eloquent/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
Please use the argument -v to see more details.
.env
使用 DB_HOST=mysql
的主文档示例 .env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=cd_eloquent
DB_USERNAME=cristian
DB_PASSWORD=cristian
如果我更改我的 .env
我更改 DB_HOST=127.0.0.1
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=cd_eloquent
DB_USERNAME=cristian
DB_PASSWORD=cristian
然后我得到所有的迁移
仅适用于 127.0.0.1 不适用于 mysql
cd_eloquent git:(master) ✗ php artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table (0.04 seconds)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table (0.05 seconds)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated: 2019_08_19_000000_create_failed_jobs_table (0.08 seconds)
当我尝试注册时,出现此错误
如果我更改我的 .env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=cd_eloquent
DB_USERNAME=cristian
DB_PASSWORD=cristian
我收到这个错误
这里有什么问题?
laradock.env
### MYSQL #################################################
MYSQL_VERSION=5.7
MYSQL_DATABASE=default
MYSQL_USER=default
MYSQL_PASSWORD=secret
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=root
MYSQL_ENTRYPOINT_INITDB=./mysql/docker-entrypoint-initdb.d
laradock 站点
站点示例
server {
listen 80;
listen [::]:80;
# For https
# listen 443 ssl;
# listen [::]:443 ssl ipv6only=on;
# ssl_certificate /etc/nginx/ssl/default.crt;
# ssl_certificate_key /etc/nginx/ssl/default.key;
server_name cd_eloquent.test;
root /var/www/cd_eloquent/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass php-upstream;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
location /.well-known/acme-challenge/ {
root /var/www/letsencrypt/;
log_not_found off;
}
error_log /var/log/nginx/laravel_error.log;
access_log /var/log/nginx/laravel_access.log;
}
示例 phpmyadmin
容器示例 运行
Docker-撰写ps
另一个例子
DB_CONNECTION=mysql
DB_HOST=laradock_mysql
DB_PORT=3306
DB_DATABASE=cd_eloquent
DB_USERNAME=cristian
只需从您的 laradock 工作区容器中重试 php artisan migrate:fresh
它就会起作用。
前任:
docker-compose exec workspace bash
php artisan migrate:fresh
有时您必须更改 .env
上的 DB_HOST 在我的情况下,IP 已更改,迁移 运行 在我的计算机上,但不是在具有另一个 IP 的容器中。
在 laradock 上,每个服务都有自己的容器,因此 localhost 或 127.0.0.1 指的是其中没有 mysql 的工作区容器,尝试:
DB_HOST=mysql
这将使用 Docker 的内部名称服务器映射正确的内部 IP 地址。
设置 laradock 后尝试迁移时出现此错误: 我按照主文档设置了 laradock,一切正常,但当我从浏览器创建新用户时却没有。
Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known (SQL: select * from information_schema.tables where table_schema = cd_eloquent and table_name = migrations and table_type = 'BASE TABLE')
at /Users/cristian/development/laravel/cd_eloquent/vendor/laravel/framework/src/Illuminate/Database/Connection.php:669
665| // If an exception occurs when attempting to run a query, we'll format the error
666| // message to include the bindings with SQL, which will make this exception a
667| // lot more helpful to the developer instead of just the database's errors.
668| catch (Exception $e) {
> 669| throw new QueryException(
670| $query, $this->prepareBindings($bindings), $e
671| );
672| }
673|
Exception trace:
1 PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known")
/Users/cristian/development/laravel/cd_eloquent/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
2 PDO::__construct("mysql:host=mysql;port=3306;dbname=cd_eloquent", "cristian", "cristian", [])
/Users/cristian/development/laravel/cd_eloquent/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70
Please use the argument -v to see more details.
.env 使用 DB_HOST=mysql
的主文档示例 .envDB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=cd_eloquent
DB_USERNAME=cristian
DB_PASSWORD=cristian
如果我更改我的 .env 我更改 DB_HOST=127.0.0.1
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=cd_eloquent
DB_USERNAME=cristian
DB_PASSWORD=cristian
然后我得到所有的迁移 仅适用于 127.0.0.1 不适用于 mysql
cd_eloquent git:(master) ✗ php artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table (0.04 seconds)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table (0.05 seconds)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated: 2019_08_19_000000_create_failed_jobs_table (0.08 seconds)
当我尝试注册时,出现此错误
如果我更改我的 .env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=cd_eloquent
DB_USERNAME=cristian
DB_PASSWORD=cristian
我收到这个错误
这里有什么问题?
laradock.env
### MYSQL #################################################
MYSQL_VERSION=5.7
MYSQL_DATABASE=default
MYSQL_USER=default
MYSQL_PASSWORD=secret
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=root
MYSQL_ENTRYPOINT_INITDB=./mysql/docker-entrypoint-initdb.d
laradock 站点
站点示例
server {
listen 80;
listen [::]:80;
# For https
# listen 443 ssl;
# listen [::]:443 ssl ipv6only=on;
# ssl_certificate /etc/nginx/ssl/default.crt;
# ssl_certificate_key /etc/nginx/ssl/default.key;
server_name cd_eloquent.test;
root /var/www/cd_eloquent/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_pass php-upstream;
fastcgi_index index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fixes timeouts
fastcgi_read_timeout 600;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
location /.well-known/acme-challenge/ {
root /var/www/letsencrypt/;
log_not_found off;
}
error_log /var/log/nginx/laravel_error.log;
access_log /var/log/nginx/laravel_access.log;
}
示例 phpmyadmin
容器示例 运行
Docker-撰写ps
另一个例子
DB_CONNECTION=mysql
DB_HOST=laradock_mysql
DB_PORT=3306
DB_DATABASE=cd_eloquent
DB_USERNAME=cristian
只需从您的 laradock 工作区容器中重试 php artisan migrate:fresh
它就会起作用。
前任:
docker-compose exec workspace bash
php artisan migrate:fresh
有时您必须更改 .env
上的 DB_HOST 在我的情况下,IP 已更改,迁移 运行 在我的计算机上,但不是在具有另一个 IP 的容器中。
在 laradock 上,每个服务都有自己的容器,因此 localhost 或 127.0.0.1 指的是其中没有 mysql 的工作区容器,尝试:
DB_HOST=mysql
这将使用 Docker 的内部名称服务器映射正确的内部 IP 地址。