Linux环境部署MySQL

LINUX环境下部署MySQL

MySQL官网:https://www.mysql.com/

MySQL是一种关系型数据库管理系统,所使用的 SQL 语言是用于访问数据库的最常用标准化语言。MySQL 软件采用了双授权政策,分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点。本文采用社区版进行测试学习MySQL。

一、准备安装包

在该目录下再创建一个文件夹,并且将安装包解压到该文件夹中

shell 复制代码
[root@test01 soft]# ls
mysql-8.0.36-1.el7.x86_64.rpm-bundle.tar
# 在当前目录下(mysql)下创建一个 mysql-8.0.26 文件夹
[root@test01 soft]# mkdir mysql-8.0.36 
# 解压安装包到该目录下
[root@test01 soft]# tar -xvf mysql-8.0.36-1.el7.x86_64.rpm-bundle.tar -C mysql-8.0.36

解压完成之后可以切换到 mysql-8.0.36 目录下查看解压后的文件

shell 复制代码
[root@test01 mysql-8.0.36]# ls
mysql-community-client-8.0.36-1.el7.x86_64.rpm
mysql-community-client-plugins-8.0.36-1.el7.x86_64.rpm
mysql-community-common-8.0.36-1.el7.x86_64.rpm
mysql-community-debuginfo-8.0.36-1.el7.x86_64.rpm
mysql-community-devel-8.0.36-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.36-1.el7.x86_64.rpm
mysql-community-icu-data-files-8.0.36-1.el7.x86_64.rpm
mysql-community-libs-8.0.36-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.36-1.el7.x86_64.rpm
mysql-community-server-8.0.36-1.el7.x86_64.rpm
mysql-community-server-debug-8.0.36-1.el7.x86_64.rpm
mysql-community-test-8.0.36-1.el7.x86_64.rpm

二、安装RPM依赖包

解压后得到的文件都是RPM文件,需要用到RPM包资源管理器相关的指令安装RPM的安装包,安装执行RPM安装包需要一些插件,因为MySQL里面有部分RPM的安装依赖于该插件。

shell 复制代码
[root@test01 mysql-8.0.36]# yum -y install libaio perl net-tools
[root@test01 mysql-8.0.36]# yum install openssl-devel

三、安装MySQL的RPM包

安装完该插件之后,依次执行以下命令安装这些RPM包。

shell 复制代码
[root@test01 mysql-8.0.36]# rpm -ivh mysql-community-common-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-common-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
准备中...                          ################################# [100%]
	软件包 mysql-community-common-8.0.36-1.el7.x86_64 已经安装
[root@test01 mysql-8.0.36]# rpm -ivh mysql-community-client-plugins-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-client-plugins-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
准备中...                          ################################# [100%]
	软件包 mysql-community-client-plugins-8.0.36-1.el7.x86_64 已经安装
[root@test01 mysql-8.0.36]# rpm -ivh mysql-community-libs-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-libs-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
准备中...                          ################################# [100%]
	软件包 mysql-community-libs-8.0.36-1.el7.x86_64 已经安装
[root@test01 mysql-8.0.36]# rpm -ivh mysql-community-libs-compat-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-libs-compat-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
准备中...                          ################################# [100%]
	软件包 mysql-community-libs-compat-8.0.36-1.el7.x86_64 已经安装
[root@test01 mysql-8.0.36]# rpm -ivh mysql-community-devel-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-devel-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
准备中...                          ################################# [100%]
	软件包 mysql-community-devel-8.0.36-1.el7.x86_64 已经安装
[root@test01 mysql-8.0.36]# rpm -ivh mysql-community-client-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-client-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
准备中...                          ################################# [100%]
	软件包 mysql-community-client-8.0.36-1.el7.x86_64 已经安装
[root@test01 mysql-8.0.36]# rpm -ivh mysql-community-server-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-server-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
错误:依赖检测失败:
	mysql-community-icu-data-files = 8.0.36-1.el7 被 mysql-community-server-8.0.36-1.el7.x86_64 需要

