From powershell console, I manage to run mysql command inside my mysql docker:
docker exec mysql-container mysql -u root -psecret -e 'show databases;'
But if I want to replace my password by MYSQL_ROOT_PASSWORD, it doesn't work anymore:
docker exec mysql-container mysql -u root -p$MYSQL_ROOT_PASSWORD -e 'show databases;'
# ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
It seems powershell interprets $MYSQL_ROOT_PASSWORD and pass it as empty to the container.
Other commands I tried:
docker exec mysql-container sh -c "mysql -u root -p$MYSQL_ROOT_PASSWORD -e 'show databases;'"
# Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
docker exec mysql-container sh -c 'mysql -u root -p$MYSQL_ROOT_PASSWORD -e "show databases;"'
# ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
"`". serverfault.com/questions/47811/…