0

I can't connect my directus project with mysql server. Getting connection refused error.

However when I'm running this command, I'm able to connect: mysql -u root -p -h localhost -P 3306

My docker-compose.yml file:

version: '3'
services:
 directus:
  container_name: directus
  image: directus/directus:latest
  ports:
    - 8055:8055
  environment:
   KEY: 'KEY_VALUE'
   SECRET: 'SECRET_VALUE'
   DB_CLIENT: 'mysql'
   DB_HOST: 'localhost'
   DB_PORT: '3306'
   DB_DATABASE: 'directus'
   DB_USER: 'root'
   DB_PASSWORD: 'MYSQL_PASSWORD'
   MYSQL_ROOT_PASSWORD: 'MYSQL_PASSWORD'
   MYSQL_USER: 'root'
   MYSQL_PASSWORD: 'MYSQL_PASSWORD'
   MYSQL_DATABASE: 'directus'
   ADMIN_EMAIL: '[email protected]'
   ADMIN_PASSWORD: 'admin'
 networks:
  directus:

1 Answer 1

2

I actually faced the same issue and after terrible search finally I made the solution.

You can connect to mysql by using this modified code:

version: '3.8'
services:
 mysql:
  image: mysql:5.7
  container_name: mysql
  restart: always
  environment:
   MYSQL_ROOT_PASSWORD: 'MYSQL_PASSWORD'
   MYSQL_DATABASE: 'directus'
  ports:
   - "3306:3306"

 directus:
  image: directus/directus:latest
  container_name: directus
  restart: always
  ports:
   - "8055:8055"
  environment:
   KEY: 'KEY_VALUE'
   SECRET: 'SECRET_VALUE'
   DB_CLIENT: 'mysql'
   DB_HOST: 'mysql'
   DB_PORT: '3306'
   DB_DATABASE: 'directus'
   DB_USER: 'root'
   DB_PASSWORD: 'MYSQL_PASSWORD'
   ADMIN_EMAIL: '[email protected]'
   ADMIN_PASSWORD: 'admin'
  depends_on:
   - mysql

networks:
 default:
  name: directus_network
Sign up to request clarification or add additional context in comments.

2 Comments

You just shared your password, key and secret with the world. Please invalidate and change them ASAP.
the edit you made is still visible in the history...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.