当前位置: 首页 > news >正文

MySQL二进制包安装

文章目录

    • 2.3 二进制包安装
      • 2.3.1 MySQL 8.0
        • 2.3.1.1 用户和组
        • 2.3.1.2 准备程序文件
        • 2.3.1.3 准备环境变量
        • 2.3.2.4 准备配置文件
        • 2.3.2.5 生成数据库文件,并提取root密码
        • 2.3.2.6 准备服务脚本和启动
        • 2.3.2.7 修改口令
        • 2.3.2.8 测试登录
        • 2.3.2.9 一键安装MySQL 8.0二进制包的脚本
      • 2.3.2 MySQL 8.4
        • 2.3.2.1 用户和组
        • 2.3.2.2 准备程序文件
        • 2.3.2.3 准备环境变量
        • 2.3.2.4 准备配置文件
        • 2.3.2.5 生成数据库文件,并提取root密码
        • 2.3.2.6 准备服务脚本和启动
        • 2.3.2.7 修改口令
        • 2.3.2.8 测试登录
        • 2.3.2.9 一键安装MySQL 8.4二进制包的脚本

2.3 二进制包安装

2.3.1 MySQL 8.0

2.3.1.1 用户和组
# 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 mysql
2.3.1.2 准备程序文件

MySQL二进制包下载,去“https://www.mysql.com/”网站下载,选择“DOWNLOADS”,如图23所示。

t23

图23 下载MySQL二进制包

选择“MySQL Community (GPL) Downloads”,如图24所示。

t24

图24 下载MySQL二进制包

然后选择“MySQL Community Server”,如图25所示。

t25

图25 下载MySQL二进制包

然后版本选择“8.0.42”,操作系统选择“Linux-Generic”,下面的有5个版本,分别是“glibc 2.28 (x86, 32-bit、x86, 64-bit和ARM, 64-bit)、glibc 2.17 (x86, 32-bit和x86, 64-bit)”,这个根据系统的glibc版本和主机的硬件架构类型下载,图26所示。

t26

图26 下载MySQL二进制包

