VMPro-16 + CentOS-8x + Linux-8虚拟机中源码编译安装MySQL-8.0.25完整版

VMPro-16 + CentOS-8x + Linux-8虚拟机中源码编译安装MySQL-8.0.25

文章目录

一)、环境>工具&版本:
01)、运行环境 & 配置
  • 实验室虚拟环境
  • CentOS-8.4_86_64 + Linux-8_86_64
  • CPU & 内存:4 + 4048MB
02)、运用软件 & 工具
  • 虚拟机运行:VMware Workstation Pro-16
  • 远程终端SSH工具:Xshell 7
  • FTP传输工具:Xftp 7
  • 可视化远程连接数据库工具:Navicat 15 for MySQL
03)、MySQL安装版本&方式
  • 安装版本:MySQL-8.0.26
  • 安装方式:源码编译安装

二)、清理 & 防火墙安装设置:
04)、清理 MySQL 的安装环境
yum erase mariadb mariadb-server mariadb-libs mariadb-devel -y
//未找到匹配的参数: mariadb
//未找到匹配的参数: mariadb-server
//未找到匹配的参数: mariadb-libs
//未找到匹配的参数: mariadb-devel
//没有软件包需要移除。
//依赖关系解决。
//无需任何处理。
//完毕!
//这样就省去了查询和删除【mariadb】的步骤,同时也能证明【CentOS-8x】的系统中,已经没有预置【mariadb】了...
05)、关闭&停止 firewall
systemctl stop firewalld.service          
systemctl disable firewalld.service     
systemctl mask firewalld                 
systemctl stop firewalld              
06)、关闭 selinux
sed -ri '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config
setenforce 0                             
07)、安装 iptables 防火墙
yum install iptables-services
  • 编辑防火墙配置文件,开放 mysql 默认端口 3306
vim /etc/sysconfig/iptables
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth0 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
-A FORWARD -p icmp -j ACCEPT
-A FORWARD -i lo -j ACCEPT
-A FORWARD -i eth0 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
  • 覆盖原文件中相应字段的全部内容并开启【3306】端口,【:wq】保存退出。
  • 【iptables】启动 & 开机自启 & 重启设置:
systemctl restart iptables.service                //重启【iptables】生效配置
systemctl enable iptables.service                 //设置【iptables】开机自启动
/usr/libexec/iptables/iptables.init restart       //重置【iptables】
三)、更新 & 依赖和必备软件安装:
08)、系统软件源更新
yum update
09)、基本依赖&必备编译工具安装
yum install -y epel-release git openssl openssl-devel libaio libaio-devel libtirpc libtirpc-devel  pkgconfig perl-JSON.noarch subversion
10)、编译安装ncurses & ncurses-devel
yum -y install ncurses-devel
mkdir lanmpp                                       
cd /root/lanmpp
wget https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.2.tar.gz
tar -xf ncurses-6.2.tar.gz
rm -rf ncurses-6.2.tar.gz
cd ncurses-6.2/
./configure --with-shared --without-debug --without-ada --enable-overwrite            
 make && make install
11)、编译安装 rpcsvc-proto
cd ..
wget https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4.2/rpcsvc-proto-1.4.2.tar.xz
tar -xf rpcsvc-proto-1.4.2.tar.xz
rm -rf rpcsvc-proto-1.4.2.tar.xz
cd rpcsvc-proto-1.4.2/
./configure --sysconfdir=/etc && make             
make install
12)、安装 cmake & bison
cd ..
yum install -y cmake bison
  • 确认一下 CentOS-8.4 中默认 CMake 的版本号
cmake --version
//cmake version 3.18.2
  • 符合编译安装 mysqlcmake 最低版本要求
13)、安装&升级 gcc gcc-c++
  • gcc 版本查询
gcc --version
//gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1)
  • 符合编译最低要求,暂时不用升级,yum 安装后配置一下即可
yum -y install gcc
yum -y install gcc-c++
dnf install centos-release-stream             
dnf install gcc-toolset-10-gcc-c++
dnf install gcc-toolset-10-gcc-libasan-devel          //若遇报错可忽略,可能是因为已安装过了...
source /opt/rh/gcc-toolset-10/enable
echo "int main(void) {}" > t.c
  • 安装留底备查,到时可以分析 & 解决因此而发的问题
===================================================================================
 软件包                     架构        版本                     仓库         大小
