Master MySQL: Complete Installation and Configuration Guide for Linux (Rocky, Ubuntu, Debian, openSUSE)
This comprehensive guide walks you through MySQL fundamentals, its key features, storage engines, architecture, and step‑by‑step installation and configuration across major Linux distributions, including repository setup, service enablement, password initialization, and verification of a working database server.
MySQL Introduction and Installation
1. MySQL Overview
1.1 Definition of MySQL
MySQL is a high‑performance, multi‑user, multi‑threaded relational database management system (RDBMS) that uses SQL (Structured Query Language) as its interface. It was originally developed by MySQL AB, later acquired by Sun, and now belongs to Oracle, while remaining open‑source under the GPL license.
1.2 Features of MySQL
Open source and free.
High performance and scalability.
Cross‑platform support (Linux, Windows, macOS, etc.).
Easy to use command‑line and graphical tools (e.g., MySQL Workbench).
Strong extensibility with multiple storage engines.
Robust security mechanisms (user privileges, encryption, SSL/TLS).
1.3 Application Areas
Web site development (e.g., content management systems, e‑commerce platforms).
Enterprise‑level applications (CRM, ERP, etc.).
Data warehousing and analytics (as part of a larger data pipeline).
Mobile application back‑ends.
1.4 Storage Engines
InnoDB – default engine, supports ACID transactions, row‑level locking, foreign keys.
MyISAM – older engine, supports full‑text search, uses table‑level locking, no transactions.
Memory – stores data in RAM for ultra‑fast access; data is lost on restart.
1.5 Architecture
MySQL architecture is divided into three layers:
Client layer : command‑line client, GUI tools, or programming language connectors send SQL statements.
Server layer : parses, optimizes, and executes queries; includes connection pool, query optimizer, and cache.
Storage‑engine layer : actual data storage and retrieval; each engine implements its own file format and indexing.
1.6 Advantages and Limitations
Advantages: excellent performance, low cost, large community, easy learning curve, wide ecosystem.
Limitations: fewer advanced analytical features compared with some commercial databases, possible data‑consistency issues if misconfigured, higher maintenance for very large clusters.
1.7 Future Trends
Continuous performance tuning for high concurrency and big‑data workloads.
Deeper integration with cloud services (e.g., Amazon RDS, Azure Database for MySQL, Alibaba Cloud MySQL).
2. MySQL Installation
2.1 Host Initialization (Network and System Settings)
2.1.1 Set Network Interface Name
For Rocky Linux 9/10, AlmaLinux 9/10, CentOS Stream 9/10, AnolisOS 23, OpenCloudOS 9:
# mkdir -p /etc/systemd/network/
# cat > /etc/systemd/network/70-eth0.link <<EOF
[Match]
MACAddress=00:0c:29:f8:60:8f
[Link]
Name=eth0
EOFAlternative using variables:
ETHNAME=$(ip addr | awk -F'[ :]' '/^2/{print $3}')
ETHMAC=$(ip addr show ${ETHNAME} | awk -F' ' '/ether/{print $2}')
cat > /etc/systemd/network/70-eth0.link <<EOF
[Match]
MACAddress=${ETHMAC}
[Link]
Name=eth0
EOF2.1.2 Modify NetworkManager Configuration (if NetworkManager is used)
# mv /etc/NetworkManager/system-connections/ens160.nmconnection /etc/NetworkManager/system-connections/eth0.nmconnection
# sed -i.bak 's/ens160/eth0/' /etc/NetworkManager/system-connections/eth0.nmconnection2.1.3 Configure GRUB (for older RHEL‑compatible releases)
# sed -ri 's/^GRUB_CMDLINE_LINUX=.*/& net.ifnames=0 biosdevname=0/' /etc/default/grub
# grub2-mkconfig -o /boot/grub2/grub.cfg # BIOS systems
# grub2-mkconfig -o /boot/efi/EFI/rocky/grub.cfg # UEFI systems2.1.4 Create Udev Rule (optional, e.g., on AnolisOS 8)
# cat > /etc/udev/rules.d/10-network.rules <<EOF
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="00:0c:29:c5:38:3b", NAME="eth0"
EOF2.1.5 Configure Network Interface File
Example for CentOS 7 (if using ifcfg‑eth0):
# cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
NAME=eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
IPADDR=172.31.0.9
PREFIX=21
GATEWAY=172.31.0.2
DNS1=223.5.5.5
DNS2=180.76.76.76
EOF2.1.6 Disable Firewall (optional for testing environments)
# systemctl disable --now firewalld # RHEL, Rocky, AlmaLinux, CentOS, openEuler, AnolisOS, OpenCloudOS, openSUSE, Kylin, UOS
# systemctl disable --now ufw # Ubuntu2.1.7 Disable SELinux (if applicable)
# setenforce 0
# sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config2.1.8 Disable AppArmor (openSUSE)
# systemctl disable --now apparmor2.1.9 Set Timezone
# timedatectl set-timezone Asia/Shanghai
# echo "Asia/Shanghai" > /etc/timezone2.2 Install MySQL from Distribution Repositories
2.2.1 Yum/DNF (RHEL‑compatible)
Enable the official MySQL Yum repository (example for Rocky 9):
# yum install -y wget
# wget https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm
# rpm -ivh mysql84-community-release-el9-1.noarch.rpm
# yum makecache
# yum list mysql-community-server --showduplicates
# yum install -y mysql-community-server
# systemctl enable --now mysqldVerify installation:
# mysql -V
# systemctl status mysqld
# grep 'temporary password' /var/log/mysqld.log2.2.2 Apt (Debian/Ubuntu)
Install the MySQL APT repository package:
# wget https://dev.mysql.com/get/mysql-apt-config_0.8.34-1_all.deb
# dpkg -i mysql-apt-config_0.8.34-1_all.deb # Choose "MySQL Server & Cluster" → "mysql-8.4-lts"
# apt update
# apt install -y mysql-community-server
# systemctl enable --now mysqlRetrieve the temporary root password and change it:
# grep 'temporary password' /var/log/mysql/error.log
# mysqladmin -uroot -p'YOUR_TEMP_PASSWORD' password 'NewStrongP@ssw0rd!'2.2.3 Zypper (openSUSE)
Add the MySQL community repository for openSUSE 15:
# wget https://repo.mysql.com/mysql80-community-release-sles15-1.noarch.rpm
# rpm -Uvh mysql80-community-release-sles15-1.noarch.rpm
# zypper refresh
# zypper install -y mysql-community-server
# systemctl enable --now mysqlCheck the temporary password and set a new one:
# grep 'temporary password' /var/log/mysql/mysqld.log
# mysqladmin -uroot -p'YOUR_TEMP_PASSWORD' password 'NewStrongP@ssw0rd!'2.3 Verify the Installation
After setting a new root password, log into MySQL and confirm basic operation:
# mysql -uroot -p'NewStrongP@ssw0rd!'
mysql> status;
mysql> show databases;
mysql> exit;Typical output shows the server version, uptime, and the default system databases ( information_schema, mysql, performance_schema, sys).
3. Additional Resources
For detailed configuration, performance tuning, and replication setup, refer to the official MySQL documentation at https://dev.mysql.com/doc/ .
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
