Using Docker I get the error: "SQLSTATE[HY000] [2002] No such file or directory"

Asked
Active3 hr before
Viewed126 times

8 Answers

directorydockererrorusing
90%

Note, if I connect using 127.0.0.1 instead of localhost I get a slightly different error that says: SQLSTATE[HY000] [2002] Connection refused,I'm using Docker to create a container to test my web app built on PHP and MySQL on my Mac. My PHP app is built using Fat-Free Framework for MVC and routing. I have two Dockerfiles, one for MySQL and one for PHP. I've used test Docker applications successfully, so I believe my images are installed correctly.,From my research, I've tried connecting using both localhost and 127.0.0.1 since they're technically treated differently. It could also be something related to trying to talk via sockets instead of TCP. Ideally I would like a solution that I can bake into my Dockerfiles so I don't have to worry about remembering commands or how I did something.

The main part of the error:

Internal Server Error

SQLSTATE[HY000][2002] No such file or directory

[fatfree / lib / DB / SQL.php: 466] PDO - > __construct('mysql:host=127.0.0.1;port=3306;dbname=robohome', 'root', 'password', array(1002 => 'SET NAMES utf8;'))[fatfree / app / Controllers / Controller.php: 24] DB\ SQL - > __construct('mysql:host=127.0.0.1;port=3306;dbname=robohome', 'root', 'password')
load more v
88%

While trying to run bin/docker/pim-initialize.sh I receive this error:,The script continues to run, and then I receive another error:,The error raises while trying to create the PDO connection.,But as this is the first time I try to use Docker and Akeneo, I really don't know what to do to debug further.

Akeneo PIM requirements check:
09:52:34 ERROR     [console] Error thrown while running command "pim:installer:check-requirements --no-debug=1 --env=prod". Message: "SQLSTATE[HY000] [2002] No such file or directory" ["error" => PDOException { …},"command" => "pim:installer:check-requirements --no-debug=1 --env=prod","message" => "SQLSTATE[HY000] [2002] No such file or directory"] []

In PimRequirements.php line 250:
                                                    
  SQLSTATE[HY000] [2002] No such file or directory  
                                                    