===================================================================================
安装:
 centos-release-stream      x86_64      8.1-1.1911.0.7.el8       extras       11 k
事务概要
===================================================================================
依赖关系解决。
===================================================================================
 软件包                          架构    版本              仓库               大小
===================================================================================
安装:
 gcc-toolset-10-gcc-c++          x86_64  10.2.1-8.2.el8    appstream          12 M
安装依赖关系:
 environment-modules             x86_64  4.5.2-1.el8       baseos            421 k
 gcc-toolset-10-gcc              x86_64  10.2.1-8.2.el8    appstream          31 M
 gcc-toolset-10-libstdc++-devel  x86_64  10.2.1-8.2.el8    appstream         2.9 M
 gcc-toolset-10-runtime          x86_64  10.1-0.el8        appstream          24 k
 scl-utils                       x86_64  1:2.0.2-14.el8    Stream-AppStream   47 k

事务概要
===================================================================================
安装  6 软件包

总下载:47 M
安装大小:123 M
14)、下载 boost
mkdir /usr/local/boost
cd  /usr/local/boost
wget https://boostorg.jfrog.io/artifactory/main/release/1.73.0/source/boost_1_73_0.tar.gz
  • 说明:不用解压&安装,mysql-8.0.25 版匹配 boost 版本是 boost_1_73_0
四)、【MySQL】源码编译&安装:
15)、创建 mysql 安装目录:
mkdir -p /usr/local/mysql
16)、创建 MySQL 系统用户(并限制该用户登录系统)
groupadd -r mysql && useradd -r -g mysql -s /sbin/nologin -M mysql 
useradd -g mysql mysql
17)、下载 mysql-8.0.25 源码版
cd /root/lanmpp
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.25.tar.gz
tar -xvf mysql-8.0.25.tar.gz
rm -rf mysql-8.0.25.tar.gz
cd mysql-8.0.25/ 
18)、预编译&安装 mysql
cmake -DWITH_BOOST=/usr/local/boost \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DSYSCONFDIR=/etc \
-DINSTALL_MANDIR=/usr/share/man \
-DEXTRA_CHARSETS=all \
-DCMAKE_C_COMPILER=/opt/rh/gcc-toolset-10/root/usr/bin/gcc \
-DCMAKE_CXX_COMPILER=/opt/rh/gcc-toolset-10/root/usr/bin/g++ \
-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 \
-DFORCE_INSOURCE_BUILD=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1 \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_USER=mysql

echo $?
0     
    
make -j 4
make instal

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tt4ewBa2-1628316859844)(C:/Users/86189/AppData/Roaming/Typora/typora-user-images/image-20210806035000142.png)]

五)、配置【MySQL】& 初始化【MySQL】数据库:
19)、更改【MySQL】安装目录的用户归属
chown -R mysql:mysql /usr/local/mysql
20)、创建数据库目录 & 设置【MySQL】数据库用户归属 & 权限
mkdir -p /data/mysql/
chown -R mysql:mysql /data/mysql/ 
ls -lrt /usr/local/mysql
21)、初始化【MySQL】数据库
cd /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
=========================================================================================================
//[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: s0>hol&pFIoi
//从上面的打印信息中可以看:初始化【MySQL】数据库后,得到【root】用户的临时密码:s0>hol&pFIoi
  • 注:【–initialize】表示默认生成密码,【 --initialize-insecure】 表示不生成密码,密码为空,【–datadir】目录下不能有数据文件
22)、创建&设置【MySQL】配置文件 my.cnf
mv /etc/my.cnf  /etc/my.cnf.old
vim /etc/my.cnf
    
# Example MySQL config file for small systems.  
#  
# This is for a system with little memory (<= 64M) where MySQL is only used  
# from time to time and it's important that the mysqld daemon  
# doesn't use much resources.  
#  
# MySQL programs look for option files in a set of  
# locations which depend on the deployment platform.  
# You can copy this option file to one of those  
# locations. For information about these locations, see:  
# http://dev.mysql.com/doc/mysql/en/option-files.html  
#  
# In this file, you can use all long options that a program supports.  
# If you want to know which options a program supports, run the program  
# with the "--help" option.  

# The following options will be passed to all MySQL clients  
[client]  
default-character-set=utf8mb4   
#password   = your_password  
port        = 3306 
socket      = /tmp/mysql.sock  

# Here follows entries for some specific programs  

# The MySQL server   
[mysqld]  

