Home > Database > Mysql Tutorial > Running MySQl in Linux (with/ without podman container with phpmyadmin)

Running MySQl in Linux (with/ without podman container with phpmyadmin)

Linda Hamilton
Release: 2025-01-22 22:18:13
Original
515 people have browsed it

Running MySQl in Linux (with/ without podman container with phpmyadmin)

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>
Copy after login
Copy after login

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.

MySQL Mirror

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

Let’s run a command to verify:

<code class="language-bash">show databases;</code>
Copy after login
Copy after login

It will list all databases. You can now access this database from MySQL Workbench or other clients using localhost:3306.

phpMyAdmin Mirror

phpMyAdmin is a Web UI for managing MySQL databases. Let's pull it first:

<code class="language-bash">podman pull phpmyadmin</code>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

Finally, let’s open our phpMyAdmin using this Pod:

<code class="language-bash">podman ps</code>
Copy after login
Copy after login

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>
Copy after login
Copy after login

Docker

  • Pull the image from Docker Hub
<code class="language-bash">show databases;</code>
Copy after login
Copy after login

Or, use Podman?

<code class="language-bash">podman pull phpmyadmin</code>
Copy after login
Copy after login
  • Now, let’s create our first container from the MySQL image. Here are the commands we will use:
<code class="language-bash">podman pod create --name mysql-pod -p 8080:8080 3306:3306</code>
Copy after login

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 is test-mysql.

-e ENV_VARIABLE=value: The -e tag creates an environment variable that will be available inside the container. It is crucial to set MYSQL_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 of detached, 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 is mysql.

-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:

  • To access the terminal inside the container, you can use the following command:
<code class="language-bash">podman stop mysql-db && podman rm mysql-db</code>
Copy after login
  • Then log in to MySQL:
<code class="language-bash">podman run -d -e MYSQL_ROOT_PASSWORD=tree --pod mysql-pod --name mysql-db mysql:latest</code>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template