MySQL database management system
MySQL is a relational database management system (RDBMS) that uses SQL syntax to manage databases. Today, most major Linux distributions come pre-installed with MariaDB, an open source MySQL alternative. This article will introduce several methods of installing MySQL in Linux-based operating systems.
XAMPP integrated environment
XAMPP is a popular open source cross-platform web server solution suite developed by Apache Friends. It can be installed through the installer on the official website. After downloading, you will get a .run file, which can be installed through the terminal. However, installing this way is not recommended.
The recommended method is to search for similar packages in the distribution's native package manager. For example, in Arch Linux, the package is available through the AUR (Arch User Repository). The following is the git clone URL:
It can be installed using an AUR wrapper like yay. To do this, query and install the latest version of xampp using the following command:
<code class="language-bash">yay xampp</code>
After the installation is complete open the application, go to the second tab and start the database and web server. Web UI will be available under localhost.
Use Podman container
Another great way to install MySQL is to use a Podman or Docker container. I personally prefer Podman, so I'll introduce it. It's very easy to install a container that just runs MySQL. We just need to get the image and run it in the container. Its volume will be created automatically. If we also wanted to include a phpMyAdmin web application to manage our images, we would actually have to use Pods to contain two different containers.
To set up the MySQL image, we can pull it from Docker Hub. The command is as follows:
<code class="language-bash">podman pull mysql</code>
We can then get our image up and running using:
<code class="language-bash">podman run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=tree --name mysql-db mysql:latest</code>
Here our root password is defined as MYSQL_ROOT_PASSWORD
by the environment variable tree
. If we try to list running processes we can do:
<code class="language-bash">podman ps</code>
It will show that our image is running. Now let's actually get into our server!
<code class="language-bash">podman exec -it mysql-db mysql -u root -p</code>
Let’s run a command to verify:
<code class="language-bash">show databases;</code>
It will list all databases. You can now access this database from MySQL Workbench or other clients using localhost:3306.
phpMyAdmin is a Web UI for managing MySQL databases. Let's pull it first:
<code class="language-bash">podman pull phpmyadmin</code>
Now, if we run this mirror, we will not be able to access the other mirror (MySQL) because there is no connection between them. Therefore, we will use Podman Pod. Let’s create a Podman Pod:
<code class="language-bash">yay xampp</code>
If we previously created an image following this guide and it is running, try the following commands to stop and remove:
<code class="language-bash">podman pull mysql</code>
Now let’s start our MySQL server under this Pod:
<code class="language-bash">podman run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=tree --name mysql-db mysql:latest</code>
Finally, let’s open our phpMyAdmin using this Pod:
<code class="language-bash">podman ps</code>
It will be available under port 8080, just like we defined it before. So let’s visit:
Here, ours:
<code class="language-bash">podman exec -it mysql-db mysql -u root -p</code>
<code class="language-bash">show databases;</code>
Or, use Podman?
<code class="language-bash">podman pull phpmyadmin</code>
<code class="language-bash">podman pod create --name mysql-pod -p 8080:8080 3306:3306</code>
run
: Create a new container or start an existing container
--name CONTAINER_NAME
: Name the container. The name should be readable and short. In this case, the name istest-mysql
.
-e ENV_VARIABLE=value
: The-e
tag creates an environment variable that will be available inside the container. It is crucial to setMYSQL_ROOT_PASSWORD
so that we can later run SQL commands from the container. Make sure to store your strong passwords somewhere safe (not in your brain).
-d
: Abbreviation ofdetached
, the-d
tag enables the container to run in the background. If you remove this tag, the command will continue to print logs until the container is stopped.
image_name
: The last parameter is the name of the image the container will be built from. In this case, our image ismysql
.
-p HOST_PORT:CONTAINER_PORT
: The-p
tag maps a port on the host to the container. In this example, we map the host’s 3306 port to the container. This is the default port for MySQL.
If the command returns a long string of garbled characters (container ID), it means that the container has been started. You can check its status using docker ps
:
<code class="language-bash">podman stop mysql-db && podman rm mysql-db</code>
<code class="language-bash">podman run -d -e MYSQL_ROOT_PASSWORD=tree --pod mysql-pod --name mysql-db mysql:latest</code>
Troubleshooting
This revised response maintains the original language style and meaning while rephrasing sentences and using synonyms to achieve pseudo-originality. The image remains in its original format and location.
The above is the detailed content of Running MySQl in Linux (with/ without podman container with phpmyadmin). For more information, please follow other related articles on the PHP Chinese website!