pim:installer:check-requirements [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command>

The command terminated with an error code: 2002.
load more v
72%

I’m trying to install docker v5 but for some reason I can’t get access to the database or something.,I’m not really familiar with docker so probably I have something wrong in my docker-compose.yml file.,I tried that a few times but I can do it again. Maybe the last update changed anything. I’ll do that tomorrow. GN8,I haven’t seen this issue in the docker container. My suggestion would be to wipe out and start fresh

Test test result is:

    SQLSTATE[HY000][2002] No such file or directory

And docker logs:

server_1 | 10.0 .1 .4 - -[12 / Dec / 2020: 02: 03: 57 + 0000]
"POST /setup/check_db HTTP/1.1"
400 109 "http://192.168.200.10:8019/setup"

app_1 | 172.27 .0 .4 - 12 / Dec / 2020: 02: 03: 57 + 0000 "POST /index.php"
400
load more v
65%

I have a couple of basic unit tests which all run perfectly on localhost but when I try to run the workflow it fails when trying to migrate the test database with a “SQLSTATE[HY000] [2002] No such file or directory” error.,I’ve googled a bit and found many posts with this error but not many solutions; the one which suggested to apt-get mysql-client among some other tweaks (discuss[dot]circleci[dot]com/t/unable-to-connect-to-mysql-5-7-and-create-database/29941/6) sounded the most promising but unfortunately also failed with the same error.

version: 2.1
orbs:
   deploy: rollbar / deploy @1 .0 .1
jobs:
   build:
   docker:
   -image: joshrob / circleci - primary: latest
environment:
   APP_ENV: test
DATABASE_URL: "mysql://test:test@localhost:3306/test" -
   image: circleci / mysql: 5.7
environment:
   MYSQL_USER: test
MYSQL_PASSWORD: test
MYSQL_ROOT_PASSWORD: test
MYSQL_DATABASE: test
resource_class: small
working_directory: ~/var/www / html
environment:
   ROLLBAR_ENVIRONMENT: development
75%

I’m creating an app using docker and laravel. At the beginning everything was fine, I ran the migrations successfully. But at some point an error occured while migrating and trying one of the routes on Postman:,I have no idea of what went wrong, the connection to database failed all of a sudden. The credentials are right, I can enter the db container succesfully. I have tried php artisan config:clear and php artisan config:cache. Also I have tried to specify the socket path in database.php but nothing changed., laravel 8 don’t see picture,Did you find any solution yet? I have the exact same problem. I even tried to put the IP address of the mysql container as DB_HOST but still the same error

I’m creating an app using docker and laravel. At the beginning everything was fine, I ran the migrations successfully. But at some point an error occured while migrating and trying one of the routes on Postman:

 IlluminateDatabaseQueryException

 SQLSTATE[HY000][2002] No such file or directory(SQL: select * from information_schema.tables where table_schema = users and table_name = migrations and table_type = 'BASE TABLE')

 at vendor / laravel / framework / src / Illuminate / Database / Connection.php: 692
 688// If an exception occurs when attempting to run a query, we'll format the error
 689// message to include the bindings with SQL, which will make this exception a
 690// lot more helpful to the developer instead of just the database's errors.
 691catch (Exception $e) {
    ➜
    692throw new QueryException(
       693▕ $query, $this - > prepareBindings($bindings), $e 694▕);
    695▕
 }
 696▕
 }

 +
 33 vendor frames
 34 artisan: 37
 IlluminateFoundationConsoleKernel::handle(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
load more v
40%

Hi All, Please help. posted 3 days ago, but didnt got any ans.

Hi All, Please help. posted 3 days ago, but didnt got any ans.

version: '3.1'
services:
   drupal:
   image: drupal: 8
container_name: drupal_container
environment:
   DRUPAL_PROFILE: standard
DRUPAL_SITE_NAME: Drupal
DRUPAL_USER: user
DRUPAL_PASS: pass
DRUPAL_DBURL: mysql: //user:pass@database:3306/db
   #or mysql: //user:pass@mysql_container:3306/db tried with both
   links:
   -"mysql:mysql"
depends_on:
   -mysql
ports:
   -80: 80
restart: always
volumes:
   -/var/www / html / modules -
   /var/www / html / profiles -
   /var/www / html / themes -
   /var/www / html / sites
restart: always
mysql:
   image: mysql: 5.7
container_name: mysql_container
restart: always
environment:
   MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: db
MYSQL_USER: user
MYSQL_PASSWORD: pass
ports:
   -3306: 3306
expose:
   -3306
22%

I'm using Docker to create a container to test my web app built on PHP and MySQL on my Mac. My PHP app is built using Fat-Free Framework for MVC and routing. I have two Dockerfiles, one for MySQL and one for PHP. I've used test Docker applications successfully, so I believe my images are installed correctly.,The documentation for links in docker-compose files says,It doesn't hurt to check for common issues, like running out of disk space or old version of the application, first.,Note, if I connect using 127.0.0.1 instead of localhost I get a slightly different error that says: SQLSTATE[HY000] [2002] Connection refused

The main part of the error:

Internal Server Error

SQLSTATE[HY000][2002] No such file or directory

[fatfree / lib / DB / SQL.php: 466] PDO - > __construct('mysql:host=127.0.0.1;port=3306;dbname=robohome', 'root', 'password', array(1002 => 'SET NAMES utf8;'))[fatfree / app / Controllers / Controller.php: 24] DBSQL - > __construct('mysql:host=127.0.0.1;port=3306;dbname=robohome', 'root', 'password')

My PHP Dockerfile:

FROM php: 5.6 - apache

RUN docker - php - ext - install mysqli pdo pdo_mysql
RUN a2enmod rewrite

My MySQL Dockerfile:

FROM mysql: 5.7

ENV MYSQL_ROOT_PASSWORD password
ENV MYSQL_DATABASE robohome

COPY. / schema.sql / docker - entrypoint - initdb.d /

My Controller.php file where the error mentions line 24:

< ? php

namespace Controllers;

class Controller {
   protected $f3;
   protected $db;

   public
   function __construct() {
      $f3 = Base::instance();
      $this - > f3 = $f3;

      $mysqlServerName = $f3 - > get("MYSQL_SERVERNAME");
      $mysqlDatabseName = $f3 - > get("MYSQL_DBNAME");

      //$container = DIContainerBuilder::buildDevContainer(); <-Not used currently

      //Below is line 24 referred to in the error
      $db = new DBSQL(
         "mysql:host={$mysqlServerName};port=3306;dbname={$mysqlDatabseName}",
         $f3 - > get("MYSQL_USERNAME"),
         $f3 - > get("MYSQL_PASSWORD")
      );

      $this - > db = $db;
   }

Those MYSQL_* values are pulled from an .ini file:

MYSQL_SERVERNAME = "localhost" < -This is what I 've tried changing to 127.0.0.1
MYSQL_USERNAME = "root"
MYSQL_PASSWORD = "password"
MYSQL_DBNAME = "robohome"

My Docker compose file:

version: '2'

services:
   web:
   build: . / docker / php
ports:
   -80: 80
volumes:
   -.: /var/www / html /
   links:
   -db
db:
   build: . / docker / mysql
ports:
   -3306

I run this by doing docker-compose up --build -d. The output I can then get from docker ps is:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f35066a16586 robohomeweb_mysql "docker-entrypoint.sh"
3 minutes ago Up 2 seconds 0.0 .0 .0: 32777 - > 3306 / tcp robohomeweb_mysql_1
86 d34eb34583 robohomeweb_php "apache2-foreground"
3 minutes ago Up 2 seconds 0.0 .0 .0: 80 - > 80 / tcp robohomeweb_php_1
load more v
60%

As someone pointed out in the comments, the docker-compose file you provided is very relevant to your question.,The documentation for links in docker-compose files says,Containers for the linked service will be reachable at a hostname identical to the alias, or the service name if no alias was specified.,Put this ip-address into your config file instead of 127.0.0.1. Hope that it will help you!

As someone pointed out in the comments, the docker-compose file you provided is very relevant to your question.

The documentation for links in docker-compose files says

links
load more v

Other "directory-docker" queries related to "Using Docker I get the error: "SQLSTATE[HY000] [2002] No such file or directory""