Following is the code inside container for the sql:
mysql:
image: mariadb
command: --max_allowed_packet=32505856
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_USER=abc
- MYSQL_PASSWORD=xyz.123
- MYSQL_DATABASE=abc
- MYSQL_ALLOW_EMPTY_PASSWORD=true
restart: always
ports:
- 3306:3306
volumes:
# Using volume mount to mimic prod setup
- /tmp/mysql:/vol_mount/
I have been trying to access the database to view tables but have been unable to do so thus far.
I have tried running commands like:
docker exec -it container_name mysql -uabc -p
and then have tried bot 'root' and 'xyz.123' when prompted to enter password. But then I get an error like
"ERROR 1045 (28000): Access denied for user 'abc'@'2001:db8:1::a7' (using password: YES)"
I need to know the commands that will allow for me to access the DB and view tables. Thanks.
This will open your mysql console with user root:
docker exec -ti mariadb-test sh -c 'mysql -uroot -p${MYSQL_ROOT_PASSWORD}'
Please note that I named the container mariadb-test
in the compose file you can use a different name if you like.
Similarly you can connect with used abc
:
docker exec -ti mariadb-test sh -c 'mysql -uabc -p${MYSQL_PASSWORD}'
UPDATE:
Run the following to check the environment variables inside your container. They should match the values provided in the docker-compose.yml.
docker exec -ti mariadb-test sh -c 'env | grep MYSQL'
Since in my solution you don't even have to type the password, it should work anyway. Please try to start from a clean state: bring down all the containers, remove volumes and restart the services with this docker-compose file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.