Table of Contents
Manjaro/Arch Linux has no smooth way to install MySQL server since they dropped support of it and replaced it with MariaDB. It is an excellent alternative of MySQL and works absolutely fine. But sometimes you just need MySQL server itself.
There is a AUR package for MySQL which — from my experience — doesn’t go well often 😏. It builds from source and I couldn’t do it after waiting an hour or so. The alternate easiest way to have MySQL in your system is installing it via docker. Let’s begin.
Install docker #
Installing docker on Manjaro is similar like installing any other standard packages.
sudo pacman -Syu sudo pacman -S docker
Next, you should enable docker service.
sudo systemctl start docker.service sudo systemctl enable docker.service
Create volumes #
These are storage for keeping your data. Let’s create two volumes, one for MySQL and another for phpMyAdmin.
docker volume create mysql-volume docker volume create phpmyadmin-volume
This will create a volume for the MySQL container.
If you want to remove a volume for some reason run:
docker volume rm <volume_name>
Creating/Running containers #
To create the MySQL container run:
docker run --name=mysql-8.0 -p3306:3306 -v mysql-volume:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d --restart unless-stopped mysql/mysql-server:8.0.29
Here we are using MySQL image version
--nameflag sets a name for the container.
-p3306:3306is telling it to bind host port 3306 to the container port 3306.
-vflag attaches the created volumes with the container.
-eflag sets a environment variable
MYSQL_ROOT_PASSWORDto set the root password which we will be using to login. The user name is
-dflag tells the container to run in detached mode, so that it keeps running even after the command is exited.
--restart unless-stoppedoption tells the container to keep running even when the computer restarts.
- Finally we provide the image name with the tag we want.
With the MySQL container created and running, let’s create the phpMyAdmin container:
docker run --name=phpmyadmin -v phpmyadmin-volume:/etc/phpmyadmin/config.user.inc.php --link mysql-8.0:db -p 8080:80 -d --restart unless-stopped -e UPLOAD_LIMIT=50M phpmyadmin/phpmyadmin
Here most of the flags are same. Except,
--linkflag tells it to link the MySQL container with phpMyAdmin.
UPLOAD_LIMITenvironment variable set the upload limit to 50 megabytes for phpMyAdmin.
Health check #
If both containers are successfully created, run following command to list out running containers:
To stop any container run:
docker stop <container_name_or_id>
And to start it:
docker start <container_name_or_id>
To delete a container:
docker rm <container_name>
Access and additional configuration #
To enter into a container run:
docker exec -it <container_name> bash
Now we need to change MySQL connection restriction so that our host machine can connect to it because by default MySQL disables this for security purpose. To do that, first enter into the MySQL container, then run:
mysql -u root -p
Then enter the password (in this
root) and we will land into MySQL console. Run:
update mysql.user set host = '%' where user='root';
Restart the containers and hit http://localhost:8080. You’ll see phpMyAdmin is waiting for you! 🗃️ You would only need to do all these steps only once, your containers will keep running unless stopped manually.