方法一:使用本地仓库的方式进行安装(省时省力)
[root@localhost ~]# dnf install mysql-server
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 Source distribution
Copyright (c) 2000, 2023, 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>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
方法二:使用本地下载方式进行安装
链接地址:
https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.35-1.el9.x86_64.rpm-bundle.tar
第一步:下载mysql
[root@localhost ~]# cat /etc/redhat-release # 查看当前Linux版本
Red Hat Enterprise Linux release 9.3 (Plow)
[root@localhost ~]# ll
总用量 4
drwxr-xr-x. 2 root root 6 1月 8 11:39 公共
drwxr-xr-x. 2 root root 6 1月 8 11:39 模板
drwxr-xr-x. 2 root root 6 1月 8 11:39 视频
drwxr-xr-x. 2 root root 6 1月 8 11:39 图片
drwxr-xr-x. 2 root root 6 1月 8 11:39 文档
drwxr-xr-x. 2 root root 6 1月 8 11:39 下载
drwxr-xr-x. 2 root root 6 1月 8 11:39 音乐
drwxr-xr-x. 2 root root 6 1月 8 11:39 桌面
-rw-------. 1 root root 1354 1月 8 11:38 anaconda-ks.cfg
[root@localhost ~]# cd 下载/
[root@localhost 下载]# ll
总用量 0 # 从官方网站下载完以后,用xftp拖移到这个目录下
[root@localhost ~]# ll
总用量 4
drwxr-xr-x. 2 root root 6 1月 8 11:39 公共
drwxr-xr-x. 2 root root 6 1月 8 11:39 模板
drwxr-xr-x. 2 root root 6 1月 8 11:39 视频
drwxr-xr-x. 2 root root 6 1月 8 11:39 图片
drwxr-xr-x. 2 root root 6 1月 8 11:39 文档
drwxr-xr-x. 2 root root 6 1月 8 11:39 下载
drwxr-xr-x. 2 root root 6 1月 8 11:39 音乐
drwxr-xr-x. 2 root root 6 1月 8 11:39 桌面
-rw-------. 1 root root 1354 1月 8 11:38 anaconda-ks.cfg
[root@localhost ~]# cd 下载/
# 进入到下载目录下面
第二步:下载完成后进行解压
[root@localhost 下载]# tar xvf mysql-8.0.35-1.el9.x86_64.rpm-bundle.tar
选中挑选以上数据包
#[root@localhost mysql]# dnf localinstall mysql-community-server-8.0.35-
1.el9.x86_64.rpm \
mysql-community-client-8.0.35-1.el9.x86_64.rpm \
mysql-community-common-8.0.35-1.el9.x86_64.rpm \
mysql-community-icu-data-files-8.0.35-1.el9.x86_64.rpm \
mysql-community-client-plugins-8.0.35-1.el9.x86_64.rpm \
mysql-community-libs-8.0.35-1.el9.x86_64.rpm
[root@localhost mysql]# systemctl start mysqld # 启动
第三步:查看密码进行登录
1. [root@localhost mysql]# grep password /var/log/mysqld.log # 查看临时密码
2024-01-08T14:19:16.356413Z 6 [Note] [MY-010454] [Server] A temporarypassword is generated for root@localhost: Rwjyfwf56e!u2. [root@localhost mysql]# mysql -uroot -p
Enter password: # 输入临时密码
输入后就可以成功登录了,第一次登录后,在执行语句之前,必须使用ALTER USER语句重置密码
第五步:重置密码
mysql> alter user 'root'@'localhost' identified by '#Openlab123';
Query OK, 0 rows affected (0.01 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
成功登录