#配置mysql的文件夹 和 mysql data目录
basedir                = /usr/local/mysql
datadir                = /data/mysql
default-storage-engine = INNODB  
character-set-server   = utf8mb4  
collation-server       = utf8mb4_general_ci  
port                   = 3306 
socket                 = /tmp/mysql.sock  
skip-external-locking  
key_buffer_size        = 16K  
max_allowed_packet     = 1M  
table_open_cache       = 4 
sort_buffer_size       = 64K  
read_buffer_size       = 256K  
read_rnd_buffer_size   = 256K  
net_buffer_length      = 2K  
thread_stack           = 128K  

# Don't listen on a TCP/IP port at all. This can be a security enhancement,  
# if all processes that need to connect to mysqld run on the same host.  
# All interaction with mysqld must be made via Unix sockets or named pipes.  
# Note that using this option without enabling named pipes on Windows  
# (using the "enable-named-pipe" option) will render mysqld useless!  
#   
#skip-networking  
server-id              = 1 

# Uncomment the following if you want to log updates  
#log-bin=mysql-bin  

# binary logging format - mixed recommended  
#binlog_format        = mixed  

# Causes updates to non-transactional engines using statement format to be  
# written directly to binary log. Before using this option make sure that  
# there are no dependencies between transactional and non-transactional  
# tables such as in the statement INSERT INTO t_myisam SELECT * FROM  
# t_innodb; otherwise, slaves may diverge from the master.  
#binlog_direct_non_transactional_updates=TRUE  

# Uncomment the following if you are using InnoDB tables  
#innodb_data_home_dir = /usr/local/mysql/data  
#innodb_data_file_path = ibdata1:10M:autoextend  
#innodb_log_group_home_dir = /usr/local/mysql/data  
# You can set .._buffer_pool_size up to 50 - 80 %  
# of RAM but beware of setting memory usage too high  
#innodb_buffer_pool_size = 16M  
#innodb_additional_mem_pool_size = 2M  
# Set .._log_file_size to 25 % of buffer pool size  
#innodb_log_file_size = 5M  
#innodb_log_buffer_size = 8M  
#innodb_flush_log_at_trx_commit = 1 
#innodb_lock_wait_timeout = 50 
binlog_format=ROW
    
[mysqldump]  
quick  
max_allowed_packet        = 2G  

[mysql]  
no-auto-rehash  
# Remove the next comment character if you are not familiar with SQL  
#safe-updates  

[myisamchk]  
key_buffer_size           = 8M  
sort_buffer_size          = 8M  

[mysqlhotcopy]  
interactive-timeout 
chmod 664 /etc/my.cnf
六)、【MySQL】启动 & 环境变量设置:
23)、设置【MySQL】启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
24)、设置【MySQL】 开机自启动
chkconfig --add mysqld
chkconfig mysqld on
25)、添加【MySQL】至环境变量
echo export PATH=$PATH:/usr/local/mysql/bin >>/etc/profile
source /etc/profile
七)、启动 & 停止和重启【MySQL】服务:
26)、启动【MySQL】
  • 使用 safe_mysqld 启动 MySQL
/usr/local/mysql/bin/mysqld_safe --user=mysql &
//太慢了,不建议使用...
  • 使用 mysqld 脚本启动 MySQL
/etc/init.d/mysqld start
//Starting MySQL SUCCESS! 
  • 使用 service 启动 MySQL 服务
service mysqld start
  • MySQL 服务多实例启动 & 停止
mysqld_multi start      //多实例启动`MySQL` 
mysqld_multi stop       //多实例停止`MySQL` 
27)、停止【MySQL】
  • 使用 mysqld 脚本停止 MySQL
/etc/inint.d/mysql stop
  • 使用 service 停止 MySQL 服务
service mysql stop
  • 使用 mysqladmin 后台停止 MySQL 服务
/usr/local/mysql/bin/mysqladmin -uroot -p shutdown
mysqladmin shutdown
  • 注:停止 & 关闭 mysql,最好别用 killall 方式
killall mysqld
killall -9 mysqld
pkill -9 mysqld
28)、重启 MySQL 服务
  • 使用 mysqld 脚本重启 MySQL
/etc/inint.d/mysql restart
  • 使用 service 重启 MySQL 服务
service mysqld restart
八)、查看 【MySQL】端口 & 服务进程状态

29)、查看 MySQL 服务端口

