当前位置:   article > 正文

Centos8使用yum安装Mysql_centos8 yum安装mysql

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
  • 1

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

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

在这里插入图片描述

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
  • 1
  • 2

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

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

方式三、修改配置文件 /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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

现在需要做的是将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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

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

shell> yum repolist enabled | grep mysql
  • 1

对于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
  • 1

5、安装mysql

执行

shell> sudo yum install mysql-community-server
  • 1

正常安装

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

6.1、启动,查看状态

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

在这里插入图片描述
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]# 
  • 1
  • 2
  • 3
  • 输入密码进入数据库修改密码并用新密码进入数据库
    修改语句为:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
  • 1

示例:

[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]# 

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/301289
推荐阅读
相关标签
  

闽ICP备14008679号