[root@rocky10 ~]# dnf info glibc
Last metadata expiration check: 0:08:38 ago on Tue 10 Jun 2025 12:21:32 PM CST.
Installed Packages
Name         : glibc
Version      : 2.39 # 可以看到Rocky 10的glibc版本是2.39
Release      : 37.el10
Architecture : x86_64
Size         : 6.2 M
Source       : glibc-2.39-37.el10.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPL-2.1-or-later AND SunPro AND LGPL-2.1-or-later WITH GCC-exception-2.0 AND BSD-3-Clause AND: GPL-2.0-or-later AND LGPL-2.1-or-later WITH GNU-compiler-exception AND GPL-2.0-only AND ISC AND: LicenseRef-Fedora-Public-Domain AND HPND AND CMU-Mach AND LGPL-2.1-only AND LGPL-2.0-or-later AND: Unicode-DFS-2015 AND GFDL-1.1-or-later AND GPL-1.0-or-later AND FSFUL AND MIT AND Inner-Net-2.0: AND X11 AND GPL-2.0-or-later WITH GCC-exception-2.0 AND GFDL-1.3-only AND GFDL-1.1-only
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.[root@rocky9 ~]# dnf info glibc
Last metadata expiration check: 0:10:23 ago on Tue 22 Apr 2025 09:55:39 PM CST.
Installed Packages
Name         : glibc
Version      : 2.34 # 可以看到Rocky 9的glibc版本是2.34
Release      : 125.el9_5.1
Architecture : x86_64
Size         : 6.1 M
Source       : glibc-2.34-125.el9_5.1.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net and: ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@rocky8 ~]# dnf info glibc
Last metadata expiration check: 0:03:40 ago on Fri 25 Apr 2025 05:47:33 PM CST.
Installed Packages
Name         : glibc
Version      : 2.28 # 可以看到Rocky 8的glibc版本是2.28
Release      : 251.el8_10.2
Architecture : x86_64
Size         : 6.6 M
Source       : glibc-2.28-251.el8_10.2.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net and: ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@almalinux10 ~]# dnf info glibc
Last metadata expiration check: 0:02:16 ago on Tue 10 Jun 2025 01:44:44 PM CST.
Installed Packages
Name         : glibc
Version      : 2.39 # 可以看到Almalinux 10的glibc版本是2.39
Release      : 37.el10.alma.1
Architecture : x86_64
Size         : 6.2 M
Source       : glibc-2.39-37.el10.alma.1.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPL-2.1-or-later AND SunPro AND LGPL-2.1-or-later WITH GCC-exception-2.0 AND BSD-3-Clause AND: GPL-2.0-or-later AND LGPL-2.1-or-later WITH GNU-compiler-exception AND GPL-2.0-only AND ISC AND: LicenseRef-Fedora-Public-Domain AND HPND AND CMU-Mach AND LGPL-2.1-only AND LGPL-2.0-or-later AND: Unicode-DFS-2015 AND GFDL-1.1-or-later AND GPL-1.0-or-later AND FSFUL AND MIT AND Inner-Net-2.0: AND X11 AND GPL-2.0-or-later WITH GCC-exception-2.0 AND GFDL-1.3-only AND GFDL-1.1-only
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.[root@almalinux9 ~]# dnf info glibc
Last metadata expiration check: 0:00:59 ago on Tue 22 Apr 2025 11:11:48 PM CST.
Installed Packages
Name         : glibc
Version      : 2.34 # 可以看到Almalinux 9的glibc版本是2.34
Release      : 125.el9_5.1
Architecture : x86_64
Size         : 6.1 M
Source       : glibc-2.34-125.el9_5.1.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net and: ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@almalinux8 ~]# dnf info glibc
Last metadata expiration check: 0:02:09 ago on Fri 25 Apr 2025 06:36:03 PM CST.
Installed Packages
Name         : glibc
Version      : 2.28 # 可以看到Almalinux 8的glibc版本是2.28
Release      : 251.el8_10.2
Architecture : x86_64
Size         : 6.6 M
Source       : glibc-2.28-251.el8_10.2.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net and: ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@centos10 ~]# dnf info glibc
Last metadata expiration check: 0:01:31 ago on Fri 25 Apr 2025 05:25:26 PM CST.
Installed Packages
Name         : glibc
Version      : 2.39 # 可以看到CentOS Stream 10的glibc版本是2.39
Release      : 37.el10
Architecture : x86_64
Size         : 6.2 M
Source       : glibc-2.39-37.el10.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPL-2.1-or-later AND SunPro AND LGPL-2.1-or-later WITH GCC-exception-2.0 AND BSD-3-Clause AND: GPL-2.0-or-later AND LGPL-2.1-or-later WITH GNU-compiler-exception AND GPL-2.0-only AND ISC AND: LicenseRef-Fedora-Public-Domain AND HPND AND CMU-Mach AND LGPL-2.1-only AND LGPL-2.0-or-later AND: Unicode-DFS-2015 AND GFDL-1.1-or-later AND GPL-1.0-or-later AND FSFUL AND MIT AND Inner-Net-2.0 AND: X11 AND GPL-2.0-or-later WITH GCC-exception-2.0 AND GFDL-1.3-only AND GFDL-1.1-only
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.[root@centos9 ~]# dnf info glibc
Last metadata expiration check: 0:00:55 ago on Fri 25 Apr 2025 06:53:50 PM CST.
Installed Packages
Name         : glibc
Version      : 2.34 # 可以看到CentOS Stream 9的glibc版本是2.34
Release      : 184.el9
Architecture : x86_64
Size         : 6.1 M
Source       : glibc-2.34-184.el9.src.rpm
Repository   : @System
From repo    : baseos
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@centos8 ~]# dnf info glibc
Last metadata expiration check: 0:02:56 ago on Fri 25 Apr 2025 07:43:16 PM CST.
Installed Packages
Name         : glibc
Version      : 2.28 # 可以看到CentOS Stream 8的glibc版本是2.28
Release      : 251.el8
Architecture : x86_64
Size         : 6.6 M
Source       : glibc-2.28-251.el8.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
... [root@centos7 ~]# yum info glibc
Loaded plugins: fastestmirror
Repository 'mysql' is missing name in configuration, using id
Loading mirror speeds from cached hostfile
Installed Packages
Name        : glibc
Arch        : x86_64
Version     : 2.17 # 可以看到CentOS 7的glibc版本是2.17
Release     : 326.el7_9
Size        : 13 M
Repo        : installed
From repo   : anaconda
Summary     : The GNU libc libraries
URL         : http://www.gnu.org/software/glibc/
License     : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+
Description : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@openeuler2403 ~]# yum info glibc
Last metadata expiration check: 0:03:19 ago on Fri 25 Apr 2025 08:21:42 PM CST.
Installed Packages
Name         : glibc
Version      : 2.38 # 可以看到openEuler 24.03的glibc版本是2.38
Release      : 47.oe2403sp1
Architecture : x86_64
Size         : 11 M
Source       : glibc-2.38-47.oe2403sp1.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and: Inner-Net-2.0 and ISC and Public Domain and GFDL-1.3-only
Description  : The GNU C Library project provides the core libraries for the GNU system and: GNU/Linux systems, as well as many other systems that use Linux as the kernel.: These libraries provide critical APIs including ISO C11, POSIX.1-2008, BSD,: OS-specific APIs and more. These APIs include such foundational facilities as: open, read, write, malloc, printf, getaddrinfo, dlopen, pthread_create, crypt,:  login, exit and more.
...[root@openeuler2203 ~]# yum info glibc
Last metadata expiration check: 0:01:16 ago on Fri 25 Apr 2025 08:40:01 PM CST.
Installed Packages
Name         : glibc
Version      : 2.34 # 可以看到openEuler 22.03的glibc版本是2.34
Release      : 152.oe2203sp4
Architecture : x86_64
Size         : 11 M
Source       : glibc-2.34-152.oe2203sp4.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The GNU C Library project provides the core libraries for the GNU system and: GNU/Linux systems, as well as many other systems that use Linux as the kernel.: These libraries provide critical APIs including ISO C11, POSIX.1-2008, BSD,: OS-specific APIs and more. These APIs include such foundational facilities as: open, read, write, malloc, printf, getaddrinfo, dlopen, pthread_create, crypt,:  login, exit and more.
...[root@anolisos23 ~]# yum info glibc
Last metadata expiration check: 0:01:02 ago on Fri Apr 25 20:58:58 2025.
Installed Packages
Name         : glibc
Version      : 2.38 # 可以看到AnolisOS 23的glibc版本是2.38
Release      : 5.an23
Architecture : x86_64
Size         : 7.4 M
Source       : glibc-2.38-5.an23.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system.: In order to save disk space and memory, as well as to make upgrading easier,: common system code is kept in one place and shared between programs.: This particular package contains the most important sets of shared libraries:: the standard C library and the standard math library.: Without these two libraries, a Linux system will not function.
...[root@anolis8 ~]# yum info glibc
Last metadata expiration check: 0:01:16 ago on Sat 26 Apr 2025 05:10:03 AM CST.
Installed Packages
Name         : glibc
Version      : 2.28 # 可以看到AnolisOS 8的glibc版本是2.28
Release      : 236.0.1.an8.8
Architecture : x86_64
Size         : 6.4 M
Source       : glibc-2.28-236.0.1.an8.8.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@opencloudos9 ~]# yum info glibc
Last metadata expiration check: 0:00:46 ago on Fri 25 Apr 2025 09:36:03 PM CST.
Installed Packages
Name         : glibc
Version      : 2.38 # 可以看到OpenCloudOS 9的glibc版本是2.38
Release      : 29.oc9
Architecture : x86_64
Size         : 6.6 M
Source       : glibc-2.38-29.oc9.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The GNU C Library project provides the core libraries for the GNU: system and GNU/Linux systems, as well as many other systems that use: Linux as the kernel. These libraries provide critical APIs including: ISO C11, POSIX.1-2008, BSD, OS-specific APIs and more. These APIs: include such foundational facilities as open, read, write, malloc,: printf, getaddrinfo, dlopen, pthread_create, crypt, login, exit and more.[root@opencloudos8 ~]# yum info glibc
Last metadata expiration check: 0:00:45 ago on Sat 26 Apr 2025 05:54:03 AM CST.
Installed Packages
Name         : glibc
Version      : 2.28 # 可以看到OpenCloudOS 9的glibc版本是2.28
Release      : 251.oc8.5.ap.1
Architecture : x86_64
Size         : 6.6 M
Source       : glibc-2.28-251.oc8.5.ap.1.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@kylin10 ~]# yum info glibc
Last metadata expiration check: 0:03:30 ago on Fri 25 Apr 2025 10:10:26 PM CST.
Installed Packages
Name         : glibc
Version      : 2.28 # 可以看到Kylin Server v10的glibc版本是2.28
Release      : 98.p02.ky10
Architecture : x86_64
Size         : 11 M
Source       : glibc-2.28-98.p02.ky10.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The GNU C Library project provides the core libraries for the GNU system and: GNU/Linux systems, as well as many other systems that use Linux as the kernel.: These libraries provide critical APIs including ISO C11, POSIX.1-2008, BSD,: OS-specific APIs and more. These APIs include such foundational facilities as: open, read, write, malloc, printf, getaddrinfo, dlopen, pthread_create, crypt,:  login, exit and more.
...[root@uos20 ~]# yum info glibc
Last metadata expiration check: 0:00:51 ago on Fri 25 Apr 2025 10:26:30 PM CST.
Installed Packages
Name         : glibc
Version      : 2.28 # 可以看到Uos Server v10的glibc版本是2.28
Release      : 97.uel20.07
Architecture : x86_64
Size         : 13 M
Source       : glibc-2.28-97.uel20.07.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The GNU C Library project provides the core libraries for the GNU system and: GNU/Linux systems, as well as many other systems that use Linux as the kernel.: These libraries provide critical APIs including ISO C11, POSIX.1-2008, BSD,: OS-specific APIs and more. These APIs include such foundational facilities as: open, read, write, malloc, printf, getaddrinfo, dlopen, pthread_create, crypt,:  login, exit and more.opensuse15:~ # zypper info glibc
Loading repository data...
Reading installed packages...Information for package glibc:
------------------------------
Repository     : mirror-sle-update
Name           : glibc
Version        : 2.38-150600.14.26.1 # 可以看到openSUSE 15的glibc版本是2.38
Arch           : x86_64
Vendor         : SUSE LLC <https://www.suse.com/>
Installed Size : 6.5 MiB
Installed      : Yes
Status         : out-of-date (version 2.38-150600.12.1 installed)
Source package : glibc-2.38-150600.14.26.1.src
Upstream URL   : https://www.gnu.org/software/libc/libc.html
Summary        : Standard Shared Libraries (from the GNU C Library)
Description    : The GNU C Library provides the most important standard libraries usedby nearly all programs: the standard C library, the standard mathlibrary, and the POSIX thread library. A system is not functionalwithout these libraries.root@ubuntu2404:~# ldd --version
ldd (Ubuntu GLIBC 2.39-0ubuntu8.4) 2.39 # 可以看到Ubuntu 24.04的glibc版本是2.39
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.root@ubuntu2204:~# ldd --version
ldd (Ubuntu GLIBC 2.35-0ubuntu3.6) 2.35 # 可以看到Ubuntu 22.04的glibc版本是2.35
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.raymond@ubuntu2004:~$ ldd --version
ldd (Ubuntu GLIBC 2.31-0ubuntu9.9) 2.31 # 可以看到Ubuntu 20.04的glibc版本是2.31
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.raymond@ubuntu1804:~$ ldd --version
ldd (Ubuntu GLIBC 2.27-3ubuntu1.4) 2.27 # 可以看到Ubuntu 18.04的glibc版本是2.27
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.root@debian12:~# ldd --version
ldd (Debian GLIBC 2.36-9+deb12u9) 2.36 # 可以看到Debian 12的glibc版本是2.36
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.root@debian11:~# ldd --version
ldd (Debian GLIBC 2.31-13+deb11u11) 2.31 # 可以看到Debian 11的glibc版本是2.31
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

