數(shù)據(jù)庫安裝部署_MySQL(5.7 & 8安裝配置)
1.前言
1.1 編寫目的
本文檔針成都開發(fā)中心MySQL安裝部署提供規(guī)范化指導(dǎo)舷暮,提供兩種安裝部署方案:
使用自動化安裝腳本進行安裝
使用官網(wǎng)下載的rpm包進行手動安裝
以上兩種方法均可以完成MySQL數(shù)據(jù)庫安裝崩哩,讀者可根據(jù)實際情況選擇合適的安裝方案知押。
1.2 前提和假設(shè)
如非特別說明,本指導(dǎo)手冊敘述的產(chǎn)品特性、操作命令吹零、用戶界面均基于MySQL 5.7.26和MySQL 8.0.22版本晰房,可能有不適用于其它版本的情況。如遇此情況窍荧,請參考其它版本廠商技術(shù)手冊中對應(yīng)的說明辉巡。
1.3 適用范圍
本指導(dǎo)手冊適用于成都開發(fā)中心測試環(huán)境安裝部署新的MySQL數(shù)據(jù)庫,配置規(guī)范僅供參考蕊退,各新老系統(tǒng)可根據(jù)實際情況自行調(diào)整相關(guān)配置參數(shù)值郊楣。
1.4 預(yù)期讀者
成都開發(fā)中心的項目基礎(chǔ)設(shè)施可行性研究、設(shè)計和實施人員瓤荔,項目組應(yīng)用系統(tǒng)設(shè)計人員净蚤,相關(guān)運行維護技術(shù)人員。
2.操作系統(tǒng)要求
2.1 參數(shù)設(shè)置
操作系統(tǒng)內(nèi)核參數(shù)參照行內(nèi)Linux安裝配置規(guī)范進行設(shè)置输硝,建議值如下:
| 參數(shù)名稱 | 參數(shù)含義 | 默認值 | 建議值 |
| :--------------------------- | :-------------------------------------- | :----------------------------- | :------------------------ |
| fs.aio-max-nr | 異步I/O總數(shù) | 65535 | 4194304 |
| fs.file-max | 系統(tǒng)最大文件句柄數(shù) | 根據(jù)主機硬件配置自動生成默認值 | 6815744 |
| kernel.shmall | 系統(tǒng)可使用的共享內(nèi)存的總量(pages) | 根據(jù)主機硬件配置自動生成默認值 | 167772160 |
| kernel.shmmax | 內(nèi)核所允許的最大共享內(nèi)存段的大小(bytes) | 根據(jù)主機硬件配置自動生成默認值 | 687194767360 |
| kernel.shmmni | 用于整個系統(tǒng)的共享內(nèi)存段的最大數(shù)目(個)| 4096 | 4096 |
| kernel.sem | 信號量設(shè)置 | 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 用戶和組
- 創(chuàng)建如下用戶及用戶組:
| 名稱 | 說明 |
| :---- | :------------------------------------- |
| 用戶 | mysql今瀑,id為321,家目錄為/home/db/mysql |
| 組 | mysql点把,id為320 |
- 創(chuàng)建mysql用戶操作命令如下
[root@mysql143 ~]# groupadd -g 320 mysql
[root@mysql143 ~]# useradd -d /home/db/mysql -u 321 -g mysql mysql
- 設(shè)置mysql用戶環(huán)境變量橘荠,修改/home/db/mysql/.bash_profile為如下內(nèi)容:
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
將以下內(nèi)容追加到y(tǒng)um.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
元數(shù)據(jù)緩存已建立
2.3.2 主機名配置
- 確認主機名
[root@mysql143 ~]# cat /etc/hostname
mysql143
2.3.3 關(guān)閉額外的服務(wù)
- 參照Linux安裝配置規(guī)范,關(guān)閉如下服務(wù):
[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 禁用額外的服務(wù)
- 參照Linux安裝配置規(guī)范优训,禁用如下服務(wù):
[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 關(guān)閉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
編輯結(jié)束后退出朵你,可以選擇重啟機器使配置生效,也可以選擇使用root用戶運行以下命令立即關(guān)閉SELINUX
[root@mysql143 selinux]# setenforce 0
setenforce: SELinux is disabled
2.3.6 關(guān)閉FIREWALL(防火墻)
- Linux7版本使用如下命令:
使用root用戶運行以下命令關(guān)閉firewall:
[root@host]#systemctl stop firewalld
運行以下命令型宙,設(shè)置下次啟動系統(tǒng)不啟動firewall:
[root@host]#systemctl disable firewalld
運行以下命令撬呢,如顯示disabled則表示設(shè)置成功:
[root@mysql143 ~]# systemctl list-unit-files|grep firewalld
firewalld.service disabled
- Linux6版本使用如下命令:
使用root用戶運行以下命令關(guān)閉iptables:
[root@host]#service iptables stop
運行以下命令,設(shè)置下次啟動系統(tǒng)不啟動iptables:
[root@host]#chkconfig iptables off
運行以下命令妆兑,如顯示disabled則表示設(shè)置成功:
[root@host]#service iptables status
2.3.7 配置LIMITS
- 根據(jù)Linux7安裝配置規(guī)范魂拦,如果用戶有個性化的值毛仪,請在/etc/security/limits.conf中配置,不得修改/etc/security/limits.d/20-proc.conf文件
| 序號 | 參數(shù) | 參數(shù)名稱 | default | 建議值 |
| :--- | :---------------------- | :-------- | :------- | :------- |
| 1 | 進程最大打開文件數(shù) | nofile | 1024 | 655360 |
| 2 | 進程堆棧 | stack | 10240 | 10240 |
| 3 | 用戶可創(chuàng)建的進程/線程數(shù) | nproc | 1024 | 65536 |
使用root用戶執(zhí)行
[root@mysql143 ~]# cat>>/etc/security/limits.conf <<EOF
> mysql soft nofile 655360
> mysql soft stack 10240
> mysql soft nproc 65536
> EOF
2.3.8 MOUNT參數(shù)
- 新增/home/db/mysql芯勘、/mysqldata箱靴、/mysqltmp、/mysqlbinlog和/mysqlbackup五個掛載點的信息荷愕,mount的時候添加如下參數(shù)來提高性能衡怀。
[root@host]# vi /etc/fstab
/dev/vg01/<lv_name1> /home/db/mysql xfs defaults 0 0
/dev/vg01/<lv_name2> /mysqldata xfs rw,noatime,nodiratime,nobarrier 0 0
/dev/vg01/<lv_name3> /mysqltmp xfs rw,noatime,nodiratime,nobarrier 0 0
/dev/vg01/<lv_name4> /mysqlbinlog xfs rw,noatime,nodiratime,nobarrier 0 0
/dev/vg01/<lv_name5> /mysqlbackup xfs defaults 0 0
[root@host]# mount –a
2.3.9 DISK I/O SCHEDULER
官方推薦io調(diào)度策略為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
檢查/驗證方法:系統(tǒng)啟動正常后,執(zhí)行:
[root@host]cat /sys/block/*/queue/scheduler
如果看到deadline 被總括號選中玉罐,表示正常屈嗤,如
noop anticipatory [deadline] cfq
3.MySQL數(shù)據(jù)庫的安裝
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包時出現(xiàn)報錯缺少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安裝基本完成茫船,我們可以指定數(shù)據(jù)存放路徑寫到/etc/my.cnf配置文件中,如:
datadir=/home/db/mysql/data
需要給目錄授權(quán)mysql用戶權(quán)限癣蟋。
- 啟動MySQL數(shù)據(jù)庫
[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數(shù)據(jù)庫
[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安裝腳本安裝數(shù)據(jù)庫(以版本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
- 執(zhí)行自動化安裝腳本開始安裝
[root@mysql143 product]# ./mysqlInstall.sh rpm 5.7.26
##### mysql安裝程序2.0 #####
1.安裝前準備
1.1修改操作系統(tǒng)配置
修改系統(tǒng)內(nèi)核參數(shù):
vm.swappiness = 1
net.ipv4.ip_local_port_range = 20000 65535
檢查io調(diào)度策略(推薦HDD硬盤設(shè)置為deadline,SSD硬盤設(shè)置為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創(chuàng)建mysql用戶
mysql用戶已存在,無需創(chuàng)建
2.安裝配置mysql
2.1安裝mysql軟件
不存在已安裝的mysql包,繼續(xù)安裝程序...
請先安裝軟件包perl-DBD-MySQL
提示需要安裝perl-DBD-MySQL包,通過yum安裝:yum -y install perl-DBD-MySQL埋泵。
繼續(xù)重新運行安裝腳本
[root@mysql143 product]# ./mysqlInstall.sh rpm 5.7.26
##### mysql安裝程序2.0 #####
1.安裝前準備
1.1修改操作系統(tǒng)配置
修改系統(tǒng)內(nèi)核參數(shù):
vm.swappiness = 1
net.ipv4.ip_local_port_range = 20000 65535
檢查io調(diào)度策略(推薦HDD硬盤設(shè)置為deadline,SSD硬盤設(shè)置為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創(chuàng)建mysql用戶
mysql用戶已存在,無需創(chuàng)建
2.安裝配置mysql
2.1安裝mysql軟件
系統(tǒng)已安裝以下mysql rpm包:
mariadb-libs-5.5.64-1.el7.x86_64
繼續(xù)安裝可能會或覆蓋已安裝的包幔欧,是否繼續(xù)?(Y:是;N:否):
選擇Y,回車繼續(xù)
開始安裝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創(chuàng)建配置文件
初始化配置文件完成
2.3初始化數(shù)據(jù)目錄
開始初始化數(shù)據(jù)目錄...
初始化完成
2.4配置mysql系統(tǒng)服務(wù)
配置完成
2.5啟動mysql服務(wù)
檢查mysql服務(wù)狀態(tài)...
mysql服務(wù)尚未啟動,開始啟動...
啟動成功
2.6初始化root@localhost用戶密碼
請為"root@localhost"用戶輸入一個新密碼:
請重新輸入新密碼:
輸入一個自定義密碼如:root1234礁蔗,回車繼續(xù)
密碼設(shè)置成功
2.7配置GTID半同步復(fù)制參數(shù)
配置完成,重啟mysql服務(wù)...
啟動成功
自此通過自動化腳本安裝MySQL 5.7.26完成。
- 我們可以通過查看腳本里面的mysql參數(shù)配置是否寫入/etc/my.cnf配置文件確認安裝是否正常完成
[root@mysql143 product]# vim /etc/my.cnf
4.MySQL參數(shù)配置(供參考)
- 文末給出一些MySQL數(shù)據(jù)庫的相關(guān)參數(shù)配置雁社,僅供參考浴井,參數(shù)值可根據(jù)系統(tǒng)實際情況進行調(diào)整,不作為標準規(guī)范
#client組參數(shù)
port=3306
socket=/home/db/mysql/data/mysql.sock
#mysql組參數(shù)
prompt=\u@\h[\d]>
#mysqld組參數(shù)
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監(jiān)控
performance_schema_instrument='memory/%=COUNTED'
performance_schema_instrument='wait/%=COUNTED'
5.通用數(shù)據(jù)庫配置
- 數(shù)據(jù)庫字符集配置
在數(shù)據(jù)庫設(shè)計開發(fā)階段霉撵,要求必須使用utf8mb4字符集磺浙,此字符集對漢字支持較好洪囤,也便于擴展輸入其他國家字符,注意在該字符集下每個中文字符最多占4個字節(jié)來存儲撕氧,和ZHS16GBK等使用兩個字節(jié)存儲中文字符不同瘤缩。
本文檔沒有過多涉及關(guān)于MySQL主從復(fù)制的內(nèi)容,重點是對單節(jié)點MySQL數(shù)據(jù)庫搭建的指導(dǎo)和建議伦泥,如需要搭建MHA架構(gòu)主從MySQL,請參考《MHA安裝手冊》剥啤。