0

I have mysql running through the docker, i.e. when I run the docker ps command, I get this result:

CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS              PORTS                                         NAMES
fXX3aeXXcXXa        mysql:5.7.22           "docker-entrypoint.s…"   35 minutes ago      Up 18 minutes       0.0.0.0:3360->3306/tcp                        db

And here is my db service in my docker-compose.yml in my laravel root project:

# ... other services
db:
    image: mysql:5.7.22
    container_name: db
    restart: unless-stopped
    tty: true
    ports:
      - "3360:3306"
    environment:
      MYSQL_DATABASE: laravel_db
      MYSQL_USER: root
      MYSQL_PASSWORD: password
      MYSQL_ROOT_PASSWORD: password
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
    volumes:
      - dbdata:/var/lib/mysql
      - ./DockerDevelopment/mysql/my.cnf:/etc/mysql/my.cnf
    networks:
      - app-network
# other services ...

So, I try this command: docker exec -it db bash then goes to my dockerized db command line, and I get this error:

root@fXX3aeXXcXXa:/# mysql -u root -p [ENTER]
Enter password: password

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

what should I do to be able to access mysql> in my docker?

Majid Alaeinia
  • 962
  • 2
  • 11
  • 27
  • Try to server mysql server instance with skip-grant-tables option, then give to the user root, the right to connect from localhost. see https://stackoverflow.com/questions/41645309/mysql-error-access-denied-for-user-rootlocalhost – Jean-Charles LUC Dec 19 '19 at 13:02

2 Answers2

0

Maybe you have to check your my.cnf. Maybe you can provide your config.

With this compose file the connect to mysql works:

version: "3"
services:
  db:
    image: mysql:5.7.22
    container_name: dbvmssettlementiban
    restart: unless-stopped
    tty: true
    ports:
      - "3306:3306"
    environment:
      MYSQL_DATABASE: vms_settlement_iban
      MYSQL_USER: root
      MYSQL_PASSWORD: password
      MYSQL_ROOT_PASSWORD: password
      SERVICE_TAGS: dev
      SERVICE_NAME: mysql
Hannes
  • 491
  • 5
  • 21
-1

Let try:
mysql --protocol tcp --port=<your-mysql-port> -u root -p

OR

Add lines below to your my.cnf on client:
[client]
protocol=tcp

This works for my case.

Nightt
  • 392
  • 1
  • 4
  • 18