一、环境部署

1、红帽为:Red Hat Enterprise Linux 9.3 64 位

如果之前安装过本地镜像版本的MySQL软件,请先删除之前的安装

[root@localhost ~]# dnf remove mysql-server -y

[root@localhost ~]# rm -rf /var/lib/mysql

[root@localhost ~]# rm -rf /var/log/mysql

[root@localhost ~]# userdel -r mysql

二、查找MySQL的命令

[root@localhost ~]# dnf repolist enabled | grep mysql mysql-connectors-community MySQL Connectors Community mysql-tools-communityMySQL Tools Community mysql80-community MySQL 8.0 Community Server

三、 安装MySQL服务器

[root@localhost ~]# dnf install mysql-server -y 结果: Updating Subscription Management repositories. Unable to read consumer identity This system is not registered with an entitlement server. You can use subscription-manager to register. Last metadata expiration check: 5 :09:04 ago on Wed 03 Jan 2024 11 :28:41 AM CST. Dependencies resolved. ================================================================================= ===================================== Package Architecture Version Repository Size ================================================================================= ===================================== Installing: mysql-community-server x86_64 8 .0.35-1.el9 mysql80-community 49 M Installing dependencies: mysql-community-client x86_64 8 .0.35-1.el9 mysql80-community 3 .5 M mysql-community-client-plugins x86_64 8 .0.35-1.el9 mysql80-community 1 .4 M mysql-community-common x86_64 8 .0.35-1.el9 mysql80-community 557 k mysql-community-icu-data-files x86_64 8 .0.35-1.el9 mysql80-community 2 .3 M mysql-community-libs x86_64 8 .0.35-1.el9 mysql80-community 1 .4 M Transaction Summary ================================================================================= ===================================== Install 6 Packages Total download size: 58 M Installed size: 334 M Downloading Packages: (1/6): mysql-community-common-8.0.35-1.el9.x86_64.rpm 246 kB/s | 557 kB 00 :02 (2/6): mysql-community-client-plugins-8.0.35-1.el9.x86_64.rpm 611 kB/s | 1 .4 MB 00 :02 (3/6): mysql-community-libs-8.0.35-1.el9.x86_64.rpm 2 .5 MB/s | 1 .4 MB 00 :00 (4/6): mysql-community-icu-data-files-8.0.35-1.el9.x86_64.rpm 2 .1 MB/s | 2 .3 MB 00 :01 (5/6): mysql-community-client-8.0.35-1.el9.x86_64.rpm 733 kB/s | 3 .5 MB 00 :04 (6/6): mysql-community-server-8.0.35-1.el9.x86_64.rpm 6 .7 MB/s | 49 MB 00 :07 ——————————————————————————— ————————————- Total 5 .7 MB/s | 58 MB 00 :10 MySQL 8 .0 Community Server 2 .9 MB/s | 3 .1 kB 00 :00 Importing GPG key 0xA8D3785C: Userid : “MySQL Release Engineering ” Fingerprint: BCA4 3417 C3B4 85DD 128E C6D4 B7B3 B788 A8D3 785C From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2023 Key imported successfully MySQL 8 .0 Community Server 2 .0 MB/s | 3 .1 kB 00 :00 Importing GPG key 0x3A79BD29: Userid : “MySQL Release Engineering ” Fingerprint: 859B E8D7 C586 F538 430B 19C2 467B 942D 3A79 BD29 From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022 Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1 /1 Installing : mysql-community-common-8.0.35-1.el9.x86_64 1 /6 Installing : mysql-community-client-plugins-8.0.35-1.el9.x86_64 2 /6 Installing : mysql-community-libs-8.0.35-1.el9.x86_64 3 /6 Running scriptlet: mysql-community-libs-8.0.35-1.el9.x86_64 3 /6 Installing : mysql-community-client-8.0.35-1.el9.x86_64 4 /6 Installing : mysql-community-icu-data-files-8.0.35-1.el9.x86_64 5 /6 Running scriptlet: mysql-community-server-8.0.35-1.el9.x86_64 6 /6 Installing : mysql-community-server-8.0.35-1.el9.x86_64 6 /6 Running scriptlet: mysql-community-server-8.0.35-1.el9.x86_64 6 /6 Verifying : mysql-community-client-8.0.35-1.el9.x86_64 1 /6 Verifying : mysql-community-client-plugins-8.0.35-1.el9.x86_64 2 /6 Verifying : mysql-community-common-8.0.35-1.el9.x86_64 3 /6 Verifying : mysql-community-icu-data-files-8.0.35-1.el9.x86_64 4 /6 Verifying : mysql-community-libs-8.0.35-1.el9.x86_64 5 /6 Verifying : mysql-community-server-8.0.35-1.el9.x86_64 6 /6 Installed products updated. Installed: mysql-community-client-8.0.35-1.el9.x86_64 mysql-community-client plugins-8.0.35-1.el9.x86_64 mysql-community-common-8.0.35-1.el9.x86_64 mysql-community-icu-data files-8.0.35-1.el9.x86_64 mysql-community-libs-8.0.35-1.el9.x86_64 mysql-community-server- 8.0.35-1.el9.x86_64 Complete! 当看到completel表示完成。

四、启动

[root@localhost ~]# systemctl start mysqld

五、查看密钥

2024-01-03T08:38:42.943965Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: t5BLwdq*orTp

六、登录MySQL

[root@localhost ~]# mysql -uroot -p Enter password:

七、输入密钥

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8 .0.35Oracle 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>

八、改密码

mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘MyNewPass4!’;

完成