显示当前主机的硬件架构类型:

[root@rocky9 ~]# arch
x86_64

根据操作系统的glibc版本去下载相应的安装包,这里系统版本选择“Linux - Generic (glibc 2.28) (x86, 64-bit)”,然后选择下面的“mysql-8.0.42-linux-glibc2.28-x86_64.tar.xz”包后面的“Download”进行下载,**注意:**glibc版本大于等于2.28的使用glibc 2.28版的MySQL二进制包,glibc版本小于2.28的使用glibc2.17版的MySQL二进制包,如图27所示。

t27

图27 下载MySQL二进制包

# Rocky、Almalinux、CentOS、openEuler、AnolisOS、OpenCloudOS、Kylin Server、Uos Server默认没有wget包,需要安装
yum install -y wget# openEuler 22.03/24.03、AnolisOS 23、OpenCloudOS 9没有安装tar包,需要安装
yum install -y tar# mysql 8.0.42 glibc2.28包
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.42-linux-glibc2.28-x86_64.tar.xz
tar xf mysql-8.0.42-linux-glibc2.28-x86_64.tar.xz -C /usr/local
ln -s /usr/local/mysql-8.0.42-linux-glibc2.28-x86_64/ /usr/local/mysql# mysql 8.0.42 glibc2.17包
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.42-linux-glibc2.17-x86_64.tar.xz
tar xf mysql-8.0.42-linux-glibc2.17-x86_64.tar.xz -C /usr/local
ln -s /usr/local/mysql-8.0.42-linux-glibc2.17-x86_64/ /usr/local/mysqlchown -R  mysql:mysql /usr/local/mysql/
2.3.1.3 准备环境变量
echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
2.3.2.4 准备配置文件
cat > /etc/my.cnf <<-EOF
[mysqld]
server-id=1
log-bin
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid[client]
socket=/data/mysql/mysql.sock
EOF
2.3.2.5 生成数据库文件,并提取root密码
mkdir -p /data/mysqlchown -R mysql:mysql /data/mysql# /data/mysql  会自动生成,但是/data/必须事先存在
# --initialize会生成一个初始化密码,--initialize-insecure生成空密码,两种方式任选一种
mysqld --initialize --user=mysql --datadir=/data/mysqlgrep password /data/mysql/mysql.log
2025-04-22T14:36:39.157585Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: K39lgjhHlu:U
# "K39lgjhHlu:U"就是初始化密码# 生成空密码的root用户
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql

Rocky 8/9/10、Almalinux 8/9/10、CentOS Stream 8/9/10、CentOS 7、openEuler 22.03/24.03、AnolisOS 8/23、OpenCloudOS 8/9:

mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory # 提示确少”libaio.so.1“文件yum install -y libaiomysqld --initialize-insecure --user=mysql --datadir=/data/mysql

Ubuntu 24.04:

mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directoryroot@ubuntu2404:~# apt search libaio
Sorting... Done
Full Text Search... Done
libaio-dev/noble-updates 0.3.113-6build1.1 amd64Linux kernel AIO access library - development fileslibaio1t64/noble-updates,now 0.3.113-6build1.1 amd64 [installed,automatic] # 可以看到libaio1t64包已经安装过了Linux kernel AIO access library - shared libraryln -s /usr/lib/x86_64-linux-gnu/libaio.so.1t64.0.2 /usr/lib/x86_64-linux-gnu/libaio.so.1mysqld --initialize-insecure --user=mysql --datadir=/data/mysql

Ubuntu 18.04:

mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directoryroot@ubuntu1804:~# apt search libaio
Sorting... Done
Full Text Search... Done
libaio-dev/bionic-updates 0.3.110-5ubuntu0.1 amd64Linux kernel AIO access library - development fileslibaio1/bionic-updates 0.3.110-5ubuntu0.1 amd64Linux kernel AIO access library - shared libraryapt install -y libaio1mysqld --initialize-insecure --user=mysql --datadir=/data/mysq

Debian 11/12:

root@debian12:~# mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directoryroot@debian12:~# apt search libaio
Sorting... Done
Full Text Search... Done
libaio-dev/stable 0.3.113-4 amd64Linux kernel AIO access library - development fileslibaio1/stable 0.3.113-4 amd64Linux kernel AIO access library - shared libraryapt install -y libaio1root@debian12:~# mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directoryroot@debian12:~# apt search libnuma
Sorting... Done
Full Text Search... Done
libnuma-dev/stable 2.0.16-1 amd64Development files for libnumalibnuma1/stable 2.0.16-1 amd64Libraries for controlling NUMA policyapt install -y libnuma1mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
2.3.2.6 准备服务脚本和启动

Rocky、Almalinux、CentOS、openEuler、AnolisOS、OpenCloudOS、 Kylin Server、Uos Server、Ubuntu、Debian:

# Rocky 9/10、Almalinux 9/10、CentOS Stream 9/10默认没有chkconfig包,需要安装
yum install -y chkconfigcp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldcat > /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
EOFsystemctl daemon-reload && systemctl enable --now mysqld

openSUSE:

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld# openSUSE
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# openSUSE
ln -s /sbin/chkconfig  /usr/lib/systemd/systemd-sysv-install
chkconfig --add mysqldservice mysqld start
2.3.2.7 修改口令
# 如果使用的是空密码,就不需要修改口令
awk '/temporary password/{print $NF}' /data/mysql/mysql.log
aupYu;uhJ9&ymysqladmin -uroot -p'aupYu;uhJ9&y' password 123456
2.3.2.8 测试登录

Rocky 8/9/10、Almalinux 8/9/10、CentOS Stream 8/9/10、CentOS 7、openEuler 22.03/24.03、AnolisOS 8/23、OpenCloudOS 8/9、Kylin Server v10、Uos Server v20、Ubuntu 18.04/20.04/22.04/24.04、Debian 11、openSUSE:

[root@rocky10 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.42 MySQL Community Server - GPLCopyright (c) 2000, 2025, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> status
--------------
mysql  Ver 8.0.42 for Linux on x86_64 (MySQL Community Server - GPL)Connection id:		8
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.0.42 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/data/mysql/mysql.sock
Binary data as:		Hexadecimal
Uptime:			15 secThreads: 2  Questions: 5  Slow queries: 0  Opens: 120  Flush tables: 3  Open tables: 36  Queries per second avg: 0.333
--------------mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)mysql> exit
Bye

Debian 12:

root@debian12:~# mysql
mysql: error while loading shared libraries: libncurses.so.6: cannot open shared object file: No such file or directoryroot@debian12:~# apt search libncurses6
Sorting... Done
Full Text Search... Done
libncurses6/stable 6.4-4 amd64shared libraries for terminal handlingapt install -y libncurses6root@debian12:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.42 MySQL Community Server - GPLCopyright (c) 2000, 2025, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> status
--------------
mysql  Ver 8.0.42 for Linux on x86_64 (MySQL Community Server - GPL)Connection id:		8
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.0.42 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/data/mysql/mysql.sock
Binary data as:		Hexadecimal
Uptime:			32 secThreads: 2  Questions: 5  Slow queries: 0  Opens: 120  Flush tables: 3  Open tables: 36  Queries per second avg: 0.156
--------------mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)mysql> exit
Bye
2.3.2.9 一键安装MySQL 8.0二进制包的脚本

Shell脚本源码地址:

Gitee:https://gitee.com/raymond9/shell

Github:https://github.com/raymond999999/shell

可以去上面的Gitee或Github代码仓库拉取脚本。

