in Mac OS X, I just created a fresh mysql container with:
docker run -d --name my_db -p 13306:3306 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=mydatabase -e MYSQL_USER=myuser -e MYSQL_PASSWORD=secret mysql:8
I want to access the command line interface like I would do with a local mysql, so I did:
$docker exec -it my_db mysql -uroot -p=root
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
$
I tried dozens of variants, using myuser as the user instead of root, asking chatgpt…just can’t figure out…
>Solution :
The mysql documentation states:
–password[=password], -p[password]
The password of the MySQL account used for connecting to the server. The password value is optional. If not given, mysql prompts for one. If given, there must be no space between –password= or -p and the password following it.
so you want:
$ docker exec -it my_db mysql -uroot -proot