Centos8使用yum安装Mysql

1、添加mysql的yum库

1、转到MySQL yum repository的下载页面https://dev.mysql.com/downloads/repo/yum/
下载你需要的文件
在这里插入图片描述

2、上传文件到服务器,使用命令来配置

示例:

shell> sudo rpm -Uvh platform-and-version-specific-package-name.rpm

因为我下载的是mysql80-community-release-el8-1.noarch.rpm,所以命令为:

shell> sudo rpm -Uvh mysql80-community-release-el8-1.noarch.rpm

在这里插入图片描述

3、选择要安装的版本

如图,你不想安装mysql80-community,而是想选择mysql57-community。可以选择以下三种中任意一种方式进行操作:

注: 在任何时候应该只有一个发行版系列被启用。当为多个版本系列时,yum将使用最新的系列。
在这里插入图片描述
方式一、使用yum config manager来修改
命令如下:

shell> sudo yum-config-manager --disable mysql80-community
shell> sudo yum-config-manager --enable mysql57-community

方式二、通过dnf config manager命令来修改
命令如下:

shell> sudo dnf config-manager --disable mysql80-community
shell> sudo dnf config-manager --enable mysql57-community

方式三、修改配置文件 /etc/yum.repos.d/mysql-community.repo
经典条目为:

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

现在需要做的是将mysql80-community中enabled=1设置为0,将mysql57-community中enabled=0变更为1

# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

4、对于启用dnf的系统,请将命令中的yum替换为dnf

shell> yum repolist enabled | grep mysql

对于centos8、RHEL8 和 Oracle Linux 8还需要进行其他操作:
官方解释如下:(EL8 systems only) EL8-based systems such as RHEL8 and Oracle Linux 8 include a MySQL module that is enabled by default. Unless this module is disabled, it masks packages provided by MySQL repositories. To disable the included module and make the MySQL repository packages visible, use the following command (for dnf-enabled systems, replace yum in the command with dnf)
意思是:(仅限EL8系统)基于EL8的系统(如RHEL8和oracle linux8)包含默认启用的MySQL模块。除非禁用此模块,否则它将屏蔽MySQL存储库提供的包。要禁用包含的模块并使MySQL存储库包可见,请使用以下命令(对于启用dnf的系统,请将命令中的yum替换为dnf)
需要执行命令:

shell> sudo yum module disable mysql

5、安装mysql

执行

shell> sudo yum install mysql-community-server

正常安装

6、启动并修改数据库密码

6.1、启动,查看状态

shell> systemctl start mysqld  #启动数据库
shell> systemctl status mysqld #查看数据库状态

在这里插入图片描述
6.2、修改密码
注: 默认情况下安装MySQL的validate_password 密码插件。这将要求密码至少包含一个大写字母、一个小写字母、一个数字和一个特殊字符,并且密码总长度至少为8个字符。

  • 获取默认密码:
[root@node-1 opt]# sudo grep 'temporary password' /var/log/mysqld.log
2021-01-09T10:48:13.359235Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: rDEi!W,>V5rS
[root@node-1 opt]# 
  • 输入密码进入数据库修改密码并用新密码进入数据库
    修改语句为:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';

示例:

[root@node-1 opt]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.22

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
Query OK, 0 rows affected (0.05 sec)

mysql> exit
Bye
[root@node-1 opt]# 
[root@node-1 opt]# 
[root@node-1 opt]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.22 MySQL Community Server - GPL

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> exit
Bye
[root@node-1 opt]# 

参考文档:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值