运维高级学习(一):CentOS RPM安装Mysql和MySQL体系结构

实验要求:

1、CentOS7 RPM方式安装MySQL5.7

(1)首先在线下载 MySQL Yum Repository

[root@localhost ~]# wget -c https://repo.mysql.com//mysql80-community-release-el7-5.noarch.rpm 

可以查看本地是否有下载

[root@localhost ~]# ll
total 16
-rw-------. 1 root root  1425 Mar 26 20:53 anaconda-ks.cfg
-rw-r--r--. 1 root root 10928 Jan 14 18:21 mysql80-community-release-el7-5.noarch.rpm

在这里插入图片描述

(2)添加 MySQL Yum Repository

[root@localhost ~]# yum localinstall mysql80-community-release-el7-5.noarch.rpm 

查看添加的Mysql情况

[root@localhost ~]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64       MySQL Connectors Community           230
mysql-tools-community/x86_64            MySQL Tools Community                138
mysql80-community/x86_64                MySQL 8.0 Community Server           321

(3)选择安装发行版
禁用8.0:yum-config-manager --disable mysql80-community
启用5.7:yum-config-manager --enable mysql57-community

(可以先安装yum-utils]# yum install yum-utils.noarch )

[root@localhost ~]# yum-config-manager --disable mysql80-community	(关闭mysql80;)
[root@localhost ~]# yum-config-manager --enable mysql57-community	(使用mysql57;)

再次查看Mysql的情况
在这里插入图片描述
(4)在线安装

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

等待安装完成即可
(5)启动数据库

[root@localhost ~]# systemctl enable --now mysqld

(6)通过验证查看Mysql的安装情况

[root@localhost ~]# netstat -lnpt | grep :3306	(查看端口号)
[root@localhost ~]# ps -ef | grep mysqld		(查看进程)
[root@localhost ~]# systemctl status mysqld		(查看状态)

在这里插入图片描述

2、CentOS7 通用二进制方式安装MySQL5.7

(1)通过在线方式下载glibc版本的Mysql

[root@localhost ~]# wget -c https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.7/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz

可以查看Mysql
在这里插入图片描述
(2)新建用户以安全方式运行进程

[root@localhost ~]# groupadd mysql -r -g 306
[root@localhost ~]# useradd -r -g mysql -s /bin/false -u 306 mysql

在这里插入图片描述
(3)解压到指定目录安装,修改目录的用户组并初始化mysql

[root@localhost ~]# tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@localhost ~]# ln -sv /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64/ /usr/local/mysql/usr/local/mysql’ -> ‘/usr/local/mysql-5.7.37-linux-glibc2.12-x86_64/[root@localhost ~]# ll /usr/local/mysql
lrwxrwxrwx 1 root root 47 Mar 26 22:30 /usr/local/mysql -> /usr/local/mysql-5.7.37-linux-glibc2.12-x86_64/
[root@localhost ~]# ll /usr/local/mysql/	查看目录当前为root所属者和所属组
total 272
drwxr-xr-x  2 root root    4096 Mar 26 22:28 bin
drwxr-xr-x  2 root root      55 Mar 26 22:28 docs
drwxr-xr-x  3 root root    4096 Mar 26 22:28 include
drwxr-xr-x  5 root root     230 Mar 26 22:28 lib
-rw-r--r--  1 7161 31415 259253 Nov 30 04:09 LICENSE
drwxr-xr-x  4 root root      30 Mar 26 22:28 man
-rw-r--r--  1 7161 31415    566 Nov 30 04:09 README
drwxr-xr-x 28 root root    4096 Mar 26 22:28 share
drwxr-xr-x  2 root root      90 Mar 26 22:28 support-files

修改目录用户组和所属组

