I got a problem with mysql:5.7 with Docker. I know there are many questions about this but I just can't get this to work.
I simply want to create a mysql:5.7 container with docker-compose with the following settings on STARTUP!!:
My yml:
db:
build: "."
command:
- "--default-authentication-plugin=mysql_native_password"
ports:
- "3306:3306"
environment:
- MYSQL_ROOT_PASSWORD="mypw"
volumes:
- "./mysql/database:/var/lib/mysql"
What i tried:
I just don't get why especially allow access from everywhere is so hard to do.
Can anyone please help with where to put what?
Thanks
There is one more variable called MYSQL_ROOT_HOST. You need to set this variable to %.
So your docker-compose.yaml file will be:
$ cat docker-compose.yaml
version: "3"
networks:
net: {}
services:
db:
# build: "."
image: mysql:5.7
command:
- "--default-authentication-plugin=mysql_native_password"
ports:
- "3309:3306"
environment:
MYSQL_ROOT_PASSWORD: mypw
MYSQL_ROOT_HOST: "%"
# volumes:
# - "./mysql/database:/var/lib/mysql"
Then I am able to connect with command:
$ mysql -uroot -h127.0.0.1 -pmypw -P3309
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.32 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Your issue may be related to volume. Once your database is initialized with some credentials you have to stop container, remove data, then modify docker-compose.yaml and start your services again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With