目录
一、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 环境规划
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 -y remove mariadb*
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文件
官网地址www.mysql.com , 利用wget下载
下载mysql80-community-release-el7-11.noarch.rpm
wget https://repo.mysql.com//mysql80-community-release-el7-11.noarch.rpm
// 下载地址来源如下几图
①
②
③
④
⑤
⑥
4.2 配置yum仓库
配置mysql的yum仓库
yum -y install mysql80-community-release-el7-11.noarch.rpm
// 这只是一个yum仓库文件
// 安装后,会在 /etc/yum.repos.d/ 里自动生成 mysql-community.repo (mysql主包,其实就是一个下载地址/yum仓库)
4.3 检查yum仓库状态
检查yum仓库状态
ls /etc/yum.repos.d/ -l
4.4 检查mysql版本
检查mysql默认安装版本
[root@harbor ~]# yum repolist enabled | grep mysql
!mysql-connectors-community/x86_64 MySQL Connectors Community 242
!mysql-tools-community/x86_64 MySQL Tools Community 104
!mysql80-community/x86_64 MySQL 8.0 Community Server 465
如果这里要下载5.7版本,进入该文件vim /etc/yum.repos.d/mysql-community.repo,把8.0版本的enabled=1改成0,把5.7版本的enabled=0改成1即可
五、安装MySQL8.0
5.1 安装mysql
使用yum直接安装mysql
yum install -y mysql-community-server
5.2 启动mysql服务
启动mysql服务,并设置开机自启。
systemctl enable mysqld --now
5.3 检查mysql服务状态
检查mysql服务状态
[root@harbor ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 六 2024-03-16 20:04:15 CST; 3h 27min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 11016 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 11095 (mysqld)
Status: "Server is operational"
Tasks: 38
Memory: 488.8M
CGroup: /system.slice/mysqld.service
└─11095 /usr/sbin/mysqld
3月 16 20:04:09 harbor systemd[1]: Starting MySQL Server...
3月 16 20:04:15 harbor systemd[1]: Started MySQL Server.
六、mysql的初始配置
6.1 获取登录密码
获取随机生成的登录密码(localhost: 后面就是默认密码)
[root@harbor ~]# grep 'temporary password' /var/log/mysqld.log
2024-03-16T12:04:11.762061Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: sdXLl8J&xp(g
mysql -uroot -p
6.3 修改本地用户密码
修改本地用户’root’@‘localhost’ 的密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Xielei@123';
密码修改后重新登录,登录成功
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>