[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql/*
[root@localhost ~]# ll /usr/local/mysql/
total 272
drwxr-xr-x  2 mysql mysql   4096 Mar 26 22:28 bin
drwxr-xr-x  2 mysql mysql     55 Mar 26 22:28 docs
drwxr-xr-x  3 mysql mysql   4096 Mar 26 22:28 include
drwxr-xr-x  5 mysql mysql    230 Mar 26 22:28 lib
-rw-r--r--  1 mysql mysql 259253 Nov 30 04:09 LICENSE
drwxr-xr-x  4 mysql mysql     30 Mar 26 22:28 man
-rw-r--r--  1 mysql mysql    566 Nov 30 04:09 README
drwxr-xr-x 28 mysql mysql   4096 Mar 26 22:28 share
drwxr-xr-x  2 mysql mysql     90 Mar 26 22:28 support-files

(4)添加配置环境变量将mysql的bin目录加入PATH环境变量,编辑/etc/profile文件
使用mysql客户端命令

[root@localhost ~]# vim /etc/profile.d/mysql.sh
export PATH=$PATH:/usr/local/mysql/bin
~                                                                                                                              
~                                                                                                                              
~                                                                                                                              
~                                                                                                                              
~                     
[root@localhost ~]# source /etc/profile.d/mysql.sh 

(5)初始化数据库—最后:后是数据库的密码

[root@localhost ~]# mysqld  --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2022-03-26T15:51:35.405198Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-03-26T15:51:35.774204Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-03-26T15:51:35.824825Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-03-26T15:51:35.884221Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 9dbe8909-ad1c-11ec-8988-000c290eccc5.
2022-03-26T15:51:35.884995Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-03-26T15:51:36.709941Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-03-26T15:51:36.709955Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-03-26T15:51:36.710793Z 0 [Warning] CA certificate ca.pem is self signed.
2022-03-26T15:51:36.992592Z 1 [Note] A temporary password is generated for root@localhost: 03lt;.Xt5Xu,

(6)因为本机没有主配置文件,所以从另外一台主机复制主配置文件到本机

[root@localhost local]# scp 192.168.142.140:/etc/my.cnf /etc
The authenticity of host '192.168.142.140 (192.168.142.140)' can't be established.
ECDSA key fingerprint is SHA256:UyfzqndzhPpQSUYCexZDbvb8sKoTc9rlnPT1yBGlK54.
ECDSA key fingerprint is MD5:d4:10:b3:0f:44:33:0b:5d:8a:e1:9c:b4:92:24:92:15.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.142.140' (ECDSA) to the list of known hosts.
root@192.168.142.140's password: 
my.cnf                                                                   100%  960    40.7KB/s   00:00    

(7)修改主配置文件,并且复制文件到指定目录

[root@localhost local]# vim /etc/my.cnf
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
pid-file=mysqld.pid
[root@localhost local]# cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld

(8)启动数据库

[root@localhost local]# chkconfig --add mysqld	添加为系统服务
[root@localhost local]# chkconfig mysqld on		开机自启动
[root@localhost local]#systemctl start mysqld
[root@localhost local]# systemctl status mysqld

在这里插入图片描述

3、简述MySQL体系结构。

Mysql是由SQL接口,解析器,优化器,缓存,存储引擎组成的
SQL Interface: SQL接口,接受用户的SQL命令,并且返回用户需要查询的结果。比如select from就是调用SQL Interface
Parser: 解析器。SQL命令传递到解析器的时候会被解析器验证和解析。
Optimizer: 查询优化器。SQL语句在查询之前会使用查询优化器对查询进行优化。
Cache和Buffer: 查询缓存。如果查询缓存有命中的查询结果,查询语句就可以直接去查询缓存中取数
据.
Engine :存储引擎。存储引擎是MySql中具体的与文件打交道的子系统。

Connectors指的是不同语言中与SQL的交互
Management Serveices & Utilities: 系统管理和控制工具
Connection Pool: 连接池。管理缓冲用户连接,线程处理等需要缓存的需求

在这里插入图片描述

4、使用mysql客户端登录服务器,重置root密码

[root@localhost ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 5.7.37 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, 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> ALTER user root@localhost identified by 'root@123';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
mysql> 

在这里插入图片描述

  • 4
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值