netstat -tunpl | grep 3306
//打印结果:    
tcp6       0      0 :::33060                :::*                    LISTEN      224664/mysqld       
tcp6       0      0 :::3306                 :::*                    LISTEN      224664/mysqld       

30)、查看 MySQL 服务进程状态

  • 带目录 & 日志查看
ps -ef | grep mysql
  • 使用 service 查看 MySQL 服务进程状态
service mysqld status
//SUCCESS! MySQL running (224664)
  • 使用 mysqld 查看 MySQL 服务进程状态
systemctl status mysqld
● mysqld.service - LSB: start and stop MySQL
   Loaded: loaded (/etc/rc.d/init.d/mysqld; generated)
   Active: active (exited) since Fri 2021-08-06 18:48:10 CST; 14min ago
     Docs: man:systemd-sysv-generator(8)
  Process: 224315 ExecStop=/etc/rc.d/init.d/mysqld stop (code=exited, status=0/SUC>
  Process: 227547 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/S>
    Tasks: 0 (limit: 23364)
   Memory: 0B
   CGroup: /system.slice/mysqld.service
九)、【MySQL】基本操作:
31)、登录 【MySQL】
mysql -uroot -p's0>hol&pFIoi'
32)、修改【MySQL】root 用户初始密码
mysql>alter user  root@'localhost' identified by "123322";
Query OK, 0 rows affected (0.02 sec)
  • 退出后重启 MySQL
mysql> \q                 //或exit退出 
service mysqld restart
33)、实际简单操作【MySQL】
  • 用新密码登录 MySQL
mysql -uroot -p'123456'
//以下的警告(命令行输入密码不安全),在非共用mysql的情况下,可以无视...    
mysql: [Warning] Using a password on the command line interface can be insecure.
34)、创建【MySQL】数据库 test,并【指定字符集 utf8mb4
mysql> create database test character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.01 sec)
  • 查看创建的【MySQL】数据库 test
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test               |
+--------------------+
5 rows in set (0.00 sec)
35)、创建【MySQL】用户并授予全局 & 远程登录权限
  • 创建【MySQL】本地用户 & 查看该用户权限 & 密码
CREATE USER 'hhdata' @' localhost' IDENTIFIED BY '123322';
Query OK, 0 rows affected (0.03 sec)
    
mysql> use mysql;
mysql> SELECT host, user, '123322' FROM user WHERE user='hhdata';
+-----------+--------+----------+
| host      | user   |  123322  |
+-----------+--------+----------+
| localhost | hhdata |  123322  |
+-----------+--------+----------+
1 row in set (0.00 sec)    
  • 设置该用户【MySQL】全局 & 远程登录权限
mysql> create user hhdata@'%' identified by '123322';
Query OK, 0 rows affected (0.01 sec)

grant all privileges on test.* to hhdata;
Query OK, 0 rows affected (0.01 sec)    
    
mysql>  flush privileges;
Query OK, 0 rows affected (0.00 sec)
  • 查看【MySQL】用户 & 某个用户的权限
mysql> select user host from mysql.user;
+------------------+
| host             |
+------------------+
| hhdata           |
| hhdata           |
| mysql.infoschema |
| mysql.session    |
| mysql.sys        |
| root             |
+------------------+
6 rows in set (0.00 sec)
    
mysql> show grants for 'hhdata'@'%'; 
+--------------------------------------------------+
| Grants for hhdata@%                              |
+--------------------------------------------------+
| GRANT USAGE ON *.* TO `hhdata`@`%`               |
| GRANT ALL PRIVILEGES ON `test`.* TO `hhdata`@`%` |
+--------------------------------------------------+
2 rows in set (0.01 sec)

mysql> quit
Bye
  • 退出后重启 MySQL
mysql> quit
Bye

service mysqld restart
//Shutting down MySQL. SUCCESS! 
//Starting MySQL.. SUCCESS! 
36)、【Navicat 15 for MySQL】远程连接 & 登录测试

Navicat远程连接&登录

  • 远程连接 & 登录成功!
    • 至此!VM虚拟机源码编译安装【MySQL-8.0.25】完美成功!
    • 说明:按本文方法安装【MySQL-8.0.26】时却有报错,目前还不知道是何原因,待问题解决了再分享…
    • 有点难度,耗时也很长,发文辛苦!如果对你有帮助,就请点个赞!留下你的高见呗…
  • 更多【IT&编程】知识内容,请关注本人【sngee】的博客…

学如人生,砥砺前行…
互勉互励,志之所趋…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值