MySQL is one of the most popular relational databases used in the world. It is an open-source project. MySQL is high performance and easy to use and it has become the database of choice for most web-based applications. Ranging from personal projects and websites to e-commerce and information services. Some of the greatest websites in the world including Facebook, Twitter, YouTube, Yahoo! use it. Doprax makes the use of MySQL database server even easier! You don't have to install anything. This document will help you start using MySQL in your project with ease.
Add MySQL service
Doprax uses the official image of MySQL provided by the Docker team. The complete MySQL official image documentation is accessible here. To get more information we suggest you read the official docs. You can customize the behavior of the image by using the environment variable. To use MySQL in your project you need to add it as a service to your project. In your project detail page got to the services sub-section and click on add service button. You will be directed to the add-services page. You will see all the services that are available to your project. Find MySQL and click add click on it.
Next, a dialog will appear and ask you to provide some information. You need to provide these values:
MYSQL_ROOT_PASSWORDis the root password of your MySQL server (Random password if left blank)
MYSQL_DATABASEis the name of the database we want to create. (db01 if left blank)
MYSQL_USERis a user that is created and will be assigned a super-user role for
MYSQL_DATABASEmentioned above (dbuser01 if left blank)
MYSQL_PASSWORDis the password for
MYSQL_USERmentioned above. (Random password if left blank)
If you do no enter any of the above values, a default value will be generated for it automatically. These values will be saved as environment variables and will be available to the MySQL instance at runtime. Click add button to add MySQL as a service to your project.
Now click the back button to go back to the services sub-section. You should see the MySQL service in this sub-section. It will look something like this:
The configuration values that we entered before are shown under the environment variables. MySQL needs to have at least the four configs that we have entered. You can change these values and also add others. The complete reference of the environment variables can be seen in official MySQL image documentation in the docker hub.
Mount a Volume on MySQL
To persist MySQL data, you need to mount a volume to
/var/lib/mysql/ path. Go to the volumes sub-section and click on the add volume button. Give it a title. Choose service: MySQL for the mount on option and for mount path enter
/var/lib/mysql/ and then click the create button.
Now a volume will be mounted on the MySQL service on
/var/lib/mysql/ and all data that will be saved to MySQL will persist. You can use File Browser, which is a volume plugin to view the content of this volume and also download the content of the volume in zip, gzip, and other formats. Check out the volumes section of the documentation for more information about volumes and File Browser.
MySQL will be accessible to the main source container and other services using hostname and port information. The default port of MySQL is 3306. The hostname of the MySQL (like every other service) is available on the services list below the service name as shown in the image below.
PhpMyAdmin is an open-source tool written in PHP and makes the administration of MySQL possible over the Web. Frequently used operations (managing databases, tables, columns, relations, indexes, users, permissions, etc) can be performed via the user interface, while you still have the ability to directly execute any SQL statement. To use PhpMyAdmin, you can click on its icon at the bottom of the MySQL service in the services list.
A button will appear shortly and by clicking on this icon, the phpMyAdmin login page will be opened in a new tab.
You can log in by providing the username and password of your MySQL instance. You can use root as username and the value of
MYSQL_ROOT_PASSWORD for the password, or you can use the value of
MYSQL_USER as the username and the value of the
MYSQL_PASSWORD for the password.
The PhpMyAdmin page looks like the image below. You can do every administration task using the PhpMyadmin interface. For more information, you can visit phpMyAdmin's official website.
You can mount a custom configuration file to your MySQL instance using the mount config files option. The default MySQL config file can be found in
/etc/mysql/my.cnf . If you want to add a config file, you can mount a file on
/etc/mysql/conf.d/config-file.cnf . When you start MySQL, it uses the combined startup settings from
/etc/mysql/conf.d/config-file.cnf, with settings from the latter taking precedence.