数据库安装部署_MySQL(5.7 & 8安装配置)
1.前言
1.1 编写目的
本文档针成都开发中心MySQL安装部署提供规范化指导,提供两种安装部署方案:
使用自动化安装脚本进行安装
使用官网下载的rpm包进行手动安装
以上两种方法均可以完成MySQL数据库安装,读者可根据实际情况选择合适的安装方案。
1.2 前提和假设
如非特别说明,本指导手册叙述的产品特性、操作命令、用户界面均基于MySQL 5.7.26和MySQL 8.0.22版本,可能有不适用于其它版本的情况。如遇此情况,请参考其它版本厂商技术手册中对应的说明。
1.3 适用范围
本指导手册适用于成都开发中心测试环境安装部署新的MySQL数据库,配置规范仅供参考,各新老系统可根据实际情况自行调整相关配置参数值。
1.4 预期读者
成都开发中心的项目基础设施可行性研究、设计和实施人员,项目组应用系统设计人员,相关运行维护技术人员。
2.操作系统要求
2.1 参数设置
操作系统内核参数参照行内Linux安装配置规范进行设置,建议值如下:
| 参数名称 | 参数含义 | 默认值 | 建议值 |
| :--------------------------- | :-------------------------------------- | :----------------------------- | :------------------------ |
| fs.aio-max-nr | 异步I/O总数 | 65535 | 4194304 |
| fs.file-max | 系统最大文件句柄数 | 根据主机硬件配置自动生成默认值 | 6815744 |
| kernel.shmall | 系统可使用的共享内存的总量(pages) | 根据主机硬件配置自动生成默认值 | 167772160 |
| kernel.shmmax | 内核所允许的最大共享内存段的大小(bytes) | 根据主机硬件配置自动生成默认值 | 687194767360 |
| kernel.shmmni | 用于整个系统的共享内存段的最大数目(个)| 4096 | 4096 |
| kernel.sem | 信号量设置 | 250 32000 32 128 | 10000 40960000 10000 4096 |
| net.ipv4.ip_local_port_range | 用于向外连接的端口范围 | 32768 61000 | 20000 65535 |
| vm.swappiness | swap空间使用(趋势) | 60 | 1 |
2.2 用户和组
- 创建如下用户及用户组:
| 名称 | 说明 |
| :---- | :------------------------------------- |
| 用户 | mysql,id为321,家目录为/home/db/mysql |
| 组 | mysql,id为320 |
- 创建mysql用户操作命令如下
[root@mysql143 ~]# groupadd -g 320 mysql
[root@mysql143 ~]# useradd -d /home/db/mysql -u 321 -g mysql mysql
- 设置mysql用户环境变量,修改/home/db/mysql/.bash_profile为如下内容:
export MYSQL_HOME=/home/db/mysql/product
export PATH=$PATH:/home/db/mysql/product/bin:/home/db/mysql/product/lib
export PS1='$LOGNAME@'`hostname`:'$PWD''$ '
if [ -t 0 ];
then stty intr ^C
fi
2.3 linux特殊配置
2.3.1 配置yum安装缺失的软件包
如果缺少某些软件包,可以使用yum来安装,需要配置成开中心的本地yum源,并重新生成yum缓存,操作如下:
- 编辑yum配置文件
[root@mysql143 ~]# vim /etc/yum.conf
将以下内容追加到yum.conf配置文件中
[China-base]
name=CentOS-$releasever - Base [China]
baseurl=http://128.160.171.181:9527/centos/$releasever/os/$basearch/
enabled=1
gpgcheck=0
[China-updates]
name=CentOS-$releasever - Updates [China]
baseurl=http://128.160.171.181:9527/centos/$releasever/updates/$basearch/
enabled=1
gpgcheck=0
[China-extras]
name=CentOS-$releasever - Extras [China]
baseurl=http://128.160.171.181:9527/centos/$releasever/extras/$basearch/
enabled=1
gpgcheck=0
[China-centosplus]
name=CentOS-$releasever - Plus [China]
baseurl=http://128.160.171.181:9527/centos/$releasever/centosplus/$basearch/
enabled=1
gpgcheck=0
[China-epel]
name=Extra Packages for Enterprise Linux $releasever [China]
baseurl=http://128.160.171.181:9527/epel/$releasever/$basearch/
failovermethod=priority
enabled=1
gpgcheck=0
保存退出。
- 将/etc/yum.repos.d下其他的repo文件进行备份,重新生成yum的缓存
[root@mysql143 yum.repos.d]# cd /etc/yum.repos.d/
[root@mysql143 yum.repos.d]#
[root@mysql143 yum.repos.d]# ll
总用量 4
drwxr-xr-x. 2 root root 187 6月 21 2019 bak
-rw-r--r--. 1 root root 61 6月 21 2019 local.repo,bak
[root@mysql143 yum.repos.d]# yum clean all
已加载插件:fastestmirror
正在清理软件源: China-base China-centosplus China-epel China-extras China-updates
Cleaning up list of fastest mirrors
Other repos take up 1.5 M of disk space (use --verbose for details)
[root@mysql143 yum.repos.d]# yum makecache
已加载插件:fastestmirror
Determining fastest mirrors
China-base | 3.6 kB 00:00:00
China-centosplus | 2.9 kB 00:00:00
China-epel | 5.4 kB 00:00:00
China-extras | 2.9 kB 00:00:00
China-updates | 2.9 kB 00:00:00
(1/19): China-base/7/x86_64/group_gz | 165 kB 00:00:00
(2/19): China-base/7/x86_64/filelists_db | 7.3 MB 00:00:00
(3/19): China-base/7/x86_64/primary_db | 6.0 MB 00:00:00
(4/19): China-base/7/x86_64/other_db | 2.6 MB 00:00:00
(5/19): China-centosplus/7/x86_64/filelists_db | 1.2 MB 00:00:00
(6/19): China-centosplus/7/x86_64/other_db | 69 kB 00:00:00
(7/19): China-centosplus/7/x86_64/primary_db | 2.7 MB 00:00:00
(8/19): China-epel/7/x86_64/group_gz | 95 kB 00:00:00
(9/19): China-epel/7/x86_64/updateinfo | 1.0 MB 00:00:00
(10/19): China-epel/7/x86_64/prestodelta | 3.8 kB 00:00:00
(11/19): China-epel/7/x86_64/filelists_db | 11 MB 00:00:00
(12/19): China-epel/7/x86_64/primary_db | 6.7 MB 00:00:00
(13/19): China-epel/7/x86_64/other_db | 3.2 MB 00:00:00
(14/19): China-extras/7/x86_64/primary_db | 164 kB 00:00:00
(15/19): China-extras/7/x86_64/filelists_db | 216 kB 00:00:00
(16/19): China-extras/7/x86_64/other_db | 106 kB 00:00:00
(17/19): China-updates/7/x86_64/filelists_db | 4.0 MB 00:00:00
(18/19): China-updates/7/x86_64/primary_db | 6.7 MB 00:00:00
(19/19): China-updates/7/x86_64/other_db | 493 kB 00:00:00
元数据缓存已建立
2.3.2 主机名配置
- 确认主机名
[root@mysql143 ~]# cat /etc/hostname
mysql143
2.3.3 关闭额外的服务
- 参照Linux安装配置规范,关闭如下服务:
[root@host]#systemctl stop abrt-ccpp.service
[root@host]#systemctl stop abrtd.service
[root@host]#systemctl stop abrt-oops.service
[root@host]#systemctl stop abrt-pstoreoops.service
[root@host]#systemctl stop abrt-vmcore.service
[root@host]#systemctl stop abrt-xorg.service
[root@host]#systemctl stop arp-ethers.service
[root@host]#systemctl stop atd.service
[root@host]#systemctl stop auditd.service
[root@host]#systemctl stop blk-availability.service
[root@host]#systemctl stop brandbot.path
[root@host]#systemctl stop chronyd.service
[root@host]#systemctl stop cpupower.service
[root@host]#systemctl stop dm-event.service
[root@host]#systemctl stop dmraid-activation.service
[root@host]#systemctl stop ebtables.service
[root@host]#systemctl stop firewalld.service
[root@host]#systemctl stop fstrim.timer
[root@host]#systemctl stop gssproxy.service
[root@host]#systemctl stop iprdump.service
[root@host]#systemctl stop iprinit.service
[root@host]#systemctl stop iprupdate.service
[root@host]#systemctl stop iprutils.target
[root@host]#systemctl stop ipsec.service
[root@host]#systemctl stop kexec.target
[root@host]#systemctl stop libstoragemgmt.service
[root@host]#systemctl stop lvm2-lvmetad.service
[root@host]#systemctl stop lvm2-lvmpolld.service
[root@host]#systemctl stop lvm2-monitor.service
[root@host]#systemctl stop mdmonitor.service
[root@host]#systemctl stop microcode.service
[root@host]#systemctl stop nfs-blkmap.service
[root@host]#systemctl stop nfs-rquotad.service
[root@host]#systemctl stop nfs-server.service
[root@host]#systemctl stop nfs.service
[root@host]#systemctl stop ntpdate.service
[root@host]#systemctl stop Plymouth*
[root@host]#systemctl stop pmcd.service
[root@host]#systemctl stop pmie.service
[root@host]#systemctl stop pmlogger.service
[root@host]#systemctl stop pmproxy.service
[root@host]#systemctl stop powertop.service
[root@host]#systemctl stop psacct.service
[root@host]#systemctl stop rasdaemon.service
[root@host]#systemctl stop ras-mc-ctl.service
[root@host]#systemctl stop rdisc.service
[root@host]#systemctl stop rhel-dmesg.service
[root@host]#systemctl stop rhel-domainname.service
[root@host]#systemctl stop rngd.service
[root@host]#systemctl stop rpc-rquotad.service
[root@host]#systemctl stop rsyncd.service
[root@host]#systemctl stop smartd.service
[root@host]#systemctl stop snmpd*
[root@host]#systemctl stop tcsd.service
[root@host]#systemctl stop tuned.service
[root@host]#systemctl stop xinetd.service
2.3.4 禁用额外的服务
- 参照Linux安装配置规范,禁用如下服务:
[root@host]#systemctl disable abrt-ccpp.service
[root@host]#systemctl disable abrtd.service
[root@host]#systemctl disable abrt-oops.service
[root@host]#systemctl disable abrt-pstoreoops.service
[root@host]#systemctl disable abrt-vmcore.service
[root@host]#systemctl disable abrt-xorg.service
[root@host]#systemctl disable arp-ethers.service
[root@host]#systemctl disable atd.service
[root@host]#systemctl disable auditd.service
[root@host]#systemctl disable blk-availability.service
[root@host]#systemctl disable brandbot.path
[root@host]#systemctl disable chronyd.service
[root@host]#systemctl disable cpupower.service
[root@host]#systemctl disable dm-event.service
[root@host]#systemctl disable dmraid-activation.service
[root@host]#systemctl disable ebtables.service
[root@host]#systemctl disable firewalld.service
[root@host]#systemctl disable fstrim.timer
[root@host]#systemctl disable gssproxy.service
[root@host]#systemctl disable iprdump.service
[root@host]#systemctl disable iprinit.service
[root@host]#systemctl disable iprupdate.service
[root@host]#systemctl disable iprutils.target
[root@host]#systemctl disable ipsec.service
[root@host]#systemctl disable kexec.target
[root@host]#systemctl disable libstoragemgmt.service
[root@host]#systemctl disable lvm2-lvmetad.service
[root@host]#systemctl disable lvm2-lvmpolld.service
[root@host]#systemctl disable lvm2-monitor.service
[root@host]#systemctl disable mdmonitor.service
[root@host]#systemctl disable microcode.service
[root@host]#systemctl disable nfs-blkmap.service
[root@host]#systemctl disable nfs-rquotad.service
[root@host]#systemctl disable nfs-server.service
[root@host]#systemctl disable nfs.service
[root@host]#systemctl disable ntpdate.service
[root@host]#systemctl disable Plymouth*
[root@host]#systemctl disable pmcd.service
[root@host]#systemctl disable pmie.service
[root@host]#systemctl disable pmlogger.service
[root@host]#systemctl disable pmproxy.service
[root@host]#systemctl disable powertop.service
[root@host]#systemctl disable psacct.service
[root@host]#systemctl disable rasdaemon.service
[root@host]#systemctl disable ras-mc-ctl.service
[root@host]#systemctl disable rdisc.service
[root@host]#systemctl disable rhel-dmesg.service
[root@host]#systemctl disable rhel-domainname.service
[root@host]#systemctl disable rngd.service
[root@host]#systemctl disable rpc-rquotad.service
[root@host]#systemctl disable rsyncd.service
[root@host]#systemctl disable smartd.service
[root@host]#systemctl disable snmpd*
[root@host]#systemctl disable tcsd.service
[root@host]#systemctl disable tuned.service
[root@host]#systemctl disable xinetd.service
2.3.5 关闭SELINUX
- 使用root用户编辑SELINUX软件配置文件
[root@mysql143 selinux]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
编辑结束后退出,可以选择重启机器使配置生效,也可以选择使用root用户运行以下命令立即关闭SELINUX
[root@mysql143 selinux]# setenforce 0
setenforce: SELinux is disabled
2.3.6 关闭FIREWALL(防火墙)
- Linux7版本使用如下命令:
使用root用户运行以下命令关闭firewall:
[root@host]#systemctl stop firewalld
运行以下命令,设置下次启动系统不启动firewall:
[root@host]#systemctl disable firewalld
运行以下命令,如显示disabled则表示设置成功:
[root@mysql143 ~]# systemctl list-unit-files|grep firewalld
firewalld.service disabled
- Linux6版本使用如下命令:
使用root用户运行以下命令关闭iptables:
[root@host]#service iptables stop
运行以下命令,设置下次启动系统不启动iptables:
[root@host]#chkconfig iptables off
运行以下命令,如显示disabled则表示设置成功:
[root@host]#service iptables status
2.3.7 配置LIMITS
- 根据Linux7安装配置规范,如果用户有个性化的值,请在/etc/security/limits.conf中配置,不得修改/etc/security/limits.d/20-proc.conf文件
| 序号 | 参数 | 参数名称 | default | 建议值 |
| :--- | :---------------------- | :-------- | :------- | :------- |
| 1 | 进程最大打开文件数 | nofile | 1024 | 655360 |
| 2 | 进程堆栈 | stack | 10240 | 10240 |
| 3 | 用户可创建的进程/线程数 | nproc | 1024 | 65536 |
使用root用户执行
[root@mysql143 ~]# cat>>/etc/security/limits.conf < mysql soft nofile 655360
> mysql soft stack 10240
> mysql soft nproc 65536
> EOF
2.3.8 MOUNT参数
- 新增/home/db/mysql、/mysqldata、/mysqltmp、/mysqlbinlog和/mysqlbackup五个挂载点的信息,mount的时候添加如下参数来提高性能。
[root@host]# vi /etc/fstab
/dev/vg01/ /home/db/mysql xfs defaults 0 0
/dev/vg01/ /mysqldata xfs rw,noatime,nodiratime,nobarrier 0 0
/dev/vg01/ /mysqltmp xfs rw,noatime,nodiratime,nobarrier 0 0
/dev/vg01/ /mysqlbinlog xfs rw,noatime,nodiratime,nobarrier 0 0
/dev/vg01/ /mysqlbackup xfs defaults 0 0
[root@host]# mount –a
2.3.9 DISK I/O SCHEDULER
官方推荐io调度策略为deadline
- linux 6配置方法
修改/etc/grub.conf,找到kernel/vmlinuz-xxx这一行,在最后添加elevator=deadline。
[root@host]vi /etc/grub.conf
title Red Hat Enterprise Linux (2.6.32-431.29.2.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-4.1.12-94.3.9.el7.x86_64 ro root=/dev/mapper/vg00-lvroot
rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=us LANG=en_US.UTF-8
rd_LVM_LV=vg00/lvroot
rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto
rd_LVM_LV=vg00/lvswap01
rd_NO_DM rhgb quiet elevator=deadline
- linux 7配置方法
修改/etc/default/grub,找到GRUB_CMDLINE_LINUX这一行,在最后添加elevator=deadline
[root@host]vi /etc/default/grub
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet elevator=deadline numa=off"
然后编译/boot/grub2/grub.cfg文件,以便生效
BIOS-Based:
[root@host] grub2-mkconfig -o /boot/grub2/grub.cfg
UEFI-Based:
[root@host] grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg
检查/验证方法:系统启动正常后,执行:
[root@host]cat /sys/block/*/queue/scheduler
如果看到deadline 被总括号选中,表示正常,如
noop anticipatory [deadline] cfq
3.MySQL数据库的安装
3.1 MySQL手动安装(版本号8.0.22)
- 将安装MySQL所需要的rpm包存放在/home/db/mysql/product路径下
[root@localhost mysql]# cd product/
[root@localhost product]# ll
total 577144
-rwxr-xr-x. 1 root root 49820920 Dec 15 13:56 mysql-community-client-8.0.22-1.el7.x86_64.rpm
-rwxr-xr-x. 1 root root 630772 Dec 15 13:56 mysql-community-common-8.0.22-1.el7.x86_64.rpm
-rwxr-xr-x. 1 root root 4809544 Dec 15 13:56 mysql-community-libs-8.0.22-1.el7.x86_64.rpm
-rwxr-xr-x. 1 root root 1273480 Dec 15 13:56 mysql-community-libs-compat-8.0.22-1.el7.x86_64.rpm
-rwxr-xr-x. 1 root root 534432648 Dec 15 13:58 mysql-community-server-8.0.22-1.el7.x86_64.rpm
-rwxr-xr-x. 1 root root 18672 Dec 15 13:56 mysqlInstall.sh
- 查看centOS 7自带的mariadb是否已安装,如果安装需要清理
[root@localhost product]# rpm -qa|grep -i mariadb
[root@localhost product]#
通过rpm -e 加包名,可以把mariadb包清掉
- 开始按顺序逐一安装MySQL的rpm包,顺序大致为common--->lib--->client--->server:
[root@localhost mysql]#
[root@localhost mysql]#
[root@localhost mysql]# chmod -R 755 product
[root@localhost mysql]#
[root@localhost mysql]# cd product/
[root@localhost product]# rpm -ivh mysql-community-common-8.0.22-1.el7.x86_64.rpm
warning: mysql-community-common-8.0.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-8.0.22-1.e################################# [100%]
[root@localhost product]# rpm -ivh mysql-community-libs-8.0.22-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
mysql-community-client-plugins = 8.0.22-1.el7 is needed by mysql-community-libs-8.0.22-1.el7.x86_64
在安装libs包时出现报错缺少plugins依赖,因此需要先安装plugins包,下载地址 https://dev.mysql.com/downloads/mysql/
[root@localhost product]# rpm -ivh mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm
warning: mysql-community-client-plugins-8.0.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-plugins-8.################################# [100%]
[root@localhost product]# rpm -ivh mysql-community-libs-8.0.22-1.el7.x86_64.rpm
warning: mysql-community-libs-8.0.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-8.0.22-1.el7################################# [100%]
[root@localhost product]# rpm -ivh mysql-community-client-8.0.22-1.el7.x86_64.rpm
warning: mysql-community-client-8.0.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-8.0.22-1.e################################# [100%]
[root@localhost product]# rpm -ivh mysql-community-server-8.0.22-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-8.0.22-1.e################################# [100%]
到这里MySQL 8.0.22的rpm安装基本完成,我们可以指定数据存放路径写到/etc/my.cnf配置文件中,如:
datadir=/home/db/mysql/data
需要给目录授权mysql用户权限。
- 启动MySQL数据库
[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]#
[root@localhost mysql]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2020-12-15 16:06:22 CST; 5s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 8810 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 8891 (mysqld)
Status: "Server is operational"
CGroup: /system.slice/mysqld.service
└─8891 /usr/sbin/mysqld
Dec 15 16:06:15 localhost.localdomain systemd[1]: Starting MySQL Server...
Dec 15 16:06:22 localhost.localdomain systemd[1]: Started MySQL Server.
- 查看MySQL的初始密码
[root@localhost mysql]# grep 'temporary password' /var/log/mysqld.log
2020-11-18T05:49:32.689561Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: R_yHaip=#9qJ
2020-12-15T08:06:18.015710Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: p%gxZpMsy5tJ
- 修改MySQL的登录密码
[root@localhost log]# mysql -u root -p
mysql> alter user root@localhost identified by 'Passw0rd!';
Query OK, 0 rows affected (0.01 sec)
mysql> exit
自此MySQL 8.0.22安装完成。
3.2 MySQL手动安装(版本号5.7.26)
- 将安装MySQL所需要的rpm包存放在/home/db/mysql/product路径下
[root@mysql143 db]# cd mysql/product/
[root@mysql143 product]# ll
总用量 198836
-rwxr-xr-x 1 root root 25381952 12月 16 09:58 mysql-community-client-5.7.26-1.el7.x86_64.rpm
-rwxr-xr-x 1 root root 280904 12月 16 09:58 mysql-community-common-5.7.26-1.el7.x86_64.rpm
-rwxr-xr-x 1 root root 2274268 12月 16 09:58 mysql-community-libs-5.7.26-1.el7.x86_64.rpm
-rwxr-xr-x 1 root root 2118444 12月 16 09:58 mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm
-rwxr-xr-x 1 root root 173541272 12月 16 09:59 mysql-community-server-5.7.26-1.el7.x86_64.rpm
- 开始按顺序逐一安装MySQL的rpm包,顺序大致为common--->lib--->client--->server:
[root@mysql143 product]# rpm -ivh mysql-community-common-5.7.26-1.el7.x86_64.rpm
警告:mysql-community-common-5.7.26-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.26-1.e################################# [100%]
[root@mysql143 product]# rpm -ivh mysql-community-libs-5.7.26-1.el7.x86_64.rpm
警告:mysql-community-libs-5.7.26-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-5.7.26-1.el7################################# [100%]
[root@mysql143 product]# rpm -ivh mysql-community-client-5.7.26-1.el7.x86_64.rpm
警告:mysql-community-client-5.7.26-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-client-5.7.26-1.e################################# [100%]
[root@mysql143 product]# rpm -ivh mysql-community-server-5.7.26-1.el7.x86_64.rpm
警告:mysql-community-server-5.7.26-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-server-5.7.26-1.e################################# [100%]
[root@mysql143 product]# rpm -ivh mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm
警告:mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-libs-compat-5.7.2################################# [100%]
- 启动MySQL数据库
[root@mysql143 product]# systemctl start mysqld
[root@mysql143 product]#
[root@mysql143 product]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 三 2020-12-16 10:21:02 CST; 5s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 18604 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 18527 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 18607 (mysqld)
CGroup: /system.slice/mysqld.service
└─18607 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
12月 16 10:20:56 mysql143 systemd[1]: Starting MySQL Server...
12月 16 10:21:02 mysql143 systemd[1]: Started MySQL Server.
- 查看MySQL的初始密码
[root@mysql143 ~]# grep 'temporary password' /var/log/mysqld.log
2020-12-16T02:20:58.128815Z 1 [Note] A temporary password is generated for root@localhost: -ivVlqDtE08q
- 修改MySQL的登录密码
[root@localhost log]# mysql -u root -p
mysql> alter user root@localhost identified by 'Passw0rd!';
Query OK, 0 rows affected (0.01 sec)
mysql> exit
自此MySQL 5.7.26安装完成。
3.3 运用MySQL安装脚本安装数据库(以版本5.7.26为例)
- 将安装MySQL所需要的rpm包和安装脚本 mysqlInstall.sh 存放在/home/db/mysql/product路径下:
[root@mysql143 mysql]# cd product/
[root@mysql143 product]# ll
总用量 198856
-rwxr-xr-x 1 root root 25381952 12月 16 10:57 mysql-community-client-5.7.26-1.el7.x86_64.rpm
-rwxr-xr-x 1 root root 280904 12月 16 10:57 mysql-community-common-5.7.26-1.el7.x86_64.rpm
-rwxr-xr-x 1 root root 2274268 12月 16 10:57 mysql-community-libs-5.7.26-1.el7.x86_64.rpm
-rwxr-xr-x 1 root root 2118444 12月 16 10:57 mysql-community-libs-compat-5.7.26-1.el7.x86_64.rpm
-rwxr-xr-x 1 root root 173541272 12月 16 10:57 mysql-community-server-5.7.26-1.el7.x86_64.rpm
-rwxr-xr-x 1 root root 18672 12月 16 11:00 mysqlInstall.sh
- 执行自动化安装脚本开始安装
[root@mysql143 product]# ./mysqlInstall.sh rpm 5.7.26
##### mysql安装程序2.0 #####
1.安装前准备
1.1修改操作系统配置
修改系统内核参数:
vm.swappiness = 1
net.ipv4.ip_local_port_range = 20000 65535
检查io调度策略(推荐HDD硬盘设置为deadline,SSD硬盘设置为NOOP):
noop [deadline] cfq
noop [deadline] cfq
noop [deadline] cfq
noop [deadline] cfq
noop [deadline] cfq
noop [deadline] cfq
noop [deadline] cfq
配置limits:
mysql soft nproc 65536
mysql soft nofile 655360
mysql soft stack 10240
1.2创建mysql用户
mysql用户已存在,无需创建
2.安装配置mysql
2.1安装mysql软件
不存在已安装的mysql包,继续安装程序...
请先安装软件包perl-DBD-MySQL
提示需要安装perl-DBD-MySQL包,通过yum安装:yum -y install perl-DBD-MySQL。
继续重新运行安装脚本
[root@mysql143 product]# ./mysqlInstall.sh rpm 5.7.26
##### mysql安装程序2.0 #####
1.安装前准备
1.1修改操作系统配置
修改系统内核参数:
vm.swappiness = 1
net.ipv4.ip_local_port_range = 20000 65535
检查io调度策略(推荐HDD硬盘设置为deadline,SSD硬盘设置为NOOP):
noop [deadline] cfq
noop [deadline] cfq
noop [deadline] cfq
noop [deadline] cfq
noop [deadline] cfq
noop [deadline] cfq
noop [deadline] cfq
配置limits:
mysql soft nproc 65536
mysql soft nofile 655360
mysql soft stack 10240
1.2创建mysql用户
mysql用户已存在,无需创建
2.安装配置mysql
2.1安装mysql软件
系统已安装以下mysql rpm包:
mariadb-libs-5.5.64-1.el7.x86_64
继续安装可能会或覆盖已安装的包,是否继续?(Y:是;N:否):
选择Y,回车继续
开始安装mysql rpm包...
警告:mysql-community-common-5.7.26-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中... ################################# [100%]
正在升级/安装...
1:mysql-community-common-5.7.26-1.e################################# [ 20%]
2:mysql-community-libs-5.7.26-1.el7################################# [ 40%]
3:mysql-community-client-5.7.26-1.e################################# [ 60%]
4:mysql-community-server-5.7.26-1.e################################# [ 80%]
5:mysql-community-libs-compat-5.7.2################################# [100%]
安装成功!
2.2创建配置文件
初始化配置文件完成
2.3初始化数据目录
开始初始化数据目录...
初始化完成
2.4配置mysql系统服务
配置完成
2.5启动mysql服务
检查mysql服务状态...
mysql服务尚未启动,开始启动...
启动成功
2.6初始化root@localhost用户密码
请为"root@localhost"用户输入一个新密码:
请重新输入新密码:
输入一个自定义密码如:root1234,回车继续
密码设置成功
2.7配置GTID半同步复制参数
配置完成,重启mysql服务...
启动成功
自此通过自动化脚本安装MySQL 5.7.26完成。
- 我们可以通过查看脚本里面的mysql参数配置是否写入/etc/my.cnf配置文件确认安装是否正常完成
[root@mysql143 product]# vim /etc/my.cnf
4.MySQL参数配置(供参考)
- 文末给出一些MySQL数据库的相关参数配置,仅供参考,参数值可根据系统实际情况进行调整,不作为标准规范
#client组参数
port=3306
socket=/home/db/mysql/data/mysql.sock
#mysql组参数
prompt=\u@\h[\d]>
#mysqld组参数
socket=/home/db/mysql/data/mysql.sock
pid_file=/home/db/mysql/data/mysqld.pid
server_id=10
port=3306
datadir=/home/db/mysql/data
tmpdir=/home/db/mysql/tmp
innodb_autoinc_lock_mode=2
innodb_buffer_pool_instances=4
innodb_buffer_pool_size=8G
innodb_flush_method=O_DIRECT
innodb_flush_log_at_timeout=2
innodb_flush_log_at_trx_commit=1
innodb_io_capacity=4000
innodb_lock_wait_timeout=600
innodb_log_buffer_size=32M
innodb_log_file_size=2G
innodb_log_files_in_group=4
innodb_max_undo_log_size=2G
innodb_page_cleaners=4
innodb_print_all_deadlocks=ON
innodb_purge_rseg_truncate_frequency=16
innodb_read_io_threads=16
innodb_write_io_threads=16
innodb_thread_concurrency=8
innodb_temp_data_file_path=ibtmp1:12M:autoextend:max:2G
innodb_undo_directory=/home/db/mysql/data
innodb_undo_log_truncate=1
innodb_undo_tablespaces=4
innodb_open_files=4000
table_open_cache=4000
table_open_cache_instances=4
transaction_isolation=READ-COMMITTED
lower_case_table_names=1
autocommit=1
character_set_server=utf8mb4
collation_server=utf8mb4_bin
default_time_zone='+8:00'
slave_skip_errors=ddl_exist_errors
max_connections=4000
wait_timeout=28800
interactive_timeout=28800
sort_buffer_size=8M
read_rnd_buffer_size=1M
join_buffer_size=2M
tmp_table_size=64M
max_heap_table_size=128M
max_allowed_packet=64M
skip_name_resolve=ON
#日志
log_error=/home/db/mysql/log/error.log
log_bin=/home/db/mysql/binlog/mysql_bin
slow_query_log_file=/home/db/mysql/log/slow.log
log_slow_admin_statements=1
log_queries_not_using_indexes=1
log_throttle_queries_not_using_indexes=10
long_query_time=1
slow_query_log=1
sync_binlog=1
log_bin_trust_function_creators=1
binlog_format=ROW
binlog_cache_size=2M
expire_logs_days=7
relay_log=/home/db/mysql/relaylog/relay_log
relay_log_index=/home/db/mysql/relaylog/relay_log.index
relay_log_info_repository=TABLE
master_info_repository=TABLE
relay_log_recovery=1
relay_log_purge=1
log_timestamps=system
log_slave_updates=1
#performance_schema监控
performance_schema_instrument='memory/%=COUNTED'
performance_schema_instrument='wait/%=COUNTED'
5.通用数据库配置
- 数据库字符集配置
在数据库设计开发阶段,要求必须使用utf8mb4字符集,此字符集对汉字支持较好,也便于扩展输入其他国家字符,注意在该字符集下每个中文字符最多占4个字节来存储,和ZHS16GBK等使用两个字节存储中文字符不同。
本文档没有过多涉及关于MySQL主从复制的内容,重点是对单节点MySQL数据库搭建的指导和建议,如需要搭建MHA架构主从MySQL,请参考《MHA安装手册》。