# install_mysql_binary_v3.sh脚本创建的数据库是空密码。
[root@rocky10 ~]# cat install_mysql_8.0_binary_v3.sh
#!/bin/bash
#
#**********************************************************************************
#Author:        Raymond
#QQ:            88563128
#Date:          2025-06-10
#FileName:      install_mysql_8.0_binary_v3.sh
#URL:           https://wx.zsxq.com/group/15555885545422
#Description:   The mysql binary script install supports 
#               “Rocky Linux 8, 9 and 10, Almalinux 8, 9 and 10, CentOS 7, 
#               CentOS Stream 8, 9 and 10, openEuler 22.03 and 24.03, 
#               AnolisOS 8 and 23, OpencloudOS 8 and 9, Kylin Server v10, 
#               Uos Server v20, Ubuntu 18.04, 20.04, 22.04 and 24.04,  
#               Debian 11 and 12, openSUSE 15“ operating systems.
#Copyright (C): 2025 All rights reserved
#**********************************************************************************
COLOR="echo -e \\033[01;31m"
END='\033[0m'# mysql 8.0.42 glibc2.28包下载地址:"https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.42-linux-glibc2.28-x86_64.tar.xz"
# mysql 8.0.42 glibc2.17包下载地址:"https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.42-linux-glibc2.17-x86_64.tar.xz"DATA_DIR=/data/mysql
GLIBC_VERSION=2.28
MYSQL_URL=https://cdn.mysql.com//Downloads/MySQL-8.0/
MYSQL_FILE="mysql-8.0.42-linux-glibc${GLIBC_VERSION}-x86_64.tar.xz"os(){. /etc/os-releaseMAIN_NAME=`sed -rn '/^NAME=/s@.*="([[:alpha:]]+).*"$@\1@p' /etc/os-release`MAIN_VERSION_ID=`sed -rn '/^VERSION_ID=/s@.*="?([0-9]+)\.?.*"?@\1@p' /etc/os-release`if [ ${MAIN_NAME} == "Ubuntu" -o ${MAIN_NAME} == "Debian" ];thenFULL_NAME="${PRETTY_NAME}"elif [ ${MAIN_NAME} == "UOS" ];thenFULL_NAME="${NAME}"elseFULL_NAME="${NAME} ${VERSION_ID}"fi
}check_file(){if [ ${MAIN_NAME} == "Rocky" -o ${MAIN_NAME} == "AlmaLinux" -o ${MAIN_NAME} == "CentOS" -o ${MAIN_NAME} == "openEuler" -o ${MAIN_NAME} == "Anolis" -o ${MAIN_NAME} == "OpenCloudOS" -o ${MAIN_NAME} == "Kylin" -o ${MAIN_NAME} == "UOS" ];thenrpm -q wget &> /dev/null || { ${COLOR}"安装wget工具,请稍等......"${END};yum install -y wget &> /dev/null; }fiif [ ! -e ${MYSQL_FILE} ];then${COLOR}"缺少${MYSQL_FILE}文件"${END}${COLOR}'开始下载MySQL二进制安装包,请稍等......'${END}wget ${MYSQL_URL}${MYSQL_FILE} || { ${COLOR}"MySQL二进制安装包下载失败。"${END}; exit; }else${COLOR}"${MYSQL_FILE}文件已准备好。"${END}fi
}install_mysql(){[ -d /usr/local/mysql ] && { ${COLOR}"MySQL数据库已存在,安装失败!"${END};exit; }${COLOR}"开始安装MySQL数据库,请稍等......"${END}if [ ${MAIN_NAME} == "openSUSE" ];thenid mysql &> /dev/null || { groupadd -r mysql && useradd -s /sbin/nologin -r -g mysql mysql; ${COLOR}"成功创建mysql用户!"${END}; }elseid mysql &> /dev/null || { useradd -s /sbin/nologin -r mysql ; ${COLOR}"成功创建mysql用户!"${END}; }fiif [ ${MAIN_NAME} == "openEuler" ];thenif [ ${MAIN_VERSION_ID} == 22 -o ${MAIN_VERSION_ID} == 24 ];thenyum install -y tar &> /dev/nullfifiif [ ${MAIN_NAME} == "Anolis" ];thenif [ ${MAIN_VERSION_ID} == 23 ];thenyum install -y tar &> /dev/nullfifiif [ ${MAIN_NAME} == "OpenCloudOS" ];thenif [ ${MAIN_VERSION_ID} == 9 ];thenyum install -y tar &> /dev/nullfifitar xf ${MYSQL_FILE} -C /usr/local/MYSQL_DIR=`echo ${MYSQL_FILE}| sed -nr 's/^(.*[0-9]).*/\1/p'`ln -s /usr/local/${MYSQL_DIR} /usr/local/mysqlchown -R mysql:mysql /usr/local/mysql/echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh. /etc/profile.d/mysql.shcat > /etc/my.cnf <<-EOF
[mysqld]
server-id=1
log-bin
datadir=${DATA_DIR}
socket=${DATA_DIR}/mysql.sock
log-error=${DATA_DIR}/mysql.log
pid-file=${DATA_DIR}/mysql.pid[client]
socket=${DATA_DIR}/mysql.sock
EOF[ -d ${DATA_DIR} ] || mkdir -p ${DATA_DIR} &> /dev/nullchown -R mysql:mysql ${DATA_DIR}if [ ${MAIN_NAME} == "Rocky" -o ${MAIN_NAME} == "AlmaLinux" -o ${MAIN_NAME} == "CentOS" -o ${MAIN_NAME} == "openEuler" -o ${MAIN_NAME} == "Anolis" -o ${MAIN_NAME} == "OpenCloudOS" ];thenyum install -y libaio &> /dev/nullfiif [ ${MAIN_NAME} == "Ubuntu" ];thenif [ ${MAIN_VERSION_ID} == 24 ];thenln -s /usr/lib/x86_64-linux-gnu/libaio.so.1t64.0.2 /usr/lib/x86_64-linux-gnu/libaio.so.1fiif [ ${MAIN_VERSION_ID} == 18 ];thenapt update &> /dev/null;apt install -y libaio1 &> /dev/nullfifiif [ ${MAIN_NAME} == "Debian" ];thenif [ ${MAIN_VERSION_ID} == 11 -o ${MAIN_VERSION_ID} == 12 ];thenapt update &> /dev/null;apt install -y libaio1 libnuma1 &> /dev/nullfiif [ ${MAIN_VERSION_ID} == 12 ];thenapt update &> /dev/null;apt install -y libncurses6 &> /dev/nullfifimysqld --initialize-insecure --user=mysql --datadir=${DATA_DIR}if [ ${MAIN_NAME} == "Rocky" ];thenif [ ${MAIN_VERSION_ID} == 9 -o ${MAIN_VERSION_ID} == 10 ];thenyum install -y chkconfig &> /dev/nullfifiif [ ${MAIN_NAME} == "AlmaLinux" ];thenif [ ${MAIN_VERSION_ID} == 9 -o ${MAIN_VERSION_ID} == 10 ];thenyum install -y chkconfig &> /dev/nullfifiif [ ${MAIN_NAME} == "CentOS" ];thenif [ ${MAIN_VERSION_ID} == 9 -o ${MAIN_VERSION_ID} == 10 ];thenyum install -y chkconfig &> /dev/nullfificp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldif [ ${MAIN_NAME} == "openSUSE" ];thencat > /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
EOFln -s /sbin/chkconfig  /usr/lib/systemd/systemd-sysv-installchkconfig --add mysqld  &> /dev/nullservice mysqld startelsecat > /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
EOFsystemctl daemon-reload && systemctl enable --now mysqld &> /dev/nullfi[ $? -ne 0 ] && { ${COLOR}"数据库启动失败,退出!"${END};exit; }${COLOR}"${FULL_NAME}操作系统,MySQL数据库安装完成!"${END}
}main(){oscheck_fileinstall_mysql
}main

2.3.2 MySQL 8.4

2.3.2.1 用户和组
# 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 mysql
2.3.2.2 准备程序文件

MySQL二进制包下载,去“https://www.mysql.com/”网站下载,选择“DOWNLOADS”,如图28所示。

t28

图28 下载MySQL二进制包

选择“MySQL Community (GPL) Downloads”,如图29所示。

t29

图29 下载MySQL二进制包

然后选择“MySQL Community Server”,如图30所示。

t30

图30 下载MySQL二进制包

然后版本选择“8.4.5 LTS”,操作系统选择“Linux-Generic”,下面的有3个版本,分别是“glibc 2.28 (x86, 64-bit和ARM, 64-bit)、glibc 2.17 (x86, 64-bit)”,这个根据系统的glibc版本和主机的硬件架构类型下载,如图31所示。

