centos 7部署mysql 5.7

文章详细介绍了MySQL5.7的两种安装方法,包括通过RPM包的离线部署,涉及下载、解压、安装、启动和密码修改过程,以及通用二进制方式的安装,包括创建用户和组、解压、初始化、配置服务脚本以及启动MySQL服务器。在安装过程中,提到了解决依赖问题和配置环境变量的步骤。
摘要由CSDN通过智能技术生成

mysql体系结构:

Mysql是由SQL接口,解析器,优化器,缓存,存储引擎组成的
Connectors指的是不同语言中与SOL的交互
Management Serveices &Utilities:系统管理和控制工具
Connection Pool:连接池。管理缓冲用户连接,线程处理等需要缓存的需求
SOL Interface:SOL接口接受用户的SQL命令,并且返回用户需要查询的结果。比如selectfrom就是调用SOLInterface
Parser:解析器。SOL命令传递到解析器的时候会被解析器验证和解析。
Optimizer:查询优化器。SQL语句在查询之前会使用查询优化器对查询进行优化。
Cache和Buffer:查询缓存。如果查询缓存有命中的查询结果,查询语包就可以直接去查询缓存中取数据.
Engine:存储引擎。存储引擎是MySql中具体的与文件打交道的子系统。

一、离线部署

1.下载mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar  rpm包

2.解压

mkdir mysql
tar xf mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar  -C mysql


[root@localhost ~]# ls mysql
mysql-community-client-5.7.18-1.el7.x86_64.rpm
mysql-community-common-5.7.18-1.el7.x86_64.rpm
mysql-community-devel-5.7.18-1.el7.x86_64.rpm
mysql-community-embedded-5.7.18-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.18-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.18-1.el7.x86_64.rpm
mysql-community-libs-5.7.18-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.18-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.18-1.el7.x86_64.rpm
mysql-community-server-5.7.18-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.18-1.el7.x86_64.rpm
mysql-community-test-5.7.18-1.el7.x86_64.rpm

3.安装

[root@localhost mysql]# rpm -ivh mysql-community-client-5.7.18-1.el7.x86_64.rpm mysql-comm.18-1.el7.x86_64.rpm mysql-community-libs-5.7.18-1.el7.x86_64.rpm 
warning: mysql-community-client-5.7.18-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key
error: Failed dependencies:
	mariadb is obsoleted by mysql-community-client-5.7.18-1.el7.x86_64
	mariadb-libs is obsoleted by mysql-community-libs-5.7.18-1.el7.x86_64
[root@localhost mysql]# rpm -e mariadb-libs mariadb
error: Failed dependencies:
	libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-9.el7.x86_64
	libmysqlclient.so.18()(64bit) is needed by (installed) perl-DBD-MySQL-4.023-6.el7.x86_64
	libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-9.el7.x86_64
	libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) perl-DBD-MySQL-4.023-6.el7.x86_64
[root@localhost mysql]# rpm -e mariadb-libs mariadb postfix perl-DBD-MySQL 
[root@localhost mysql]# rpm -ivh mysql-community-client-5.7.18-1.el7.x86_64.rpm mysql-community-common-5.7.18-1.el7.x86_64.rpm mysql-community-server-5.7.18-1.el7.x86_64.rpm mysql-community-libs-5.7.18-1.el7.x86_64.rpm 

4.启动并查询密码

systemctl start mysqld
 awk '/temporary password/ {print $NF}' /var/log.my

5.登录并修改密码

 mysql -uroot -p 
 Enter password:
mysql> alter user root@localhost identified by "xxxxxxxxxxx"

二、通用二进制方式安装

1.下载mysql-5.7.14-linux-glibc2.5-x86_64.tar版本的mysql

2、创建用户和组

[root@localhost ~]# groupadd -r mysql
[root@localhost ~]# useradd mysql -r -g mysql -c "MYSQL Server" -s/bin/false

3.解压

[root@localhost ~]# tar xf mysql-5.7.14-linux-glibc2.5-x86_64.tar -C /usr/local/
[root@localhost ~]# cd /usr/local/
root@localhost local]# ls
bin    include  libexec                                         sbin
etc    lib      mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz       share
games  lib64    mysql-test-5.7.14-linux-glibc2.5-x86_64.tar.gz  src
[root@localhost local]# tar xf /usr/local/mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz -C /usr/local/

4.创建软链接

[root@localhost local]# ln -sv /usr/local/mysql-5.7.14-linux-glibc2.5-x86_64 /usr/local/mysql

5.初始化

[root@localhost ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

6.提供配置文件和服务脚本

[root@localhost ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
[root@localhost ~]# vim /etc/my.cnf
 basedir =/usr/local/mysql
 datadir =/usr/local/mysql/data
[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
#添加系统服务,并设置开机自启动
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig mysqld on

7.启动mysql并配置环境变量

[root@localhost ~]# /usr/local/mysql/bin/mysqld_safe --user=mysql &
[root@localhost ~]# vim /etc/profile.d/mysql.sh

#加载
[root@localhost ~]# . /etc/profile.d/mysql.sh

8.测试

[root@localhost ~]# mysql -uroot -p
Enter password: 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值