一、环境准备
1.1 操作系统
建议操作系统内存给到8G [root@rhel76 ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.6 (Maipo) 共享内存大小调整 [root@rhel76 ~]# free -m [root@rhel76 ~]# df -h /dev/shm/ Filesystem Size Used Avail Use% Mounted on tmpfs 3.9G 0 3.9G 0% /dev/shm 调整方法:修改/etc/fstab [root@rhel76 ~]# vi /etc/fstab tmpfs /dev/shm tmpfs defaults,size=6144M 0 0 [root@rhel76 ~]# cat /etc/fstab | grep shm #重新挂载 [root@rhel76 ~]# mount -o remount /dev/shm
1.2 磁盘空间
[root@rhel76 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/rhel-root xfs 30G 4.1G 26G 14% / devtmpfs devtmpfs 2.0G 0 2.0G 0% /dev tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs tmpfs 2.0G 13M 2.0G 1% /run tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup /dev/mapper/rhel-u01 xfs 28G 33M 28G 1% /u01 /dev/sda1 xfs 950M 164M 786M 18% /boot tmpfs tmpfs 394M 4.0K 394M 1% /run/user/42 tmpfs tmpfs 394M 56K 394M 1% /run/user/0 /dev/sr0 iso9660 4.2G 4.2G 0 100% /run/media/root/RHEL-7.6 Server.x86_64
1.3 关闭防火墙
[root@rhel76 ~]# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2021-11-25 22:32:51 UTC; 7h left Docs: man:firewalld(1) Main PID: 9694 (firewalld) Tasks: 2 CGroup: /system.slice/firewalld.service └─9694 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid Nov 25 22:32:50 rhel76 systemd[1]: Starting firewalld - dynamic firewall daemon... Nov 25 22:32:51 rhel76 systemd[1]: Started firewalld - dynamic firewall daemon. [root@rhel76 ~]# systemctl stop firewalld [root@rhel76 ~]# systemctl disable firewalld Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service. Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
1.4 关闭 selinux
[root@rhel76 ~]# getenforce Enforcing [root@rhel76 ~]# cp /etc/selinux/config /etc/selinux/config_`date +"%Y%m%d_%H%M%S"` [root@rhel76 ~]# sed -i 's/SELINUX\=enforcing/SELINUX\=disabled/g' /etc/selinux/config 以上修改完后重启 [root@rhel76 ~]# reboot [root@rhel76 ~]# getenforce Disabled [root@rhel76 ~]# sestatus SELinux status: disabled
1.5 Host解析
[root@rhel76 ~]# hostnamectl set-hostname jeames007 [root@rhel76 ~]# hostname jeames007 [root@rhel76 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.6.81 jeames007
1.6 卸载mariadb
只有rpm安装方式是需要卸载旧版本的mysql,二进制安装和编译安装不需要,但是要注意端口冲突 rpm若不卸载旧版本,在安装时,它会提示你mysql已安装,此时是无法再次安装的,只有通过yum更新版本 为了保证后续操作不会产生其他冲突,我们卸载原有的mysql 注:在卸载旧的MySQL之前,注意备份数据 #查看是否已安装mysql数据库 [root@jeames007 ~]# rpm -qa|grep mysql #卸载mysql [root@jeames007 ~]# rpm -qa|grep mysql|xargs rpm -e --nodeps #卸载mariadb [root@jeames007 ~]# rpm -qa|grep mariadb mariadb-libs-5.5.60-1.el7_5.x86_64 [root@jeames007 ~]# rpm -qa|grep mariadb-libs|xargs rpm -e --nodeps
1.7 Mysql源码下载
https://dev.mysql.com/downloads/mysql/ mysql-boost-8.0.27.tar.gz MD5: 80310c5a1b24145fa072927ab99a4c0d
二、 yum安装及配置
2.1 挂载本地光盘镜像
[root@jeames007 ~]# mkdir -p /mnt/dvd/ [root@jeames007 ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/rhel-root xfs 30G 4.1G 26G 14% / devtmpfs devtmpfs 2.0G 0 2.0G 0% /dev tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm tmpfs tmpfs 2.0G 13M 2.0G 1% /run tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup /dev/sda1 xfs 950M 164M 786M 18% /boot /dev/mapper/rhel-u01 xfs 28G 33M 28G 1% /u01 tmpfs tmpfs 394M 8.0K 394M 1% /run/user/42 tmpfs tmpfs 394M 20K 394M 1% /run/user/0 /dev/sr0 iso9660 4.2G 4.2G 0 100% /run/media/root/RHEL-7.6 Server.x86_64 [root@jeames007 ~]# mount /dev/sr0 /mnt/dvd mount: /dev/sr0 is write-protected, mounting read-only
2.2 配置yum源
[root@jeames007 ~]# cd /etc/yum.repos.d/ cat >> /etc/yum.repos.d/redhat.repo << "EOF" [rhel7] name=jeames repo baseurl=file:///mnt/dvd/ gpgcheck=0 EOF
2.3 yum安装
[root@jeames007 ~]# yum -y install lrzsz wget perl-Digest-MD5 [root@jeames007 ~]# yum -y install ncurses-devel libaio-devel [root@jeames007 ~]# yum -y install cmake gcc gcc-c++ [root@jeames007 ~]# yum install –y openssl openssl-devel ncurses ncurses-devel
三、 系统包升级
3.1 cmake升级
cmake升级,MySQL8版本需要cmake3来编译,此时需要安装cmake3.5.1及以上的版本
参考博客:cmake如何进行版本升级
3.2 GCC升级
GCC是Linux下的C语言编译工具, mysql8.0版本源码编译完全由C和C++编写, 要求必须安装GCC5.3或以上版本。 GCC编译这个过程很慢,经历了1个小时40分钟,耐心等待
参考博客:Linux gcc升级全过程,过程超详细
3.3 devtoolset包安装
下载网站: https://pkgs.org/download/rpm-build [root@jeames007 ~]# rpm -ivh devtoolset-10-runtime-10.0-0.el7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:devtoolset-10-runtime-10.0-0.el7 ################################# [100%] [root@jeames007 ~]# rpm -ivh devtoolset-10-binutils-2.35-5.el7.2.x86_64.rpm warning: devtoolset-10-binutils-2.35-5.el7.2.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID f2ee9d55: NOKEY Preparing... ################################# [100%] Updating / installing... 1:devtoolset-10-binutils-2.35-5.el7################################# [100%] [root@jeames007 ~]# rpm -ivh devtoolset-10-gcc-10.2.1-11.1.el7.x86_64.rpm Preparing... ################################# [100%] Updating / installing... 1:devtoolset-10-gcc-10.2.1-11.1.el7################################# [100%] [root@jeames007 ~]# rpm -ivh devtoolset-10-libstdc++-devel-10.2.1-11.1.el7.x86_64.rpm warning: devtoolset-10-libstdc++-devel-10.2.1-11.1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID f2ee9d55: NOKEY Preparing... ################################# [100%] Updating / installing... 1:devtoolset-10-libstdc++-devel-10.################################# [100%] [root@jeames007 ~]# rpm -ivh devtoolset-10-gcc-c++-10.2.1-11.1.el7.x86_64.rpm warning: devtoolset-10-gcc-c++-10.2.1-11.1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID f2ee9d55: NOKEY Preparing... ################################# [100%] Updating / installing... 1:devtoolset-10-gcc-c++-10.2.1-11.1################################# [100%] [root@jeames007 ~]# rpm -qa | grep devtoolset
四、安装及配置
4.1 编译
[root@jeames007 ~]# mkdir /soft [root@jeames007 ~]# mv mysql-boost-8.0.27.tar.gz /soft/ [root@jeames007 ~]# cd /soft [root@jeames007 soft]# tar -zxf mysql-boost-8.0.27.tar.gz [root@jeames007 soft]# ll total 285340 drwxr-xr-x 31 7161 31415 4096 Sep 28 13:22 mysql-8.0.27 -rw-r--r-- 1 root root 292184025 Nov 25 15:08 mysql-boost-8.0.27.tar.gz [root@jeames007 soft]# cd mysql-8.0.27 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DSYSCONFDIR=/etc \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_FEDERATED_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DENABLED_LOCAL_INFILE=1 \ -DENABLE_DTRACE=0 \ -DDEFAULT_CHARSET=utf8mb4 \ -DDEFAULT_COLLATION=utf8mb4_general_ci \ -DWITH_EMBEDDED_SERVER=1 \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST=/soft/mysql-8.0.27/boost/boost_1_73_0 \ -DFORCE_INSOURCE_BUILD=1 [root@jeames007 ~]# make -j4 --此处编译需要1个小时,一定要耐心等待 [root@jeames007 ~]# make install
4.2 用户及组
groupadd mysql useradd -g mysql mysql chown -R mysql:mysql /usr/local/mysql
4.3 参数文件
cat > /etc/my.cnf <<"EOF" [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data port=3306 server_id=80273306 log-bin skip-name-resolve character_set_server=utf8mb4 default-time-zone = '+8:00' log_timestamps = SYSTEM EOF
4.4 初始化
/usr/local/mysql/bin/mysqld --initialize-insecure --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
4.5 环境变量
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /root/.bashrc source /root/.bashrc
4.6 启动Mysql
#启动 MySQL mysqld_safe & #登录 mysql,默认密码为空 mysql -uroot -p #关闭 MySQL mysqladmin -uroot -p shutdown