t31

图31 下载MySQL二进制包

[root@rocky10 ~]# dnf info glibc
Last metadata expiration check: 0:08:38 ago on Tue 10 Jun 2025 12:21:32 PM CST.
Installed Packages
Name         : glibc
Version      : 2.39 # 可以看到Rocky 10的glibc版本是2.39
Release      : 37.el10
Architecture : x86_64
Size         : 6.2 M
Source       : glibc-2.39-37.el10.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPL-2.1-or-later AND SunPro AND LGPL-2.1-or-later WITH GCC-exception-2.0 AND BSD-3-Clause AND: GPL-2.0-or-later AND LGPL-2.1-or-later WITH GNU-compiler-exception AND GPL-2.0-only AND ISC AND: LicenseRef-Fedora-Public-Domain AND HPND AND CMU-Mach AND LGPL-2.1-only AND LGPL-2.0-or-later AND: Unicode-DFS-2015 AND GFDL-1.1-or-later AND GPL-1.0-or-later AND FSFUL AND MIT AND Inner-Net-2.0: AND X11 AND GPL-2.0-or-later WITH GCC-exception-2.0 AND GFDL-1.3-only AND GFDL-1.1-only
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.[root@rocky9 ~]# dnf info glibc
Last metadata expiration check: 0:10:23 ago on Tue 22 Apr 2025 09:55:39 PM CST.
Installed Packages
Name         : glibc
Version      : 2.34 # 可以看到Rocky 9的glibc版本是2.34
Release      : 125.el9_5.1
Architecture : x86_64
Size         : 6.1 M
Source       : glibc-2.34-125.el9_5.1.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net and: ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@rocky8 ~]# dnf info glibc
Last metadata expiration check: 0:03:40 ago on Fri 25 Apr 2025 05:47:33 PM CST.
Installed Packages
Name         : glibc
Version      : 2.28 # 可以看到Rocky 8的glibc版本是2.28
Release      : 251.el8_10.2
Architecture : x86_64
Size         : 6.6 M
Source       : glibc-2.28-251.el8_10.2.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net and: ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@almalinux10 ~]# dnf info glibc
Last metadata expiration check: 0:02:16 ago on Tue 10 Jun 2025 01:44:44 PM CST.
Installed Packages
Name         : glibc
Version      : 2.39 # 可以看到Almalinux 10的glibc版本是2.39
Release      : 37.el10.alma.1
Architecture : x86_64
Size         : 6.2 M
Source       : glibc-2.39-37.el10.alma.1.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPL-2.1-or-later AND SunPro AND LGPL-2.1-or-later WITH GCC-exception-2.0 AND BSD-3-Clause AND: GPL-2.0-or-later AND LGPL-2.1-or-later WITH GNU-compiler-exception AND GPL-2.0-only AND ISC AND: LicenseRef-Fedora-Public-Domain AND HPND AND CMU-Mach AND LGPL-2.1-only AND LGPL-2.0-or-later AND: Unicode-DFS-2015 AND GFDL-1.1-or-later AND GPL-1.0-or-later AND FSFUL AND MIT AND Inner-Net-2.0: AND X11 AND GPL-2.0-or-later WITH GCC-exception-2.0 AND GFDL-1.3-only AND GFDL-1.1-only
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.[root@almalinux9 ~]# dnf info glibc
Last metadata expiration check: 0:00:59 ago on Tue 22 Apr 2025 11:11:48 PM CST.
Installed Packages
Name         : glibc
Version      : 2.34 # 可以看到Almalinux 9的glibc版本是2.34
Release      : 125.el9_5.1
Architecture : x86_64
Size         : 6.1 M
Source       : glibc-2.34-125.el9_5.1.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net and: ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@almalinux8 ~]# dnf info glibc
Last metadata expiration check: 0:02:09 ago on Fri 25 Apr 2025 06:36:03 PM CST.
Installed Packages
Name         : glibc
Version      : 2.28 # 可以看到Almalinux 8的glibc版本是2.28
Release      : 251.el8_10.2
Architecture : x86_64
Size         : 6.6 M
Source       : glibc-2.28-251.el8_10.2.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net and: ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@centos10 ~]# dnf info glibc
Last metadata expiration check: 0:01:31 ago on Fri 25 Apr 2025 05:25:26 PM CST.
Installed Packages
Name         : glibc
Version      : 2.39 # 可以看到CentOS Stream 10的glibc版本是2.39
Release      : 37.el10
Architecture : x86_64
Size         : 6.2 M
Source       : glibc-2.39-37.el10.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPL-2.1-or-later AND SunPro AND LGPL-2.1-or-later WITH GCC-exception-2.0 AND BSD-3-Clause AND: GPL-2.0-or-later AND LGPL-2.1-or-later WITH GNU-compiler-exception AND GPL-2.0-only AND ISC AND: LicenseRef-Fedora-Public-Domain AND HPND AND CMU-Mach AND LGPL-2.1-only AND LGPL-2.0-or-later AND: Unicode-DFS-2015 AND GFDL-1.1-or-later AND GPL-1.0-or-later AND FSFUL AND MIT AND Inner-Net-2.0 AND: X11 AND GPL-2.0-or-later WITH GCC-exception-2.0 AND GFDL-1.3-only AND GFDL-1.1-only
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.[root@centos9 ~]# dnf info glibc
Last metadata expiration check: 0:00:55 ago on Fri 25 Apr 2025 06:53:50 PM CST.
Installed Packages
Name         : glibc
Version      : 2.34 # 可以看到CentOS Stream 9的glibc版本是2.34
Release      : 184.el9
Architecture : x86_64
Size         : 6.1 M
Source       : glibc-2.34-184.el9.src.rpm
Repository   : @System
From repo    : baseos
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@centos8 ~]# dnf info glibc
Last metadata expiration check: 0:02:56 ago on Fri 25 Apr 2025 07:43:16 PM CST.
Installed Packages
Name         : glibc
Version      : 2.28 # 可以看到CentOS Stream 8的glibc版本是2.28
Release      : 251.el8
Architecture : x86_64
Size         : 6.6 M
Source       : glibc-2.28-251.el8.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
... [root@centos7 ~]# yum info glibc
Loaded plugins: fastestmirror
Repository 'mysql' is missing name in configuration, using id
Loading mirror speeds from cached hostfile
Installed Packages
Name        : glibc
Arch        : x86_64
Version     : 2.17 # 可以看到CentOS 7的glibc版本是2.17
Release     : 326.el7_9
Size        : 13 M
Repo        : installed
From repo   : anaconda
Summary     : The GNU libc libraries
URL         : http://www.gnu.org/software/glibc/
License     : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+
Description : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@openeuler2403 ~]# yum info glibc
Last metadata expiration check: 0:03:19 ago on Fri 25 Apr 2025 08:21:42 PM CST.
Installed Packages
Name         : glibc
Version      : 2.38 # 可以看到openEuler 24.03的glibc版本是2.38
Release      : 47.oe2403sp1
Architecture : x86_64
Size         : 11 M
Source       : glibc-2.38-47.oe2403sp1.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and: Inner-Net-2.0 and ISC and Public Domain and GFDL-1.3-only
Description  : The GNU C Library project provides the core libraries for the GNU system and: GNU/Linux systems, as well as many other systems that use Linux as the kernel.: These libraries provide critical APIs including ISO C11, POSIX.1-2008, BSD,: OS-specific APIs and more. These APIs include such foundational facilities as: open, read, write, malloc, printf, getaddrinfo, dlopen, pthread_create, crypt,:  login, exit and more.
...[root@openeuler2203 ~]# yum info glibc
Last metadata expiration check: 0:01:16 ago on Fri 25 Apr 2025 08:40:01 PM CST.
Installed Packages
Name         : glibc
Version      : 2.34 # 可以看到openEuler 22.03的glibc版本是2.34
Release      : 152.oe2203sp4
Architecture : x86_64
Size         : 11 M
Source       : glibc-2.34-152.oe2203sp4.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The GNU C Library project provides the core libraries for the GNU system and: GNU/Linux systems, as well as many other systems that use Linux as the kernel.: These libraries provide critical APIs including ISO C11, POSIX.1-2008, BSD,: OS-specific APIs and more. These APIs include such foundational facilities as: open, read, write, malloc, printf, getaddrinfo, dlopen, pthread_create, crypt,:  login, exit and more.
...[root@anolisos23 ~]# yum info glibc
Last metadata expiration check: 0:01:02 ago on Fri Apr 25 20:58:58 2025.
Installed Packages
Name         : glibc
Version      : 2.38 # 可以看到AnolisOS 23的glibc版本是2.38
Release      : 5.an23
Architecture : x86_64
Size         : 7.4 M
Source       : glibc-2.38-5.an23.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system.: In order to save disk space and memory, as well as to make upgrading easier,: common system code is kept in one place and shared between programs.: This particular package contains the most important sets of shared libraries:: the standard C library and the standard math library.: Without these two libraries, a Linux system will not function.
...[root@anolis8 ~]# yum info glibc
Last metadata expiration check: 0:01:16 ago on Sat 26 Apr 2025 05:10:03 AM CST.
Installed Packages
Name         : glibc
Version      : 2.28 # 可以看到AnolisOS 8的glibc版本是2.28
Release      : 236.0.1.an8.8
Architecture : x86_64
Size         : 6.4 M
Source       : glibc-2.28-236.0.1.an8.8.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@opencloudos9 ~]# yum info glibc
Last metadata expiration check: 0:00:46 ago on Fri 25 Apr 2025 09:36:03 PM CST.
Installed Packages
Name         : glibc
Version      : 2.38 # 可以看到OpenCloudOS 9的glibc版本是2.38
Release      : 29.oc9
Architecture : x86_64
Size         : 6.6 M
Source       : glibc-2.38-29.oc9.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The GNU C Library project provides the core libraries for the GNU: system and GNU/Linux systems, as well as many other systems that use: Linux as the kernel. These libraries provide critical APIs including: ISO C11, POSIX.1-2008, BSD, OS-specific APIs and more. These APIs: include such foundational facilities as open, read, write, malloc,: printf, getaddrinfo, dlopen, pthread_create, crypt, login, exit and more.[root@opencloudos8 ~]# yum info glibc
Last metadata expiration check: 0:00:45 ago on Sat 26 Apr 2025 05:54:03 AM CST.
Installed Packages
Name         : glibc
Version      : 2.28 # 可以看到OpenCloudOS 9的glibc版本是2.28
Release      : 251.oc8.5.ap.1
Architecture : x86_64
Size         : 6.6 M
Source       : glibc-2.28-251.oc8.5.ap.1.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The glibc package contains standard libraries which are used by: multiple programs on the system. In order to save disk space and: memory, as well as to make upgrading easier, common system code is: kept in one place and shared between programs. This particular package: contains the most important sets of shared libraries: the standard C: library and the standard math library. Without these two libraries, a: Linux system will not function.
...[root@kylin10 ~]# yum info glibc
Last metadata expiration check: 0:03:30 ago on Fri 25 Apr 2025 10:10:26 PM CST.
Installed Packages
Name         : glibc
Version      : 2.28 # 可以看到Kylin Server v10的glibc版本是2.28
Release      : 98.p02.ky10
Architecture : x86_64
Size         : 11 M
Source       : glibc-2.28-98.p02.ky10.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The GNU C Library project provides the core libraries for the GNU system and: GNU/Linux systems, as well as many other systems that use Linux as the kernel.: These libraries provide critical APIs including ISO C11, POSIX.1-2008, BSD,: OS-specific APIs and more. These APIs include such foundational facilities as: open, read, write, malloc, printf, getaddrinfo, dlopen, pthread_create, crypt,:  login, exit and more.
...[root@uos20 ~]# yum info glibc
Last metadata expiration check: 0:00:51 ago on Fri 25 Apr 2025 10:26:30 PM CST.
Installed Packages
Name         : glibc
Version      : 2.28 # 可以看到Uos Server v10的glibc版本是2.28
Release      : 97.uel20.07
Architecture : x86_64
Size         : 13 M
Source       : glibc-2.28-97.uel20.07.src.rpm
Repository   : @System
From repo    : anaconda
Summary      : The GNU libc libraries
URL          : http://www.gnu.org/software/glibc/
License      : LGPLv2+ and LGPLv2+ with exceptions and GPLv2+ and GPLv2+ with exceptions and BSD and Inner-Net: and ISC and Public Domain and GFDL
Description  : The GNU C Library project provides the core libraries for the GNU system and: GNU/Linux systems, as well as many other systems that use Linux as the kernel.: These libraries provide critical APIs including ISO C11, POSIX.1-2008, BSD,: OS-specific APIs and more. These APIs include such foundational facilities as: open, read, write, malloc, printf, getaddrinfo, dlopen, pthread_create, crypt,:  login, exit and more.opensuse15:~ # zypper info glibc
Loading repository data...
Reading installed packages...Information for package glibc:
------------------------------
Repository     : mirror-sle-update
Name           : glibc
Version        : 2.38-150600.14.26.1 # 可以看到openSUSE 15的glibc版本是2.38
Arch           : x86_64
Vendor         : SUSE LLC <https://www.suse.com/>
Installed Size : 6.5 MiB
Installed      : Yes
Status         : out-of-date (version 2.38-150600.12.1 installed)
Source package : glibc-2.38-150600.14.26.1.src
Upstream URL   : https://www.gnu.org/software/libc/libc.html
Summary        : Standard Shared Libraries (from the GNU C Library)
Description    : The GNU C Library provides the most important standard libraries usedby nearly all programs: the standard C library, the standard mathlibrary, and the POSIX thread library. A system is not functionalwithout these libraries.root@ubuntu2404:~# ldd --version
ldd (Ubuntu GLIBC 2.39-0ubuntu8.4) 2.39 # 可以看到Ubuntu 24.04的glibc版本是2.39
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.root@ubuntu2204:~# ldd --version
ldd (Ubuntu GLIBC 2.35-0ubuntu3.6) 2.35 # 可以看到Ubuntu 22.04的glibc版本是2.35
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.raymond@ubuntu2004:~$ ldd --version
ldd (Ubuntu GLIBC 2.31-0ubuntu9.9) 2.31 # 可以看到Ubuntu 20.04的glibc版本是2.31
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.raymond@ubuntu1804:~$ ldd --version
ldd (Ubuntu GLIBC 2.27-3ubuntu1.4) 2.27 # 可以看到Ubuntu 18.04的glibc版本是2.27
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.root@debian12:~# ldd --version
ldd (Debian GLIBC 2.36-9+deb12u9) 2.36 # 可以看到Debian 12的glibc版本是2.36
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.root@debian11:~# ldd --version
ldd (Debian GLIBC 2.31-13+deb11u11) 2.31 # 可以看到Debian 11的glibc版本是2.31
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

