Question
- How to add a MySQL server ran in a docker container as a remote database server?
- How to create a MySQL server running in a Plesk Docker extension container and add it as an external database server in Plesk?
Answer
- Log into your server via SSH
- Create the directory
/var/docker/mysqlby executing the following command:# mkdir -p /var/docker/mysql/
- Log into Plesk
- Go to Docker
- Type mysql in the search box
Note: The steps here are for a Docker container running MySQL version 8.3.0
- Press Run (local)
- Check the Automatic start after system reboot box
- Uncheck the Automatic port mapping box
- Uncheck a private port on the host, set external port 3306 to external port 3307 and internal port 33060 to external port 33070
Note:
Make sure ports 3307 and 33070 are open in all firewalls for your Plesk server's public IP address
- Set Volume mapping for Container to
/var/lib/mysqland to Host to/var/docker/mysqlWarning: Not mapping
/var/lib/mysqlto/var/docker/mysqlcreates risk of losing data on the container's recreation. Add
MYSQL_ROOT_PASSWORDas a new Environment variable (in order to set a new password for the root user of MySQL in this container) and enter a password that you would like to use as the Value:- Press OK
When the container starts, log into via the server SSH terminal and fix the issue outlined on this page: mysql - Authentication plugin 'caching_sha2_password' cannot be loaded - Stack Overflow
# docker exec -it mysql bash
# mysql -p
# mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOUR_MYSQL_SERVER_PASSWORD';
# mysql> exitAdd your MySQL Docker container as an external database in Plesk by using the information on the following page of the Plesk Obsidian documentation:
Note: Make sure you use the public IP of the server and the external port that you have used (3307 in this example)
If you are planning to use this DB server as Default, go to Tools & Settings > Database Servers > Settings > Default settings for remote access of database users, and make sure access from remote servers is allowed. (This server would be a remote DB server even though it is hosted on the same VM).