Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel Laradock-SQLSTATE[HY000][2002]连接被拒绝(SQL:select count(*)作为来自'users'的聚合,其中'email'=_Laravel_Laradock - Fatal编程技术网

Laravel Laradock-SQLSTATE[HY000][2002]连接被拒绝(SQL:select count(*)作为来自'users'的聚合,其中'email'=

Laravel Laradock-SQLSTATE[HY000][2002]连接被拒绝(SQL:select count(*)作为来自'users'的聚合,其中'email'=,laravel,laradock,Laravel,Laradock,在设置laradock后尝试迁移时,出现以下错误: 我在主文档之后设置了laradock,一切正常,但当我从浏览器创建新用户时,一切都不正常 Illuminate\Database\QueryException : SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known (SQL: select * from inform

在设置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 示例.env使用DB\u HOST=mysql跟踪主文档

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
### 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.env

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=cd_eloquent
DB_USERNAME=cristian
DB_PASSWORD=cristian
### 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;
}
DB_CONNECTION=mysql
DB_HOST=laradock_mysql
DB_PORT=3306
DB_DATABASE=cd_eloquent
DB_USERNAME=cristian
示例phpmyadmin

运行的容器示例

Docker compose ps

另一个例子

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;
}
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迁移:从docker环境(即..env)内部进行更新您必须使用容器名称引用数据库。有关列表,请参见
docker compose ps
。不要使用localhost。您重命名了容器吗?从屏幕截图上看,它似乎被称为
laradock\u mysql
,而不是
mysql
。我用您提供的示例更新了帖子,但它不起作用。