显示当前主机的硬件架构类型:

[root@rocky9 ~]# arch
x86_64

根据操作系统的glibc版本去下载相应的安装包,这里系统版本选择“Linux - Generic (glibc 2.28) (x86, 64-bit)”,然后选择下面的“mysql-8.4.5-linux-glibc2.28-x86_64.tar.xz”包后面的“Download”进行下载,**注意:**glibc版本大于等于2.28的使用glibc 2.28版的MySQL二进制包,glibc版本小于2.28的使用glibc2.17版的MySQL二进制包,如图32所示。

t32

图32 下载MySQL二进制包

# Rocky、Almalinux、CentOS、openEuler、AnolisOS、OpenCloudOS、Kylin Server、Uos Server默认没有wget包,需要安装
yum install -y wget# openEuler 22.03/24.03、AnolisOS 23、OpenCloudOS 9没有安装tar包,需要安装
yum install -y tar# mysql 8.4.5 glibc2.28包
wget https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.5-linux-glibc2.28-x86_64.tar.xz
tar xf mysql-8.4.5-linux-glibc2.28-x86_64.tar.xz -C /usr/local
ln -s /usr/local/mysql-8.4.5-linux-glibc2.28-x86_64/ /usr/local/mysql# mysql 8.4.5 glibc2.17包
wget https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.5-linux-glibc2.17-x86_64.tar.xz
tar xf mysql-8.4.5-linux-glibc2.17-x86_64.tar.xz -C /usr/local
ln -s /usr/local/mysql-8.4.5-linux-glibc2.17-x86_64/ /usr/local/mysqlchown -R  mysql:mysql /usr/local/mysql/
2.3.2.3 准备环境变量
echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
2.3.2.4 准备配置文件
cat > /etc/my.cnf <<-EOF
[mysqld]
server-id=1
log-bin
datadir=/data/mysql
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid[client]
socket=/data/mysql/mysql.sock
EOF
2.3.2.5 生成数据库文件,并提取root密码
mkdir -p /data/mysqlchown -R mysql:mysql /data/mysql# /data/mysql  会自动生成,但是/data/必须事先存在
# --initialize会生成一个初始化密码,--initialize-insecure生成空密码,两种方式任选一种
mysqld --initialize --user=mysql --datadir=/data/mysqlgrep password /data/mysql/mysql.log
2025-04-22T14:36:39.157585Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: K39lgjhHlu:U
# "K39lgjhHlu:U"就是初始化密码# 生成空密码的root用户
mysqld --initialize-insecure --user=mysql --datadir=/data/mysql

