一、环境部署
1.克隆rhel9.3虚拟机并命名为rhel9.3-mysql-master
2.远程登录连接
3.修改主机名
[root@localhost ~]# hostnamectl set-hostname mysql-server
[root@localhost ~]# reboot
4.克隆rhel7.9同上操作
二、MySQL源码安装
1.下载MySQL8.0.40
链接:https://downloads.mysql.com/archives/community/
2.利用Xftp上传下载后的安装包并解压
[root@mysql-master ~]# cd /opt/ #上传至该路径
[root@mysql-master opt]# ll
total 479012
-rw-r--r--. 1 root root 490502884 Sep 5 14:29 mysql-boost-8.0.40.tar.gz
[root@mysql-master opt]# tar xf mysql-boost-8.0.40.tar.gz #解压
[root@mysql-master opt]# ll
total 479016
drwxr-xr-x. 32 7161 31415 4096 Sep 18 2024 mysql-8.0.40
-rw-r--r--. 1 root root 490502884 Sep 5 14:29 mysql-boost-8.0.40.tar.gz
[root@mysql-master opt]# cd mysql-8.0.40/
[root@mysql-master mysql-8.0.40]# ls
boost doxygen_resources mysql-test sql
client extra MYSQL_VERSION sql-common
cmake include mysys storage
CMakeLists.txt INSTALL packaging strings
components libbinlogevents plugin support-files
config.h.cmake libbinlogstandalone README testclients
configure.cmake libchangestreams router unittest
CONTRIBUTING.md libmysql run_doxygen.cmake utilities
Docs libservices scripts vio
Doxyfile-ignored LICENSE SECURITY.md
Doxyfile.in man share
[root@mysql-master mysql-8.0.40]#
3.源码部署MySQL8.0.40
# 安装mysql8的依赖软件----------------------------------------------------------
[root@mysql-master ~]# yum install -y git bison openssl-devel ncurses-devel -y
# 安装cmake3-------------------------------------------------------------------
[root@mysql-master ~]# yum list cmake # 查看可安装的版本
可安装的软件包
cmake.x86_64 2.8.12.2-2.el7 baseos
[root@mysql-master ~]# vim /etc/yum.repos.d/epel.repo
添加如下内容:
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0
[root@mysql-master ~]# yum install cmake3 -y # 安装
# 安装gcc-11,找到相关的rpm包上传至linux后解压并安装----------------------------
[root@mysql-master ~]# cd /opt/ # 将gcc-11的安装包上传到该路径下
[root@mysql-master opt]#ll
总用量 534764
-rw-r--r-- 1 root root 57087061 9月 2 14:44 gcc-11.zip
drwxr-xr-x 32 7161 31415 4096 9月 18 2024 mysql-8.0.40
-rw-r--r-- 1 root root 490502884 9月 2 14:29 mysql-boost-8.0.40.tar.gz
[root@mysql-master opt]# yum install unzip -y # 安装unzip
[root@mysql-master opt]# unzip gcc-11.zip # 解压缩
[root@mysql-master opt]# cd gcc-11/
[root@mysql-master gcc-11]# ls
[root@mysql-master gcc-11]# yum install ./*.rpm -y # 安装
[root@mysql-master gcc-11]# source /opt/rh/devtoolset-11/enable # 生效
[root@mysql-master gcc-11]# cat /opt/rh/devtoolset-11/enable >> ~/.bash_profile # 读入
[root@mysql-master gcc-11]# gcc -v # 查看版本
gcc version 11.2.1 20220127 (Red Hat 11.2.1-9) (GCC)
————————————————
版权声明:本文为CSDN博主「叫我Zoe就行」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_75156059/article/details/151122002
4.编译安装mysql8.0.40
[root@master opt]# cd mysql-8.0.40/
[root@master mysql-8.0.40]# mkdir bld
[root@master mysql-8.0.40]# cd bld
[root@master bld]# cmake .. \
-DWITH_BOOST=../boost/boost_1_77_0/ \ #指定MySQL 源码编译所依赖的 Boost 库的路径
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #指定安装路径
-DMYSQL_DATADIR=/data/mysql \ #指定数据目录
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \ #指定套接字文件
-DWITH_INNOBASE_STORAGE_ENGINE=1 \ #指定启用INNODB存储引擎,默认用myisam
-DWITH_EXTRA_CHARSETS=all \ #扩展字符集
-DDEFAULT_CHARSET=utf8mb4 \ #指定默认字符集
-DDEFAULT_COLLATION=utf8mb4_unicode_ci \ #指定默认校验字符集
-DWITH_SSL=system \ #指定MySQL使用系统已安装的 SSL 库
[root@master bld]# make -j 2 ########该过程很久,请耐心等待,利用多核 CPU 资源同时运行 2 个编译进程
[root@master bld]# make install
# 生成启动脚本
[root@mysql-master ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
# 修改环境变量
[root@mysql-master ~]# vim ~/.bash_profile
添加如下内容:
export PATH=$PATH:/usr/local/mysql/bin
[root@mysql-master ~]# source ~/.bash_profile # 生效
# 建立数据库程序运行用户
[root@mysql-master ~]# useradd -M -s /sbin/nologin mysql
# 建立数据库数据目录
[root@mysql-master ~]# mkdir -p /data/mysql/
[root@mysql-master ~]# chown -R mysql:mysql /data/mysql/
# 创建配置文件
[root@mysql-master ~]# vim /etc/my.cnf
全部删出,然后添加如下内容:提示语删掉
[mysqld]
datadir=/data/mysql # 指定数据目录
socket=/data/mysql/mysql.sock # 指定套接字
server_id=136 # 写该主机的主机号即可
log-bin=binlog
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/data/mysql/master.err
pid-file=/data/mysql/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
----------------------------------------------------------------------
# 数据库初始化建立mysql基本数据,注意在输出中查看临时密码
[root@mysql-master ~]# mysqld --initialize --user=mysql
IjhUEt+J>2n.
#启动数据库
[root@mysql-master ~]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/master.err'.
临时密码:. SUCCESS!
#修改数据库密码,新密码为123
[root@mysql-master ~]# mysqladmin -uroot -p password '123'
Enter password: IjhUEt+J>2n. # 临时密码
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
#使用新密码登录数据库
[root@mysql-master ~]# mysql -uroot -p123
mysql>