No solution I found on stackoverflow works because, as noted below, I cannot even log into the MySQL container to update privileges.
I have a Laravel project in docker with a mysql database on an Ubuntu VPS. My docker.compose.yml file is set up as follows for mysql. With this setup I can access the mysql directly in Navicat app on Windows. However, this data does not persist once I "docker-compose down" the containers.
mysql:
image: mysql:8.0.33
container_name: mysql
ports:
- 3306:3306
environment:
MYSQL_DATABASE: dbasename
MYSQL_USER: dbaseuser
MYSQL_PASSWORD: dbasepwd
MYSQL_ROOT_PASSWORD: rootpwd
command: mysqld --sql_mode="ALLOW_INVALID_DATES,NO_ZERO_DATE"
networks:
- laravel
To attempt persistent data, when I add the following to the docker-compose.yml under mysql, I get "1130 host [my VPS ip address] not allowed to connect to this MySQL server" when trying Navicat remotely.
volumes:
- ./mysql:/var/lib/mysql
There is no firewall block (VPS port 3306 is set to allow any IP address).
I read about changing user privileges via
GRANT ALL PRIVILEGES ON database_name.* TO 'your_user'@'your_host' IDENTIFIED BY 'your_password';
However, I cannot even log into mySQL via CLI on my VPS - neither the username nor root with passwords as set in my docker-compose file are accepted. I have no way in!
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Please help.