Applicable to:
- Plesk for Linux
Question
How to install a MySQL database server in a Docker container hosted in Plesk?
Answer
-
Connect to your Plesk server via SSH.
-
Create directory
/var/docker/mysql
:# mkdir -p /var/docker/mysql/
-
Go to Docker extension.
Note: If Docker is not installed, get it from Extensions catalog.
-
Click Run Container and search for mysql.
-
Select required version and click Next. In this example, we are installing MySQL version 8.0.
-
Click Next. The image download will begin.
-
Once downloaded, configure the container:
-
Give it a recognizable name
-
Select Automatic start after system reboot
-
Uncheck Automatic port mapping
-
Uncheck Make the port inaccessible from the Internet for both port mappings
-
Point:
-
internal port 3306 to external port 3307
-
internal port 33060 to external port 33070
-
-
In Volume mapping field, point
/var/docker/mysql
(host) to/var/lib/mysql
(container).Note: Volume mapping is required to recover MySQL data if something happens to this Docker container.
-
In Environment variables section, click Add one more and add
MYSQL_ROOT_PASSWORD
to Variable and your root password to Value.Note: Keep default environment variables as-is.
-
-
Click Run.
-
Once container is started, go to Tools & Settings > Database Servers and click Add Database Server.
-
Fill in the fields:
-
Host name or IP address: 127.0.0.1
-
Port number: 3307
-
Username: root
-
Password: your_root_password
-
-
Click OK.
Additional Information
- To allow remote connections to this database server:
-
Go to Tools & Settings > Database Servers > localhost and tick the option Allow local MariaDB/MySQL server to accept external connections.
-
Access the MySQL server from a command-line interface:
Note: Replace mysql-8.0 with the name of your Docker container with MySQL server.
# docker exec -it mysql-8.0 bash
# mysql -p
-
Update the host for root user:
MYSQL_LIN: UPDATE mysql.user SET host='%' WHERE user='root';
MYSQL_LIN: FLUSH PRIVILEGES;
MYSQL_LIN: exit
-
Open ports 3307 and 33070 in Plesk firewall and other firewall systems, if you use any.
-
- To use this database server as default, go to Tools & Settings > Database Servers > 127.0.0.1 and tick the option Use this server as default for MySQL.
Comments
0 comments
Please sign in to leave a comment.