CentOS-9安装Mysql服务器(7/8/9通用)傻瓜式详解

MySQL 是一种广泛使用的开源关系型数据库管理系统,它可以存储和管理各种类型的数据,如文本,数字,日期,图像等。MySQL 8 是 MySQL 的最新版本,它提供了许多新的特性和改进,如窗口函数,通用表表达式,角色,JSON 支持等。

本文将介绍如何在 CentOS Stream 9 系统中安装 MySQL 8,并进行基本的配置和测试。

前提条件
在开始安装 MySQL 8 之前,您需要准备以下内容:

一台运行 CentOS Stream 9 的服务器,具有 root 权限或 sudo 权限的用户账户。
一个稳定的网络连接,可以访问 MySQL 的官方仓库和下载安装包。
至少 1 GB 的可用磁盘空间,用于存储 MySQL 的程序和数据文件。
安装步骤
以下是在 CentOS Stream 9 中安装 MySQL 8 的详细步骤:

更新系统软件包并安装必要的依赖包。在终端中执行以下命令:

sudo dnf update -y
sudo dnf install -y wget
1
2
下载 MySQL 的官方仓库配置文件,并将其保存到 /etc/yum.repos.d 目录中。在终端中执行以下命令:

wget https://repo.mysql.com/mysql80-community-release-el9-1.noarch.rpm
sudo rpm -ivh mysql80-community-release-el9-1.noarch.rpm
1
2
启用 MySQL 8 的仓库,并禁用其他版本的仓库。在终端中执行以下命令:

sudo dnf config-manager --disable mysql57-community
sudo dnf config-manager --disable mysql56-community
sudo dnf config-manager --enable mysql80-community
1
2
3
安装 MySQL 8 的软件包。在终端中执行以下命令:

sudo dnf install -y mysql-community-server
1
启动 MySQL 服务,并设置开机自启动。在终端中执行以下命令:

sudo systemctl start mysqld
sudo systemctl enable mysqld
1
2
查看 MySQL 服务的状态,确保它正在运行。在终端中执行以下命令:

sudo systemctl status mysqld
1
如果看到类似以下的输出,说明 MySQL 服务已经成功启动:

● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2023-12-15 16:10:23 CST; 2min 15s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 1234 (mysqld)
   Status: "Server is operational"
   CGroup: /system.slice/mysqld.service
           └─1234 /usr/sbin/mysqld
1
2
3
4
5
6
7
8
9
获取 MySQL 的初始临时密码,用于登录 MySQL 并修改密码。在终端中执行以下命令:

sudo grep 'temporary password' /var/log/mysqld.log
1
如果看到类似以下的输出,说明已经找到了初始临时密码:

2023-12-15T08:10:25.123456Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 7fjD#kL9x5a!
1
请记下这个密码,稍后会用到。

登录 MySQL 并修改密码。在终端中执行以下命令:

mysql -u root -p
1
输入刚才获取的初始临时密码,然后按回车键。如果看到类似以下的输出,说明已经成功登录 MySQL:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.27 MySQL Community Server - GPL

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>
1
2
3
4
5
6
7
8
9
10
11
12
13
在 MySQL 提示符下,执行以下命令,修改密码:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
1
其中,new_password 是您自己设定的新密码,需要符合 MySQL 的密码策略要求,比如长度,复杂度等。如果修改成功,您会看到类似以下的输出:

Query OK, 0 rows affected (0.01 sec)
1
然后,退出 MySQL 提示符,返回终端:

exit
1
重新登录 MySQL,使用新的密码。在终端中执行以下命令:

mysql -u root -p
1
输入新的密码,然后按回车键。如果看到类似以下的输出,说明已经成功登录 MySQL,并使用了新的密码:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.27 MySQL Community Server - GPL

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>
1
2
3
4
5
6
7
8
9
10
11
12
13
总结
本文介绍了如何在 CentOS Stream 9 系统中安装 MySQL 8,并进行基本的配置和测试。您可以根据您的需要,进一步修改 MySQL 的设置,如创建数据库,用户,授权,备份,恢复等。
————————————————

                            版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
                        
原文链接:https://blog.youkuaiyun.com/asd54090/article/details/141297909

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值