MySQL 案例实战--MySQL 数据库的部署

前言

本环境是基于 Centos 7.8 系统构建MySQL学习环境
安装MySQL-5.7.14


一、系统环境准备

系统要求

Centos 7.8 系统 :
cup:2*2 内存 2G 硬盘20G NAT网络模式(可访问互联网) 基于MIni 安装

安装常用软件安装包

#开始安装
[root@mysql-server ~]# yum install vim bash-completion wget tree lrzsz net-tools psmisc -y
#检查软件安装情况
[root@mysql-server ~]# rpm -aq | egrep -i 'vim|bash-completion|wget|tree|lrzsz|net-tools|psmisc'
vim-enhanced-7.4.629-6.el7.x86_64
vim-minimal-7.4.629-6.el7.x86_64
psmisc-22.20-16.el7.x86_64
vim-filesystem-7.4.629-6.el7.x86_64
wget-1.14-18.el7_6.1.x86_64
net-tools-2.0-0.25.20131004git.el7.x86_64
lrzsz-0.12.20-36.el7.x86_64
vim-common-7.4.629-6.el7.x86_64
bash-completion-2.1-8.el7.noarch
tree-1.6.0-10.el7.x86_64

系统配置

#关闭、禁用开机自启防火墙
[root@mysql-server ~]# systemctl stop firewalld.service 
[root@mysql-server ~]# systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
#关闭、禁用开机自启selinux
[root@mysql-server ~]# setenforce 0
[root@mysql-server ~]# vim /etc/selinux/config 
SELINUX=disabled
#配置系统DNS解析
[root@mysql-server ~]# vim /etc/resolv.conf 
# Generated by NetworkManager
nameserver 114.114.114.114
nameserver 8.8.8.8

二、yum 在线安装

配置MySQL yum 源

清华大学镜像源:https://mirrors.tuna.tsinghua.edu.cn/

  • 配置yum源
[root@mysql-server ~]# vim /etc/yum.repos.d/MySQL-5.7.repo
[mysql-5.7]
name=mysql
baseurl=https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-5.7-community-el7-x86_64/
enabled=1
gpgcheck=0


[root@mysql-server ~]# yum repolist | grep -i ^mysql
Repository base is listed more than once in the configuration
mysql-5.7             mysql                                                  464
  • 安装 MySQL-5.7.14
[root@mysql-server ~]# yum install mysql-community-server-5.7.14 -y

[root@mysql-server ~]# rpm -qa | grep -i ^mysql
mysql-community-libs-5.7.32-1.el7.x86_64
mysql-community-common-5.7.14-1.el7.x86_64
mysql-community-client-5.7.32-1.el7.x86_64
mysql-community-server-5.7.14-1.el7.x86_64

启动服务、并查看状态

[root@mysql-server ~]# systemctl enable --now mysqld
[root@mysql-server ~]# systemctl is-active mysqld
active
[root@mysql-server ~]]# systemctl is-enabled mysqld
enabled
[root@mysql-server ~]# netstat -lnutp | grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      2870/mysqld

获取数据库默认密码

[root@mysql-server ~]# awk '/temporary password/ {print $NF}' /var/log/mysqld.log 
Dli.1_lB173J

登录数据库

[root@mysql-server ~]# mysql -uroot -pDli.1_lB173J
mysql: [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 3
Server version: 5.7.14

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

三、rpm 离线安装

上传软件压缩包

在这里插入图片描述

[root@mysql-server ~]# ll mysql*
-rw-r--r-- 1 root root 569344000 Oct 21 10:20 mysql-5.7.14-1.el7.x86_64.rpm-bundle.tar

解压

[root@mysql-server ~]# tar xf mysql-5.7.14-1.el7.x86_64.rpm-bundle.tar 
[root@mysql-server ~]# ll
total 1112012
-rw-------. 1 root root       1496 Jun  1 21:14 anaconda-ks.cfg
-rw-r--r--  1 root root  569344000 Oct 21 10:20 mysql-5.7.14-1.el7.x86_64.rpm-bundle.tar
-rw-r--r--  1 7155 31415  25012200 Jul 14  2016 mysql-community-client-5.7.14-1.el7.x86_64.rpm
-rw-r--r--  1 7155 31415    277608 Jul 14  2016 mysql-community-common-5.7.14-1.el7.x86_64.rpm
-rw-r--r--  1 7155 31415   3770552 Jul 14  2016 mysql-community-devel-5.7.14-1.el7.x86_64.rpm
-rw-r--r--  1 7155 31415  45366572 Jul 14  2016 mysql-community-embedded-5.7.14-1.el7.x86_64.rpm
-rw-r--r--  1 7155 31415  23925764 Jul 14  2016 mysql-community-embedded-compat-5.7.14-1.el7.x86_64.rpm
-rw-r--r--  1 7155 31415 125630688 Jul 14  2016 mysql-community-embedded-devel-5.7.14-1.el7.x86_64.rpm
-rw-r--r--  1 7155 31415   2235496 Jul 14  2016 mysql-community-libs-5.7.14-1.el7.x86_64.rpm
-rw-r--r--  1 7155 31415   2112812 Jul 14  2016 mysql-community-libs-compat-5.7.14-1.el7.x86_64.rpm
-rw-r--r--  1 7155 31415  51288740 Jul 14  2016 mysql-community-minimal-debuginfo-5.7.14-1.el7.x86_64.rpm
-rw-r--r--  1 7155 31415 158947688 Jul 14  2016 mysql-community-server-5.7.14-1.el7.x86_64.rpm
-rw-r--r--  1 7155 31415  14021340 Jul 14  2016 mysql-community-server-minimal-5.7.14-1.el7.x86_64.rpm
-rw-r--r--  1 7155 31415 116741256 Jul 14  2016 mysql-community-test-5.7.14-1.el7.x86_64.rpm

安装

#卸载mariadb-libs
[root@mysql-server ~]# yum remove mariadb-libs -y
#安装MySQL-5.7.14
[root@mysql-server ~]# yum localinstall mysql-community-client-5.7.14-1.el7.x86_64.rpm mysql-community-server-5.7.14-1.el7.x86_64.rpm mysql-community-libs-5.7.14-1.el7.x86_64.rpm mysql-community-common-5.7.14-1.el7.x86_64.rpm  -y

启动服务、并查看状态

[root@mysql-server ~]# systemctl enable --now mysqld
[root@mysql-server ~]# systemctl is-active mysqld
active
[root@mysql-server ~]]# systemctl is-enabled mysqld
enabled
[root@mysql-server ~]# netstat -lnutp | grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      2870/mysqld

