安装MySQL8数据库

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 本文介绍了MySQL的不同版本及其特点,并详细描述了如何通过Yum源安装MySQL 8.4社区版,包括配置Yum源、安装MySQL、启动服务、设置开机自启动、修改root用户密码以及设置远程登录等步骤。最后还提供了测试连接的方法。适用于初学者和运维人员。

安装MySQL8

MySQL Community Server 社区版本,开源免费,自由下载,但不提供官方技术支持,适用于大多数普通用户。

MySQL Enterprise Edition 企业版本,需付费,不能在线下载,可以试用30天。提供了更多的功能和更完备的技术支持,更适合于对数据库的功能和可靠性要求较高的企业客户。

MySQL Cluster 集群版,开源免费。用于架设集群服务器,可将几个MySQL Server封装成一个Server。需要在社区版或企业版的基础上使用。

MySQL Cluster CGE 高级集群版,需付费。

安装 mysql yum源

[root@web ~]# wget https://repo.mysql.com//mysql84-community-release-el9-1.noarch.rpm

[root@web ~]# yum install ./mysql84-community-release-el9-1.noarch.rpm 

[root@web ~]#

安装成功后,查看MySQL版本:

[root@web ~]# yum repolist all | grep mysql
mysql-8.4-lts-community                      MySQL 8.4 LTS Community Server 启用
mysql-8.4-lts-community-debuginfo            MySQL 8.4 LTS Community Server 禁用
mysql-8.4-lts-community-source               MySQL 8.4 LTS Community Server 禁用
mysql-cluster-8.0-community                  MySQL Cluster 8.0 Community    禁用
mysql-cluster-8.0-community-debuginfo        MySQL Cluster 8.0 Community -  禁用
mysql-cluster-8.0-community-source           MySQL Cluster 8.0 Community -  禁用
mysql-cluster-8.4-lts-community              MySQL Cluster 8.4 LTS Communit 禁用
mysql-cluster-8.4-lts-community-debuginfo    MySQL Cluster 8.4 LTS Communit 禁用
mysql-cluster-8.4-lts-community-source       MySQL Cluster 8.4 LTS Communit 禁用
mysql-cluster-innovation-community           MySQL Cluster Innovation Relea 禁用
mysql-cluster-innovation-community-debuginfo MySQL Cluster Innovation Relea 禁用
mysql-cluster-innovation-community-source    MySQL Cluster Innovation Relea 禁用
mysql-connectors-community                   MySQL Connectors Community     启用
mysql-connectors-community-debuginfo         MySQL Connectors Community - D 禁用
mysql-connectors-community-source            MySQL Connectors Community - S 禁用
mysql-innovation-community                   MySQL Innovation Release Commu 禁用
mysql-innovation-community-debuginfo         MySQL Innovation Release Commu 禁用
mysql-innovation-community-source            MySQL Innovation Release Commu 禁用
mysql-tools-8.4-lts-community                MySQL Tools 8.4 LTS Community  启用
mysql-tools-8.4-lts-community-debuginfo      MySQL Tools 8.4 LTS Community  禁用
mysql-tools-8.4-lts-community-source         MySQL Tools 8.4 LTS Community  禁用
mysql-tools-community                        MySQL Tools Community          禁用
mysql-tools-community-debuginfo              MySQL Tools Community - Debugi 禁用
mysql-tools-community-source                 MySQL Tools Community - Source 禁用
mysql-tools-innovation-community             MySQL Tools Innovation Communi 禁用
mysql-tools-innovation-community-debuginfo   MySQL Tools Innovation Communi 禁用
mysql-tools-innovation-community-source      MySQL Tools Innovation Communi 禁用
mysql80-community                            MySQL 8.0 Community Server     禁用
mysql80-community-debuginfo                  MySQL 8.0 Community Server - D 禁用
mysql80-community-source                     MySQL 8.0 Community Server - S 禁用
[root@web ~]#

安装MySQL

[root@web ~]# yum install mysql-community-server

启动MySQL服务
[root@web ~]# systemctl start mysqld

确认MySQL正常启动
[root@web ~]# systemctl status mysqld

设置MySQL开机自启动
[root@web ~]# systemctl enable mysqld

查看生成 MySQL root用户临时密码:
[root@web ~]# grep 'temporary password' /var/log/mysqld.log

修改root用户密码

