Databases 12 min read

Step‑by‑Step: Install MySQL on AlmaLinux (CentOS Alternative) with Docker Compose

This comprehensive tutorial walks you through installing MySQL on AlmaLinux, covering prerequisite cleanup, official repository setup, secure configuration, service management, and an optional Docker‑Compose deployment, plus tips for connecting with DataGrip.

IT Xianyu
IT Xianyu
IT Xianyu
Step‑by‑Step: Install MySQL on AlmaLinux (CentOS Alternative) with Docker Compose

Why choose AlmaLinux?

AlmaLinux is a community‑driven, binary‑compatible replacement for CentOS, offering the same stability for enterprise workloads. MySQL runs on top of this operating system as the database service.

Traditional installation (RPM/YUM)

All commands are executed on the AlmaLinux terminal.

Check for existing MySQL packages

sudo rpm -qa | grep mysql  # list installed MySQL‑related packages

If any mysql‑* or mariadb‑* packages are found, remove them to avoid conflicts:

sudo rpm -e --nodeps <package1> <package2> ...  # force removal, use with caution

Install the official MySQL YUM repository

sudo dnf install https://dev.mysql.com/get/mysql80-community-release-el8-7.noarch.rpm

Import the MySQL GPG key

sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

Install the MySQL server package sudo dnf install mysql-community-server Start and enable the service

sudo systemctl start mysqld
sudo systemctl enable mysqld
sudo systemctl status mysqld  # should show active (running)

Retrieve the temporary root password

sudo grep 'temporary password' /var/log/mysqld.log

Run the secure installation script sudo mysql_secure_installation Follow the prompts: set a strong root password, remove anonymous users, disallow remote root login, delete the test database, and reload privilege tables.

Test the installation mysql -u root -p Enter the new password, then verify the version:

SELECT VERSION();

Docker‑Compose deployment (optional)

Docker Compose isolates MySQL in a container, making setup and teardown painless.

Create a project directory mkdir mysql-docker && cd mysql-docker Create docker-compose.yml

version: '3.8'
services:
  mysql_db:
    image: mysql:8.0.33
    container_name: my_mysql_container
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: YourStrongRootPass!
      MYSQL_DATABASE: my_app_db
      MYSQL_USER: app_user
      MYSQL_PASSWORD: AppUserPass123
    volumes:
      - mysql_data:/var/lib/mysql
    ports:
      - "3306:3306"
    networks:
      - mysql_net
volumes:
  mysql_data:
networks:
  mysql_net:

Start the stack docker-compose up -d Check container status docker-compose ps Connect inside the container

docker-compose exec mysql_db mysql -u root -p
Docker Compose MySQL diagram
Docker Compose MySQL diagram

Connecting with DataGrip

DataGrip is a JetBrains IDE for database management. Create a new MySQL data source, set host to localhost (or the Docker‑mapped host), port 3306 (or the mapped port), user root (or app_user), and the password you defined. Test the connection; if it fails, common issues include wrong credentials, MySQL service not running, or missing SSH tunnel configuration for remote hosts.

LinuxMySQLDocker ComposeAlmaLinuxDataGripDatabase Installation
IT Xianyu
Written by

IT Xianyu

We share common IT technologies (Java, Web, SQL, etc.) and practical applications of emerging software development techniques. New articles are posted daily. Follow IT Xianyu to stay ahead in tech. The IT Xianyu series is being regularly updated.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.