出现错误信息,要解决这个问题,需要先安装缺失的ICU数据文件。

shell 复制代码
[root@test01 mysql-8.0.36]# yum install mysql-community-icu-data-files-8.0.36-1.el7.x86_64.rpm
已加载插件:fastestmirror, langpacks
正在检查 mysql-community-icu-data-files-8.0.36-1.el7.x86_64.rpm: mysql-community-icu-data-files-8.0.36-1.el7.x86_64
mysql-community-icu-data-files-8.0.36-1.el7.x86_64.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql-community-icu-data-files.x86_64.0.8.0.36-1.el7 将被 安装
--> 解决依赖关系完成
http://mirrors.aliyun.com/centos-altarch/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
===============================================================================================
 Package         架构   版本         源                                                   大小
===============================================================================================
正在安装:
 mysql-community-icu-data-files
                 x86_64 8.0.36-1.el7 /mysql-community-icu-data-files-8.0.36-1.el7.x86_64 3.9 M

事务概要
===============================================================================================
安装  1 软件包

总计:3.9 M
安装大小:3.9 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
  正在安装    : mysql-community-icu-data-files-8.0.36-1.el7.x86_64                         1/1 
  验证中      : mysql-community-icu-data-files-8.0.36-1.el7.x86_64                         1/1 

已安装:
  mysql-community-icu-data-files.x86_64 0:8.0.36-1.el7                                         

完毕!

安装缺失的ICU文件后重新安装mysql-community-server-8.0.36-1.el7.x86_64.rpm包。

shell 复制代码
[root@test01 mysql-8.0.36]# rpm -ivh mysql-community-server-8.0.36-1.el7.x86_64.rpm
警告:mysql-community-server-8.0.36-1.el7.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID a8d3785c: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-server-8.0.36-1.e################################# [100%]

四、启动MySQL服务

在Linux中MySQL安装好了之后系统会自动的注册一个服务,服务名称叫做 mysqld,所以可以通过以下命令操作MySQL:

  • 启动MySQL服务:systemctl start mysqld
  • 重启MySQL服务:systemctl restart mysqld
  • 关闭MySQL服务:systemctl stop mysqld
shell 复制代码
# 启动mysql服务
[root@panweidb mysql-8.0.36]# systemctl start mysqld
Redirecting to /bin/systemctl start mysqld.service

RPM安装MySQL会自动生成一个随机密码,可以在/var/log/mysqld.log这个文件中查找密码。

shell 复制代码
[root@panweidb mysql-8.0.36]# cat /var/log/mysqld.log | grep password
2024-04-18T09:24:14.608802Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: lpOagaL2hu;d

五、连接MySQL服务

shell 复制代码
[root@test01 mysql-8.0.36]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.36

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> 

为了方便后期使用需要更改初始密码

shell 复制代码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'Test@123';
Query OK, 0 rows affected (0.01 sec)
相关推荐
tokepson2 小时前
Mysql下载部署方法备份(Windows/Linux)
linux·服务器·windows·mysql
zz_nj5 小时前
工作的环境
linux·运维·服务器
极客先躯5 小时前
如何自动提取Git指定时间段的修改文件?Win/Linux双平台解决方案
linux·git·elasticsearch
suijishengchengde6 小时前
****LINUX时间同步配置*****
linux·运维
什么都不会的Tristan6 小时前
MybatisPlus-扩展功能
数据库·mysql
qiuqyue6 小时前
基于虹软Linux Pro SDK的多路RTSP流并发接入、解码与帧级处理实践
linux·运维·网络
切糕师学AI6 小时前
Linux 操作系统简介
linux
南烟斋..7 小时前
GDB调试核心指南
linux·服务器
爱跑马的程序员7 小时前
Linux 如何查看文件夹的大小(du、df、ls、find)
linux·运维·ubuntu
oMcLin9 小时前
如何在 Ubuntu 22.04 LTS 上部署并优化 Magento 电商平台,提升高并发请求的响应速度与稳定性?
linux·运维·ubuntu