1、创建/usr/local/mysql8目录,用于存放mysql8。
mkdir /usr/local/mysql8
cd /usr/local/mysql8
2、下载mysql安装包
wget https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
1、执行命令安装mysql
yum -y install mysql80-community-release-el7-2.noarch.rpm
发生报错,报错内容如下:
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist 无法下载 repo 'appstream' 的元数据:无法准备内部镜像列表:镜像列表中没有 URL
2、执行以下命令从CentOS 8 迁移到CentOS Stream 8,解决上述问题。
dnf --disablerepo '*' --enablerepo=extras swap centos-linux-repos centos-stream-repos
3、迁移完成后,继续执行以下命令安装mysql。
yum -y install mysql80-community-release-el7-2.noarch.rpm
4、执行以下命令下载
yum -y install mysql-community-server
报错内容如下:
[root@localhost mysql8]# yum -y install mysql-community-server MySQL 8.0 Community Server 972 kB/s | 2.4 MB 00:02 MySQL Connectors Community 52 kB/s | 51 kB 00:00 MySQL Tools Community 380 kB/s | 711 kB 00:01 All matches were filtered out by modular filtering for argument: mysql-community-server Error: Unable to find a match: mysql-community-server
5、针对步骤4出现"无法匹配"的问题,解决方式如下:
5.1、执行以下命令关闭centos8本地的mysql模块。
yum module disable mysql
执行结果:[root@localhost mysql8]# yum module disable mysql Last metadata expiration check: 0:00:52 ago on Wed 14 Sep 2022 11:28:18 AM CST. Dependencies resolved. ================================================================================ Package Architecture Version Repository Size ================================================================================ Disabling modules: mysql Transaction Summary ================================================================================ Is this ok [y/N]: y Complete!
5.2、执行yum -y install mysql-community-server --nogpgcheck命令在禁止进行gpg check的情况下继续进行安装。
yum -y install mysql-community-server --nogpgcheck
执行结果:
[root@localhost mysql8]# yum -y install mysql-community-server --nogpgcheck Last metadata expiration check: 0:04:24 ago on Wed 14 Sep 2022 11:28:18 AM CST. Dependencies resolved. ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: mysql-community-server x86_64 8.0.30-1.el7 mysql80-community 54 M Installing dependencies: compat-openssl10 x86_64 1:1.0.2o-4.el8 appstream 1.1 M mysql-community-client x86_64 8.0.30-1.el7 mysql80-community 14 M mysql-community-client-plugins x86_64 8.0.30-1.el7 mysql80-community 2.5 M mysql-community-common x86_64 8.0.30-1.el7 mysql80-community 645 k mysql-community-icu-data-files x86_64 8.0.30-1.el7 mysql80-community 2.1 M mysql-community-libs x86_64 8.0.30-1.el7 mysql80-community 1.5 M ncurses-compat-libs x86_64 6.1-9.20180224.el8 baseos 328 k Transaction Summary ================================================================================ Install 8 Packages Total size: 76 M Installed size: 351 M Downloading Packages: [SKIPPED] compat-openssl10-1.0.2o-4.el8.x86_64.rpm: Already downloaded [SKIPPED] ncurses-compat-libs-6.1-9.20180224.el8.x86_64.rpm: Already downloaded [SKIPPED] mysql-community-client-8.0.30-1.el7.x86_64.rpm: Already downloaded [SKIPPED] mysql-community-client-plugins-8.0.30-1.el7.x86_64.rpm: Already downloaded [SKIPPED] mysql-community-common-8.0.30-1.el7.x86_64.rpm: Already downloaded [SKIPPED] mysql-community-icu-data-files-8.0.30-1.el7.x86_64.rpm: Already downloaded [SKIPPED] mysql-community-libs-8.0.30-1.el7.x86_64.rpm: Already downloaded [SKIPPED] mysql-community-server-8.0.30-1.el7.x86_64.rpm: Already downloaded Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : compat-openssl10-1:1.0.2o-4.el8.x86_64 1/8 Running scriptlet: compat-openssl10-1:1.0.2o-4.el8.x86_64 1/8 Installing : mysql-community-client-plugins-8.0.30-1.el7.x86_64 2/8 Installing : mysql-community-common-8.0.30-1.el7.x86_64 3/8 Installing : mysql-community-libs-8.0.30-1.el7.x86_64 4/8 Running scriptlet: mysql-community-libs-8.0.30-1.el7.x86_64 4/8 Installing : mysql-community-icu-data-files-8.0.30-1.el7.x86_64 5/8 Installing : ncurses-compat-libs-6.1-9.20180224.el8.x86_64 6/8 Installing : mysql-community-client-8.0.30-1.el7.x86_64 7/8 Running scriptlet: mysql-community-server-8.0.30-1.el7.x86_64 8/8 Installing : mysql-community-server-8.0.30-1.el7.x86_64 8/8 Running scriptlet: mysql-community-server-8.0.30-1.el7.x86_64 8/8 Verifying : compat-openssl10-1:1.0.2o-4.el8.x86_64 1/8 Verifying : ncurses-compat-libs-6.1-9.20180224.el8.x86_64 2/8 Verifying : mysql-community-client-8.0.30-1.el7.x86_64 3/8 Verifying : mysql-community-client-plugins-8.0.30-1.el7.x86_64 4/8 Verifying : mysql-community-common-8.0.30-1.el7.x86_64 5/8 Verifying : mysql-community-icu-data-files-8.0.30-1.el7.x86_64 6/8 Verifying : mysql-community-libs-8.0.30-1.el7.x86_64 7/8 Verifying : mysql-community-server-8.0.30-1.el7.x86_64 8/8 Installed: compat-openssl10-1:1.0.2o-4.el8.x86_64 mysql-community-client-8.0.30-1.el7.x86_64 mysql-community-client-plugins-8.0.30-1.el7.x86_64 mysql-community-common-8.0.30-1.el7.x86_64 mysql-community-icu-data-files-8.0.30-1.el7.x86_64 mysql-community-libs-8.0.30-1.el7.x86_64 mysql-community-server-8.0.30-1.el7.x86_64 ncurses-compat-libs-6.1-9.20180224.el8.x86_64 Complete!
1、执行命令启动数据库。
systemctl start mysqld.service
2、执行命令查看当前登录密码。
grep "password" /var/log/mysqld.log
执行结果:
[root@localhost ~]# grep "password" /var/log/mysqld.log 2022-09-14T03:33:50.871635Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: hfi-u/uXd5ma
3、执行命令登录mysql数据库。其中-u代表指定用户,-p代表指定密码。
mysql -u root -p
执行结果:
[root@localhost ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.30 Copyright (c) 2000, 2022, 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>
4、执行命令查看mysql状态。这里观察到,mysqld.service状态为active。
systemctl status mysqld.service
执行结果:
[root@localhost ~]# systemctl status mysqld.service ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: > Active: active (running) since Wed 2022-09-14 11:33:54 CST; 2h 53min ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 36779 (mysqld) Status: "Server is operational" Tasks: 39 (limit: 4636) Memory: 49.3M CGroup: /system.slice/mysqld.service └─36779 /usr/sbin/mysqld