Rocky 8/9/10、Almalinux 8/9/10、CentOS Stream 8/9/10、CentOS 7、openEuler 22.03/24.03、AnolisOS 8/23、OpenCloudOS 8/9:

mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory # 提示确少”libaio.so.1“文件yum install -y libaiomysqld --initialize-insecure --user=mysql --datadir=/data/mysql

Ubuntu 24.04:

mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directoryroot@ubuntu2404:~# apt search libaio
Sorting... Done
Full Text Search... Done
libaio-dev/noble-updates 0.3.113-6build1.1 amd64Linux kernel AIO access library - development fileslibaio1t64/noble-updates,now 0.3.113-6build1.1 amd64 [installed,automatic] # 可以看到libaio1t64包已经安装过了Linux kernel AIO access library - shared libraryln -s /usr/lib/x86_64-linux-gnu/libaio.so.1t64.0.2 /usr/lib/x86_64-linux-gnu/libaio.so.1mysqld --initialize-insecure --user=mysql --datadir=/data/mysql

Ubuntu 18.04:

mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directoryroot@ubuntu1804:~# apt search libaio
Sorting... Done
Full Text Search... Done
libaio-dev/bionic-updates 0.3.110-5ubuntu0.1 amd64Linux kernel AIO access library - development fileslibaio1/bionic-updates 0.3.110-5ubuntu0.1 amd64Linux kernel AIO access library - shared libraryapt install -y libaio1mysqld --initialize-insecure --user=mysql --datadir=/data/mysq

Debian 11/12:

root@debian12:~# mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directoryroot@debian12:~# apt search libaio
Sorting... Done
Full Text Search... Done
libaio-dev/stable 0.3.113-4 amd64Linux kernel AIO access library - development fileslibaio1/stable 0.3.113-4 amd64Linux kernel AIO access library - shared libraryapt install -y libaio1root@debian12:~# mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directoryroot@debian12:~# apt search libnuma
Sorting... Done
Full Text Search... Done
libnuma-dev/stable 2.0.16-1 amd64Development files for libnumalibnuma1/stable 2.0.16-1 amd64Libraries for controlling NUMA policyapt install -y libnuma1mysqld --initialize-insecure --user=mysql --datadir=/data/mysql
2.3.2.6 准备服务脚本和启动

Rocky、Almalinux、CentOS、openEuler、AnolisOS、OpenCloudOS、 Kylin Server、Uos Server、Ubuntu、Debian:

# Rocky 9/10、Almalinux 9/10、CentOS Stream 9/10默认没有chkconfig包,需要安装
yum install -y chkconfigcp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldcat > /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
EOFsystemctl daemon-reload && systemctl enable --now mysqld

openSUSE:

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld# openSUSE
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# openSUSE
ln -s /sbin/chkconfig  /usr/lib/systemd/systemd-sysv-install
chkconfig --add mysqldservice mysqld start
2.3.2.7 修改口令
# 如果使用的是空密码,就不需要修改口令
awk '/temporary password/{print $NF}' /data/mysql/mysql.log
aupYu;uhJ9&ymysqladmin -uroot -p'aupYu;uhJ9&y' password 123456
2.3.2.8 测试登录

Rocky 8/9、Almalinux 8/9、CentOS Stream 8/9/10、CentOS 7、openEuler 22.03/24.03、AnolisOS 8/23、OpenCloudOS 8/9、Kylin Server v10、Uos Server v20、Ubuntu 18.04/20.04/22.04/24.04、Debian 11、openSUSE:

[root@rocky10 ~]# mysql
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.4.5 MySQL Community Server - GPLCopyright (c) 2000, 2025, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> status
--------------
mysql  Ver 8.4.5 for Linux on x86_64 (MySQL Community Server - GPL)Connection id:		10
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.4.5 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/data/mysql/mysql.sock
Binary data as:		Hexadecimal
Uptime:			1 min 14 secThreads: 2  Questions: 9  Slow queries: 0  Opens: 130  Flush tables: 3  Open tables: 46  Queries per second avg: 0.121
--------------mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.01 sec)mysql> exit
Bye

Debian 12:

root@debian12:~# mysql
mysql: error while loading shared libraries: libncurses.so.6: cannot open shared object file: No such file or directoryroot@debian12:~# apt search libncurses6
Sorting... Done
Full Text Search... Done
libncurses6/stable 6.4-4 amd64shared libraries for terminal handlingapt install -y libncurses6root@debian12:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.5 MySQL Community Server - GPLCopyright (c) 2000, 2025, Oracle and/or its affiliates.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> status
--------------
mysql  Ver 8.4.5 for Linux on x86_64 (MySQL Community Server - GPL)Connection id:		8
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.4.5 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/data/mysql/mysql.sock
Binary data as:		Hexadecimal
Uptime:			3 min 5 secThreads: 2  Questions: 6  Slow queries: 0  Opens: 120  Flush tables: 3  Open tables: 36  Queries per second avg: 0.032
--------------mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)mysql> exit
Bye
2.3.2.9 一键安装MySQL 8.4二进制包的脚本

Shell脚本源码地址:

Gitee:https://gitee.com/raymond9/shell

Github:https://github.com/raymond999999/shell

可以去上面的Gitee或Github代码仓库拉取脚本。