获取数据库默认密码

[root@mysql-server ~]# awk '/temporary password/ {print $NF}' /var/log/mysqld.log 
O/Q-owypP9xl

登录数据库

[root@mysql-server ~]# mysql -uroot -pDli.1_lB173J
mysql: [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 3
Server version: 5.7.14

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

三、通用二进制安装

创建用户组、用户

[root@mysql-server ~]# groupadd -r -g 200 mysql
[root@mysql-server ~]# useradd -r -g 200 -u 200 -c "MySQL Server"  mysql

上传二进制文件包

在这里插入图片描述
解压

#解压
[root@mysql-server ~]# tar xf mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
#创建软连接
[root@mysql-server ~]# cd /usr/local/
[root@mysql-server local]# ln -s mysql-5.7.20-linux-glibc2.12-x86_64/ mysql

授权

[root@mysql-server local]# chown -R mysql.mysql mysql/*

初始化

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

提供配置文件和脚本

#提供配置文件
[root@mysql-server ~]# \cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
修改:datadir
[root@mysql-server ~]# vim /etc/my.cnf
datadir = /usr/local/mysql/data
#提供服务脚本
[root@mysql-server ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

启动服务

#添加到系统服务
[root@mysql-server ~]# chkconfig --add mysqld
#启动服务
[root@mysql-server ~]# systemctl start mysqld
#开机自启动
[root@mysql-server ~]# chkconfig mysqld on

添加环境变量

#添加环境变量
[root@mysql-server ~]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@mysql-server ~]# 加载到当前
source /etc/profile.d/mysql.sh

登录数据库

[root@mysql-server ~]# mysql -uroot -pDli.1_lB173J
mysql: [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 3
Server version: 5.7.14

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

四、源码安装

上传安装包

在这里插入图片描述
解压

[root@mysql-server mysql-5.7.14]# tar xf mysql-boost-5.7.14.tar.gz -C /usr/local/src/

安装依赖软件包

[root@mysql-server mysql-5.7.14]# yum install cmake gcc gcc-c++ ncurses-devel -y

检查、编译、安装

#检查
[root@mysql-server mysql-5.7.14]# cd /usr/local/src/mysql-5.7.14/
[root@mysql-server mysql-5.7.14]# cmake . -DWITH_BOOST=/usr/local/src/mysql-5.7.14/boost/boost_1_59_0/
#编译
[root@mysql-server mysql-5.7.14]# make
#安装
[root@mysql-server mysql-5.7.14]# make install

创建用户和组

[root@mysql-server ~]# groupadd -r -g 333 mysql
[root@mysql-server ~]# useradd -r -u 333 -g 333 -c 'MySQL Server' mysql

初始化

[root@mysql-server local]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/date

提供配置文件和脚本

#提供配置文件
[root@mysql-server ~]# \cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
修改:datadir
[root@mysql-server ~]# vim /etc/my.cnf
datadir = /usr/local/mysql/data
#提供服务脚本
[root@mysql-server ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

启动服务

#添加到系统服务
[root@mysql-server ~]# chkconfig --add mysqld
#启动服务
[root@mysql-server ~]# systemctl start mysqld
#开机自启动
[root@mysql-server ~]# chkconfig mysqld on

添加环境变量

#添加环境变量
[root@mysql-server ~]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@mysql-server ~]# 加载到当前
source /etc/profile.d/mysql.sh

登录数据库

[root@mysql-server ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.14

Copyright (c) 2000, 2016, 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> 
mysql> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值