Linux系统之安装MySQL8.0版本

在这里插入图片描述

一、MySQL介绍

1.1 MySQL简介

MySQL 8.0 是最新版本的 MySQL 数据库管理系统,是一种关系型数据库管理系统,由 Oracle 公司开发和维护。MySQL 8.0 带来了一系列新特性,包括多个性能提升,更好的安全性和扩展性,以及新的管理功能。

1.2 MySQL特点

  • 更好的性能:MySQL 8.0 提供了对于大型查询和事务处理的更好的性能支持。它引入了新的索引类型,如哈希索引,以提供更快的查询操作。

  • 更好的安全性:MySQL 8.0 引入了更好的密码验证规则,以保证用户账户的安全性。它还支持更强的加密,如 TLS 和 SSL。此外,它还提供了更好的访问控制机制,如基于角色的访问控制。

  • 更好的扩展性:MySQL 8.0 引入了新的数据字典架构,它使用了更高效的内存表来缓存表元数据信息,以提高性能。

  • 新的管理功能:MySQL 8.0 引入了新的管理功能,如 InnoDB 集成的全文搜索、更好的在线DDL 和 JSON 支持。

二、本次实践介绍

2.1 环境规划

本次实践环境为个人测试环境,使用操作系统为centos7.6。

hostname IP地址 系统版本 内核版本 mysql版本
jeven 192.168.3.166 centos7.6 3.10.0-957.el7.x86_64 mysql8.0.34

2.2 本次实践目的

1.在centos7.6系统下安装MySQL8.0版本。
2.可以远程登录mysql数据库。

三、卸载mariadb数据库

3.1 卸载mariadb数据库

如果系统上已安装有maraidb数据库,需要卸载mariadb

yum remove mariadb* -y
rm -rf /etc/my.cnf
rm -rf /var/lib/mysql/

3.2 卸载mysql数据库

如果系统已安装有其他版本的mysql,需提前卸载清空环境。


rpm -e mysql  // 普通删除模式
rpm -e --nodeps mysql  // 强力删除模式,
rm -rf /etc/my.cnf
rm -rf /var/lib/mysql/

四、配置yum仓库

4.1 下载rpm文件

下载mysql80-community-release-el7-7.noarch.rpm

wget https://repo.mysql.com//mysql80-community-release-el7-7.noarch.rpm

在这里插入图片描述

4.2 配置yum仓库

配置mysql的yum仓库

 sudo rpm -Uvh mysql80-community-release-el7-7.noarch.rpm

在这里插入图片描述

4.3 检查yum仓库状态

检查yum仓库状态

[root@jeven ~]# yum repolist all |grep enable
base/7/x86_64                                CentOS-7 - Base - m enabled: 10,072
extras/7/x86_64                              CentOS-7 - Extras - enabled:    518
mysql-connectors-community/x86_64            MySQL Connectors Co enabled:    227
mysql-tools-community/x86_64                 MySQL Tools Communi enabled:    100
mysql80-community/x86_64                     MySQL 8.0 Community enabled:    424
updates/7/x86_64                             CentOS-7 - Updates  enabled:  5,061

4.4 检查mysql版本

检查mysql默认安装版本

[root@jeven ~]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64 MySQL Connectors Community                 227
mysql-tools-community/x86_64      MySQL Tools Community                      100
mysql80-community/x86_64          MySQL 8.0 Community Server                 424

五、安装MySQL8.0

5.1 安装mysql

使用yum直接安装mysql

yum install mysql-community-server -y

在这里插入图片描述

5.2 启动mysql服务

启动mysql服务,并设置开机自启。

 systemctl enable --now mysqld

5.3 检查mysql服务状态

检查mysql服务状态

[root@jeven ~]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2023-07-23 19:37:31 CST; 35s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 117898 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 117971 (mysqld)
   Status: "Server is operational"
    Tasks: 38
   Memory: 472.2M
   CGroup: /system.slice/mysqld.service
           └─117971 /usr/sbin/mysqld

Jul 23 19:37:21 jeven systemd[1]: Starting MySQL Server...
Jul 23 19:37:31 jeven systemd[1]: Started MySQL Server.

六、mysql的初始配置

6.1 获取登录密码

获取随机生成的登录密码

[root@jeven ~]# grep 'temporary password' /var/log/mysqld.log
2023-07-23T11:37:25.670116Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Sw#rsuaMh4(I

6.2 本地登录mysql

本地使用生成的随机密码,登录mysql。

mysql -uroot -p

在这里插入图片描述

6.3 修改本地用户密码

修改本地用户’root’@‘localhost’ 的密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root.36#336';

在这里插入图片描述

6.4 新建远程登录用户

  • 设置用户密码策略的安全强度
set global validate_password.policy=LOW;
  • 设置密码长度不少于4
set global validate_password.length=4;
  • 查看密码策略
SHOW VARIABLES LIKE 'validate_password%';

在这里插入图片描述

  • 新建用户
create user 'admin'@'%' identified WITH mysql_native_password BY 'admin';
grant all on *.* to  'admin'@'%'    with GRANT OPTION;
flush privileges;

七、远程登录mysql

在其他mysql客户端远程登录mysql

[root@server ~]# mysql -h 192.168.3.166 -uadmin -padmin
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.34 MySQL Community Server - GPL

Copyright (c) 2000, 2018, 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>

猜你喜欢

转载自blog.csdn.net/jks212454/article/details/131882628