安装包下载:https://dev.mysql.com/downloads/mysql/

Centos7.9 RPM方式安装 MySQL8.4_Server

卸载mysql-libs

[root@ora11 fra]# yum remove mysql-libs
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-9.el7.x86_64
--> Running transaction check
---> Package postfix.x86_64 2:2.10.1-9.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================================================================================
 Package                                       Arch                                    Version                                           Repository                                  Size
==========================================================================================================================================================================================
Removing:
 mariadb-libs                                  x86_64                                  1:5.5.68-1.el7                                    @anaconda                                  4.4 M
Removing for dependencies:
 postfix                                       x86_64                                  2:2.10.1-9.el7                                    @anaconda                                   12 M

Transaction Summary
==========================================================================================================================================================================================
Remove  1 Package (+1 Dependent package)

Installed size: 17 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 2:postfix-2.10.1-9.el7.x86_64                                                                                                                                          1/2
  Erasing    : 1:mariadb-libs-5.5.68-1.el7.x86_64                                                                                                                                     2/2
  Verifying  : 1:mariadb-libs-5.5.68-1.el7.x86_64                                                                                                                                     1/2
  Verifying  : 2:postfix-2.10.1-9.el7.x86_64                                                                                                                                          2/2

Removed:
  mariadb-libs.x86_64 1:5.5.68-1.el7

Dependency Removed:
  postfix.x86_64 2:2.10.1-9.el7

Complete!

解压安装包

[root@ora11 fra]# tar -xvf mysql-8.4.0-1.el7.x86_64.rpm-bundle.tar
mysql-community-client-8.4.0-1.el7.x86_64.rpm
mysql-community-client-plugins-8.4.0-1.el7.x86_64.rpm
mysql-community-common-8.4.0-1.el7.x86_64.rpm
mysql-community-debuginfo-8.4.0-1.el7.x86_64.rpm
mysql-community-devel-8.4.0-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.4.0-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.4.0-1.el7.x86_64.rpm
mysql-community-libs-8.4.0-1.el7.x86_64.rpm
mysql-community-libs-compat-8.4.0-1.el7.x86_64.rpm
mysql-community-server-8.4.0-1.el7.x86_64.rpm
mysql-community-server-debug-8.4.0-1.el7.x86_64.rpm
mysql-community-test-8.4.0-1.el7.x86_64.rpm

安装依赖包

yum install -y net-tools perl-Getopt-Long

rpm安装

[root@ora11 fra]# rpm -ivh mysql-community-common-8.4.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.4.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.4.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.4.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.4.0-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.4.0-1.el7.x86_64.rpm

warning: mysql-community-common-8.4.0-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-8.4.0-1.el################################# [100%]
[root@ora11 fra]# rpm -ivh mysql-community-client-plugins-8.4.0-1.el7.x86_64.rpm
warning: mysql-community-client-plugins-8.4.0-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-plugins-8.################################# [100%]
[root@ora11 fra]# rpm -ivh mysql-community-libs-8.4.0-1.el7.x86_64.rpm
warning: mysql-community-libs-8.4.0-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-8.4.0-1.el7 ################################# [100%]
[root@ora11 fra]# rpm -ivh mysql-community-client-8.4.0-1.el7.x86_64.rpm
warning: mysql-community-client-8.4.0-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-8.4.0-1.el################################# [100%]
[root@ora11 fra]# rpm -ivh mysql-community-icu-data-files-8.4.0-1.el7.x86_64.rpm
warning: mysql-community-icu-data-files-8.4.0-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-icu-data-files-8.################################# [100%]
[root@ora11 fra]# rpm -ivh mysql-community-server-8.4.0-1.el7.x86_64.rpm
warning: mysql-community-server-8.4.0-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-8.4.0-1.el################################# [100%]

检查版本

[root@ora11 fra]# mysql --version
mysql  Ver 8.4.0 for Linux on x86_64 (MySQL Community Server - GPL)

修改配置文件

#创建目录
mkdir -p /mysql/log
mkdir -p /mysql/data
chown -R mysql:mysql /mysql

#关闭selinux
sed -i 's/SELINUX\=enforcing/SELINUX\=disabled/g' /etc/selinux/config
setenforce 0

#修改配置文件
vi /etc/my.cnf

datadir=/mysql/data
log-error=/mysql/log/mysqld.log
mysql_native_password=ON

初始化数据库

[root@ora11 fra]# mysqld --initialize --user=mysql

启动服务

[root@ora11 fra]# systemctl start mysqld
[root@ora11 fra]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2024-05-31 15:21:32 CST; 3s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 52620 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 52650 (mysqld)
   Status: "Server is operational"
    Tasks: 36
   CGroup: /system.slice/mysqld.service
           └─52650 /usr/sbin/mysqld

May 31 15:21:31 ora11 systemd[1]: Starting MySQL Server...
May 31 15:21:32 ora11 systemd[1]: Started MySQL Server.

检查开机启动

[root@ora11 fra]# systemctl list-unit-files|grep mysqld.service
mysqld.service                                enabled

修改初始密码

[root@ora11 fra]# cat /var/log/mysqld.log
2024-05-31T07:21:20.813057Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2024-05-31T07:21:20.814991Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.4.0) initializing of server in progress as process 52564
2024-05-31T07:21:20.828105Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2024-05-31T07:21:21.181657Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2024-05-31T07:21:21.695447Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: %Yd#rNHRt2mg
2024-05-31T07:21:23.111270Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.
[root@ora11 fra]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.4.0

Copyright (c) 2000, 2024, 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> alter user 'root'@'localhost' identified by 'abc123';
Query OK, 0 rows affected (0.00 sec)

mysql>