# install_mysql_binary_v3.sh脚本创建的数据库是空密码。
[root@rocky10 ~]# cat install_mysql_8.4_binary_v3.sh
#!/bin/bash
#
#**********************************************************************************
#Author:        Raymond
#QQ:            88563128
#Date:          2025-06-10
#FileName:      install_mysql_8.4_binary_v3.sh
#URL:           https://wx.zsxq.com/group/15555885545422
#Description:   The mysql binary script install supports 
#               “Rocky Linux 8, 9 and 10, Almalinux 8, 9 and 10, CentOS 7, 
#               CentOS Stream 8, 9 and 10, openEuler 22.03 and 24.03, 
#               AnolisOS 8 and 23, OpencloudOS 8 and 9, Kylin Server v10, 
#               Uos Server v20, Ubuntu 18.04, 20.04, 22.04 and 24.04,  
#               Debian 11 and 12, openSUSE 15“ operating systems.
#Copyright (C): 2025 All rights reserved
#**********************************************************************************
COLOR="echo -e \\033[01;31m"
END='\033[0m'# mysql 8.4.5 glibc2.28包下载地址:"https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.5-linux-glibc2.28-x86_64.tar.xz"
# mysql 8.4.5 glibc2.17包下载地址:"https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.5-linux-glibc2.17-x86_64.tar.xz"DATA_DIR=/data/mysql
GLIBC_VERSION=2.28
MYSQL_URL=https://cdn.mysql.com//Downloads/MySQL-8.4/
MYSQL_FILE="mysql-8.4.5-linux-glibc${GLIBC_VERSION}-x86_64.tar.xz"os(){. /etc/os-releaseMAIN_NAME=`sed -rn '/^NAME=/s@.*="([[:alpha:]]+).*"$@\1@p' /etc/os-release`MAIN_VERSION_ID=`sed -rn '/^VERSION_ID=/s@.*="?([0-9]+)\.?.*"?@\1@p' /etc/os-release`if [ ${MAIN_NAME} == "Ubuntu" -o ${MAIN_NAME} == "Debian" ];thenFULL_NAME="${PRETTY_NAME}"elif [ ${MAIN_NAME} == "UOS" ];thenFULL_NAME="${NAME}"elseFULL_NAME="${NAME} ${VERSION_ID}"fi
}check_file(){if [ ${MAIN_NAME} == "Rocky" -o ${MAIN_NAME} == "AlmaLinux" -o ${MAIN_NAME} == "CentOS" -o ${MAIN_NAME} == "openEuler" -o ${MAIN_NAME} == "Anolis" -o ${MAIN_NAME} == "OpenCloudOS" -o ${MAIN_NAME} == "Kylin" -o ${MAIN_NAME} == "UOS" ];thenrpm -q wget &> /dev/null || { ${COLOR}"安装wget工具,请稍等......"${END};yum install -y wget &> /dev/null; }fiif [ ! -e ${MYSQL_FILE} ];then${COLOR}"缺少${MYSQL_FILE}文件"${END}${COLOR}'开始下载MySQL二进制安装包,请稍等......'${END}wget ${MYSQL_URL}${MYSQL_FILE} || { ${COLOR}"MySQL二进制安装包下载失败。"${END}; exit; }else${COLOR}"${MYSQL_FILE}文件已准备好。"${END}fi
}install_mysql(){[ -d /usr/local/mysql ] && { ${COLOR}"MySQL数据库已存在,安装失败!"${END};exit; }${COLOR}"开始安装MySQL数据库,请稍等......"${END}if [ ${MAIN_NAME} == "openSUSE" ];thenid mysql &> /dev/null || { groupadd -r mysql && useradd -s /sbin/nologin -r -g mysql mysql; ${COLOR}"成功创建mysql用户!"${END}; }elseid mysql &> /dev/null || { useradd -s /sbin/nologin -r mysql ; ${COLOR}"成功创建mysql用户!"${END}; }fiif [ ${MAIN_NAME} == "openEuler" ];thenif [ ${MAIN_VERSION_ID} == 22 -o ${MAIN_VERSION_ID} == 24 ];thenyum install -y tar &> /dev/nullfifiif [ ${MAIN_NAME} == "Anolis" ];thenif [ ${MAIN_VERSION_ID} == 23 ];thenyum install -y tar &> /dev/nullfifiif [ ${MAIN_NAME} == "OpenCloudOS" ];thenif [ ${MAIN_VERSION_ID} == 9 ];thenyum install -y tar &> /dev/nullfifitar xf ${MYSQL_FILE} -C /usr/local/MYSQL_DIR=`echo ${MYSQL_FILE}| sed -nr 's/^(.*[0-9]).*/\1/p'`ln -s /usr/local/${MYSQL_DIR} /usr/local/mysqlchown -R mysql:mysql /usr/local/mysql/echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh. /etc/profile.d/mysql.shcat > /etc/my.cnf <<-EOF
[mysqld]
server-id=1
log-bin
datadir=${DATA_DIR}
socket=${DATA_DIR}/mysql.sock
log-error=${DATA_DIR}/mysql.log
pid-file=${DATA_DIR}/mysql.pid[client]
socket=${DATA_DIR}/mysql.sock
EOF[ -d ${DATA_DIR} ] || mkdir -p ${DATA_DIR} &> /dev/nullchown -R mysql:mysql ${DATA_DIR}if [ ${MAIN_NAME} == "Rocky" -o ${MAIN_NAME} == "AlmaLinux" -o ${MAIN_NAME} == "CentOS" -o ${MAIN_NAME} == "openEuler" -o ${MAIN_NAME} == "Anolis" -o ${MAIN_NAME} == "OpenCloudOS" ];thenyum install -y libaio &> /dev/nullfiif [ ${MAIN_NAME} == "Ubuntu" ];thenif [ ${MAIN_VERSION_ID} == 24 ];thenln -s /usr/lib/x86_64-linux-gnu/libaio.so.1t64.0.2 /usr/lib/x86_64-linux-gnu/libaio.so.1fiif [ ${MAIN_VERSION_ID} == 18 ];thenapt update &> /dev/null;apt install -y libaio1 &> /dev/nullfifiif [ ${MAIN_NAME} == "Debian" ];thenif [ ${MAIN_VERSION_ID} == 11 -o ${MAIN_VERSION_ID} == 12 ];thenapt update &> /dev/null;apt install -y libaio1 libnuma1 &> /dev/nullfiif [ ${MAIN_VERSION_ID} == 12 ];thenapt update &> /dev/null;apt install -y libncurses6 &> /dev/nullfifimysqld --initialize-insecure --user=mysql --datadir=${DATA_DIR}if [ ${MAIN_NAME} == "Rocky" ];thenif [ ${MAIN_VERSION_ID} == 9 -o ${MAIN_VERSION_ID} == 10 ];thenyum install -y chkconfig &> /dev/nullfifiif [ ${MAIN_NAME} == "AlmaLinux" ];thenif [ ${MAIN_VERSION_ID} == 9 -o ${MAIN_VERSION_ID} == 10 ];thenyum install -y chkconfig &> /dev/nullfifiif [ ${MAIN_NAME} == "CentOS" ];thenif [ ${MAIN_VERSION_ID} == 9 -o ${MAIN_VERSION_ID} == 10 ];thenyum install -y chkconfig &> /dev/nullfificp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqldif [ ${MAIN_NAME} == "openSUSE" ];thencat > /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
EOFln -s /sbin/chkconfig  /usr/lib/systemd/systemd-sysv-installchkconfig --add mysqld  &> /dev/nullservice mysqld startelsecat > /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
EOFsystemctl daemon-reload && systemctl enable --now mysqld &> /dev/nullfi[ $? -ne 0 ] && { ${COLOR}"数据库启动失败,退出!"${END};exit; }${COLOR}"${FULL_NAME}操作系统,MySQL数据库安装完成!"${END}
}main(){oscheck_fileinstall_mysql
}main
http://www.lryc.cn/news/594875.html

相关文章:

  • 图论(2):最短路
  • 基于deepseek的LORA微调
  • 【深度学习新浪潮】如何系统性地学习扩散模型?
  • 分布式定时任务系列13:死循环是任务触发的银弹?
  • uniapp 输入时动态修改值(如含单位)光标被强制移至末尾
  • docker 软件bug 误导他人 笔记
  • 装饰器模式分析
  • java解析nc气象数据
  • numpy库的基础知识
  • 用Dify构建气象智能体:从0到1搭建AI工作流实战指南
  • React-useEffect的闭包陷阱(stale closure)
  • react 录音功能
  • 《Linux 环境下 Nginx 多站点综合实践:域名解析、访问控制与 HTTPS 加密部署》​
  • 大模型——Prompt 优化还是模型微调
  • Ubuntu 22.04 安装 Docker (安装包形式)
  • WPF 项目设置应用程序图标和设置程序集图标
  • 移星科技 modbus-tcp 转 modbus-Rtu模块
  • (数据结构)线性表(中):SLIst单链表
  • tcpdump 命令解析(随手记)
  • IOPaint+CPolar:零公网IP也能搭建专属AI图像编辑平台
  • 高级技术【Java】【反射】【注解】【动态代理】
  • 复习博客:JVM
  • 【Project】ELK 7.17.16 日志分析系统部署
  • 阿里云平台使用的ack创建的pod与服务器中的MongoDB不在同一网段如何解决
  • 【图像处理基石】什么是相机的内外参数?
  • 单表查询-分页提前获取数据
  • 自动化与安全 - 将 Terraform 集成到 CI/CD
  • 安装pytorch(cpu版)
  • 电科金仓2025发布会,国产数据库的AI融合进化与智领未来
  • 【Lucene】SimScorer