# 登录数据库
[root@web ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.3

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

# 修改root密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password@2024';
Query OK, 0 rows affected (0.01 sec)

mysql>

设置远程登录

# 查看默认库
mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql>

# 选择使用mysql库
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 


# 查询用户表
mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host      | user             | authentication_string                                                  | plugin                |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root             | $A$005$@c%qYYPJ~F-qAGZDHB6e7/1eEIz5VmK2O87RS12HBQpiPrZ7nVNqHX/D3 | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)

mysql> 


# 修改root的授权
mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> 


# 需要执行俩次
mysql> Grant all privileges on *.* to 'root'@'%';
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql> 
mysql> Grant all privileges on *.* to 'root'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> 

# 刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql> 
mysql>

# 再次查看用户表
mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host      | user             | authentication_string                                                  | plugin                |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| %         | root             | $A$005$@c%qYYPJ~F-qAGZDHB6e7/1eEIz5VmK2O87RS12HBQpiPrZ7nVNqHX/D3 | caching_sha2_password |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)

mysql>

测试连接

# 使用其他主机进行登录数据库
[root@k8s-master01 ~]# mysql -u root -p -h 192.168.1.130
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.4.3 MySQL Community Server - GPL

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

关于

https://www.oiox.cn/

https://www.oiox.cn/index.php/start-page.html

CSDN、GitHub、51CTO、知乎、开源中国、思否、掘金、简书、华为云、阿里云、腾讯云、哔哩哔哩、今日头条、新浪微博、个人博客

全网可搜《小陈运维》

文章主要发布于微信公众号

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
1天前
|
关系型数据库 MySQL 数据库
docker高级篇(大厂进阶):安装mysql主从复制
docker高级篇(大厂进阶):安装mysql主从复制
37 24
|
9天前
|
关系型数据库 MySQL 数据库
Python处理数据库:MySQL与SQLite详解 | python小知识
本文详细介绍了如何使用Python操作MySQL和SQLite数据库,包括安装必要的库、连接数据库、执行增删改查等基本操作,适合初学者快速上手。
74 15
|
3天前
|
SQL 关系型数据库 MySQL
数据库数据恢复—Mysql数据库表记录丢失的数据恢复方案
Mysql数据库故障: Mysql数据库表记录丢失。 Mysql数据库故障表现: 1、Mysql数据库表中无任何数据或只有部分数据。 2、客户端无法查询到完整的信息。
|
10天前
|
关系型数据库 MySQL 数据库
数据库数据恢复—MYSQL数据库文件损坏的数据恢复案例
mysql数据库文件ibdata1、MYI、MYD损坏。 故障表现:1、数据库无法进行查询等操作;2、使用mysqlcheck和myisamchk无法修复数据库。
|
14天前
|
关系型数据库 MySQL Linux
MySQL数据库下载安装教程(Windows&Linux)
本文档详细介绍了MySQL的安装步骤,包括安装前的准备工作、下载安装包、Windows和Linux系统下的具体安装流程,以及如何配置MySQL服务、设置环境变量、启动服务和连接数据库等关键操作。
|
14天前
|
SQL 关系型数据库 MySQL
MySQL导入.sql文件后数据库乱码问题
本文分析了导入.sql文件后数据库备注出现乱码的原因,包括字符集不匹配、备注内容编码问题及MySQL版本或配置问题,并提供了详细的解决步骤,如检查和统一字符集设置、修改客户端连接方式、检查MySQL配置等,确保导入过程顺利。
|
22天前
|
关系型数据库 MySQL 数据库
GBase 数据库如何像MYSQL一样存放多行数据
GBase 数据库如何像MYSQL一样存放多行数据
|
20天前
|
网络安全 数据库
gbase 8a 数据库 安装8ampp 常见ssh报错问题
gbase 8a 数据库 安装8ampp 常见ssh报错问题
|
SQL Java 数据库连接
MySQL---数据库从入门走向大神系列(十五)-Apache的DBUtils框架使用
MySQL---数据库从入门走向大神系列(十五)-Apache的DBUtils框架使用
195 0
MySQL---数据库从入门走向大神系列(十五)-Apache的DBUtils框架使用
|
SQL 关系型数据库 MySQL
MySQL---数据库从入门走向大神系列(六)-事务处理与事务隔离(锁机制)
MySQL---数据库从入门走向大神系列(六)-事务处理与事务隔离(锁机制)
145 0
MySQL---数据库从入门走向大神系列(六)-事务处理与事务隔离(锁机制)