user2243747
user2243747

Reputation: 2967

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

I am new to docker and container world. Having trouble setting up mysql client on my local machine. I am referring to this tutorial.

My docker-compose.yml file looks like

version: "3.7"
services: 
  db:
    image: mysql
    container_name: "mySql-wordpress"
    restart: always   
    environment: 
      MYSQL_ROOT_PASSWORD: p@55w0rD@1234
    ports: 
      - "3306:3306"
    command: --default-authentication-plugin=mysql_native_password
    networks: 
      - back
  adminer:
    image: adminer
    restart: always
    ports:
      - 8282:8080
networks: 
  back:
volumes: 
  db_data:

No issue with that I was able to execute docker-compose up -d command successfully. Below is out put of docker ps command

 CONTAINER ID        IMAGE                   COMMAND                  CREATED             STATUS              PORTS
                                    NAMES
8ecd82867a06        mysql                   "docker-entrypoint.s…"   37 seconds ago      Up 34 seconds       0.0.0.0:3306->3306/tcp, 33060/tcp
                                    mySql-wordpress
ae01696e6445        adminer                 "entrypoint.sh docke…"   8 minutes ago       Up 7 seconds        0.0.0.0:8282->8080/tcp
                                    ae01696e6445_wordpressdemo_adminer_1
aa7e1055fc99        phpmyadmin/phpmyadmin   "/docker-entrypoint.…"   16 minutes ago      Up 16 minutes       0.0.0.0:8181->80/tcp
                                    wordpressdemo_phpmyadmin_1

Now when I try to login into Adminer portal I am getting error message

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

enter image description here

I also tried to install phpmyadmin/phpmyadmin Image but getting below error:

mysqli_real_connect(): The server requested authentication method unknown to the client [caching_sha2_password]

mysqli_real_connect(): (HY000/2054): The server requested authentication method unknown to the client

enter image description here

It looks like my SQL server is not setup properly. Any pointers?

UPDATE 1

With the image mysql:5.7 I can see below two error messages on phpMyAdmin

mysqli_real_connect(): php_network_getaddresses: getaddrinfo failed: Name or service not known

mysqli_real_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known

Upvotes: 7

Views: 10479

Answers (3)

Maknaka
Maknaka

Reputation: 79

In the docker-compose file in the Adminder service add lines

environment:
      ADMINER_DEFAULT_SERVER: db

ADMINER_DEFAULT_SERVER must be the same name as the service name for your database. In your case, it is 'db' When you go to localhost:8282, then Adminder should pull the server name automatically.

Upvotes: 3

rubo77
rubo77

Reputation: 20875

If you use docker and, like in your example, your database docker-container is called db then enter this as Server in the form:

System: Mysql
Server: db
Username: root
Password: ...
Database: ...

Upvotes: 12

micah94
micah94

Reputation: 424

I'm not familiar with docker, but I had this same No such file or directory error with adminer when I tried to login.

I fixed it by creating a custom php.ini file to tell PHP where MYSQL put its socket file. I had compiled PHP manually so I did not already have a php.ini. Check if you already have one.

In my case under Debian Linux, I found the socket file here /var/run/mysqld/mysqld.sock

So inside the php.ini file, added this:

mysqli.default_socket = "/var/run/mysqld/mysqld.sock"

Restart your PHP service.

Upvotes: 6

Related Questions