Step-by-Step Guide to Installing MySQL 8.x Binary Packages on Linux
This comprehensive tutorial explains how to install MySQL 8.0 and 8.4 binary packages on various Linux distributions, covering user creation, package download, environment setup, configuration, initialization, dependency handling, service script creation, password setting, and verification of the installation.
2.3 Binary Package Installation
2.3.1 MySQL 8.0
2.3.1.1 Users and Groups
# Rocky, AlmaLinux, CentOS, openEuler, AnolisOS, OpenCloudOS, Kylin Server, UOS Server, Ubuntu, Debian
useradd -s /sbin/nologin -r mysql
# openSUSE
groupadd -r mysql
useradd -s /sbin/nologin -r -g mysql mysql2.3.1.2 Prepare Program Files
Download the MySQL binary package from MySQL official website . Choose "DOWNLOADS", then select "MySQL Community (GPL) Downloads". For version 8.0.42, select the appropriate glibc version (glibc 2.28 for most systems, glibc 2.17 for older CentOS 7) and architecture (x86_64).
2.3.1.3 Prepare Environment Variables
echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh2.3.1.4 Prepare Configuration File
cat > /etc/my.cnf <<-EOF
[mysqld]
server-id=1
log-bin
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
datadir=/data/mysql
socket=/data/mysql/mysql.sock
[client]
socket=/data/mysql/mysql.sock
EOF2.3.1.5 Initialize Database and Retrieve Root Password
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
mysqld --initialize --user=mysql --datadir=/data/mysql # generates temporary password
# Example output line:
# A temporary password is generated for root@localhost: K39lgjhHlu:U
# To use an empty password instead:
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql2.3.1.6 Install Required Libraries
On RHEL‑compatible systems install libaio:
yum install -y libaioOn Ubuntu install the appropriate libaio package and create a symlink if necessary:
apt update && apt install -y libaio1
ln -s /usr/lib/x86_64-linux-gnu/libaio.so.1t64.0.2 /usr/lib/x86_64-linux-gnu/libaio.so.1On Debian also install libnuma1 and libncurses6 when required:
apt install -y libaio1 libnuma1 libncurses62.3.1.7 Create Service Script and Enable Service
# For Rocky, AlmaLinux, CentOS, openEuler, AnolisOS, OpenCloudOS, Kylin, UOS, Ubuntu, Debian
yum install -y chkconfig # if not already installed
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
cat > /lib/systemd/system/mysqld.service <<-EOF
[Unit]
Description=mysql database server
After=network.target
[Service]
Type=notify
PrivateNetwork=false
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
SuccessExitStatus=5 6
ExecStart=/etc/init.d/mysqld start
ExecStop=/etc/init.d/mysqld stop
ExecReload=/etc/init.d/mysqld reload
[Install]
WantedBy=multi-user.target
Alias=mysqld.service
EOF
systemctl daemon-reload && systemctl enable --now mysqld
# For openSUSE
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
cat > /usr/lib/systemd/system/mysqld.service <<-EOF
[Unit]
Description=mysql database server
After=network.target
[Service]
Type=notify
PrivateNetwork=false
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
SuccessExitStatus=5 6
ExecStart=/etc/init.d/mysqld start
ExecStop=/etc/init.d/mysqld stop
ExecReload=/etc/init.d/mysqld reload
[Install]
WantedBy=multi-user.target
Alias=mysqld.service
EOF
ln -s /sbin/chkconfig /usr/lib/systemd/systemd-sysv-install
chkconfig --add mysqld
service mysqld start2.3.1.8 Change Root Password
# If you used the temporary password:
awk '/temporary password/{print $NF}' /data/mysql/mysql.log
# Example: K39lgjhHlu:U
mysqladmin -uroot -p'K39lgjhHlu:U' password '123456'
# If you initialized with --initialize-insecure, no password change is needed.2.3.1.9 Verify Installation
mysql -u root -p
# After login, you should see something like:
# mysql Ver 8.0.42 for Linux on x86_64 (MySQL Community Server - GPL)
# Server version: 8.0.42 MySQL Community Server - GPL
# ...
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+2.3.2 MySQL 8.4
2.3.2.1 Users and Groups
# Rocky, AlmaLinux, CentOS, openEuler, AnolisOS, OpenCloudOS, Kylin Server, UOS Server, Ubuntu, Debian
useradd -s /sbin/nologin -r mysql
# openSUSE
groupadd -r mysql
useradd -s /sbin/nologin -r -g mysql mysql2.3.2.2 Prepare Program Files
Download MySQL 8.4.5 binary package (glibc 2.28 or glibc 2.17) from the MySQL website, then extract it to /usr/local and create a symbolic link /usr/local/mysql.
2.3.2.3 Prepare Environment Variables
echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh2.3.2.4 Prepare Configuration File
cat > /etc/my.cnf <<-EOF
[mysqld]
server-id=1
log-bin
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
datadir=/data/mysql
socket=/data/mysql/mysql.sock
[client]
socket=/data/mysql/mysql.sock
EOF2.3.2.5 Initialize Database
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql2.3.2.6 Install Required Libraries
Install libaio (and libnuma on Debian) as described in the 8.0 section, adapting package names for each distribution.
2.3.2.7 Create Service Script and Enable Service
Use the same service‑script steps as for MySQL 8.0, adjusting the binary path to the newly extracted 8.4 directory.
2.3.2.8 Change Root Password
# If you used --initialize, retrieve temporary password from the log and change it:
awk '/temporary password/{print $NF}' /data/mysql/mysql.log
mysqladmin -uroot -p'<temporary_password>' password 'new_password'2.3.2.9 Verify Installation
mysql -u root -p
show databases;2.3.2.10 One‑Click Installation Scripts
Shell scripts install_mysql_8.0_binary_v3.sh and install_mysql_8.4_binary_v3.sh automate the entire process for supported distributions (Rocky, AlmaLinux, CentOS, openEuler, AnolisOS, OpenCloudOS, Kylin, UOS, Ubuntu, Debian, openSUSE). The scripts detect the OS, select the correct glibc version, download the appropriate package, install dependencies, configure MySQL, initialize the data directory, set up systemd service, and start the server.
Source code is available at:
Gitee: https://gitee.com/raymond9/shell
GitHub: https://github.com/raymond999999/shell
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
