0

I am trying to get access to mysql running on host from docker container.

On my server I am running mysql with version 5.7.39. I crated new mysql database and user and granted all privileges:

CREATE DATABASE strapi CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; 
CREATE USER 'strapi'@'localhost' IDENTIFIED BY 'password'; 
GRANT ALL PRIVILEGES ON strapi.* TO 'strapi'@'localhost';

I created my dockre-compose file with network_mode: host so that I could have access to mysql on host machine:

version: '3.8'
services:
  strapi:
    image: naskio/strapi
    environment:
      NODE_ENV: production
      DATABASE_CLIENT: mysql
      DATABASE_HOST: localhost
      DATABASE_PORT: 3306
      DATABASE_NAME: strapi
      DATABASE_USERNAME: strapi
      DATABASE_PASSWORD: 'password'
      DATABASE_SSL: 'false'
    volumes:
      - ./app:/srv/app
    network_mode: 'host'

However, it keeps generate error message that says "Access denied" in short

WARNING: The reu variable is not set. Defaulting to a blank string.
Recreating strapi_strapi_1 ... done
Attaching to strapi_strapi_1
strapi_1  | Starting your app...
strapi_1  | [2022-08-01T12:29:22.054Z] debug ⛔️ Server wasn't able to start properly.
strapi_1  | [2022-08-01T12:29:22.055Z] error Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'strapi'@'localhost' (using password: YES)
strapi_1  |     at Handshake.Sequence._packetToError (/srv/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
strapi_1  |     at Handshake.ErrorPacket (/srv/app/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
strapi_1  |     at Protocol._parsePacket (/srv/app/node_modules/mysql/lib/protocol/Protocol.js:291:23)
strapi_1  |     at Parser._parsePacket (/srv/app/node_modules/mysql/lib/protocol/Parser.js:433:10)
strapi_1  |     at Parser.write (/srv/app/node_modules/mysql/lib/protocol/Parser.js:43:10)
strapi_1  |     at Protocol.write (/srv/app/node_modules/mysql/lib/protocol/Protocol.js:38:16)
strapi_1  |     at Socket.<anonymous> (/srv/app/node_modules/mysql/lib/Connection.js:88:28)
strapi_1  |     at Socket.<anonymous> (/srv/app/node_modules/mysql/lib/Connection.js:526:10)
strapi_1  |     at Socket.emit (events.js:315:20)
strapi_1  |     at addChunk (internal/streams/readable.js:309:12)
strapi_1  |     at readableAddChunk (internal/streams/readable.js:284:9)
strapi_1  |     at Socket.Readable.push (internal/streams/readable.js:223:10)
strapi_1  |     at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
strapi_1  |     --------------------
strapi_1  |     at Protocol._enqueue (/srv/app/node_modules/mysql/lib/protocol/Protocol.js:144:48)
strapi_1  |     at Protocol.handshake (/srv/app/node_modules/mysql/lib/protocol/Protocol.js:51:23)
strapi_1  |     at Connection.connect (/srv/app/node_modules/mysql/lib/Connection.js:116:18)
strapi_1  |     at /srv/app/node_modules/knex/lib/dialects/mysql/index.js:68:18
strapi_1  |     at new Promise (<anonymous>)
strapi_1  |     at Client_MySQL.acquireRawConnection (/srv/app/node_modules/knex/lib/dialects/mysql/index.js:63:12)
strapi_1  |     at create (/srv/app/node_modules/knex/lib/client.js:290:39)
strapi_strapi_1 exited with code 1

To test if I have access directly from host executed successfully this command:

mysql --default-auth=mysql_native_password --host=localhost --user=strapi --password='password' strapi

I have no more idea what I can check to make it running.

I can also see in /var/log/mysql/error.log on host that:

2022-08-01T13:36:58.226683Z 5648 [Note] Access denied for user 'strapi'@'localhost' (using password: YES)

I have no idea why it wont work. Please help.

1 Answer 1

1

You might want to check this guide for Strapi v4 on Docker. It's recommended by Strapi. I've used it and I'm able to connect to MySQL database both from my machine and from Docker container.

You might also consider using newer version of MySQL.

Sign up to request clarification or add additional context in comments.

Comments

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.