Linux第十周(二进制安装MYSQL5.7,编译安装MYSQL5.7,二进制安装mariadb10.4)

Posted JINX穆空

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux第十周(二进制安装MYSQL5.7,编译安装MYSQL5.7,二进制安装mariadb10.4)相关的知识,希望对你有一定的参考价值。

2、通过编译、二进制安装mysql5.7

二进制安装MYSQL5.7

#创建目录并进入
mkdir /server/
cd /server
#上传刚下载的5.7的二进制包
[root@centos8-2 server]# ll
total 650940
-rw-r--r-- 1 root root 666559924 Jan 25 10:18 mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
#解包
tar xf mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
#做软链接
[root@centos8-2 server]# ln -s mysql-5.7.36-linux-glibc2.12-x86_64 /server/mysql
[root@centos8-2 server]# ll
total 650940
lrwxrwxrwx 1 root root 35 Jan 26 10:49 mysql -> mysql-5.7.36-linux-glibc2.12-x86_64
drwxr-xr-x 9 root root 129 Jan 26 10:48 mysql-5.7.36-linux-glibc2.12-x86_64
-rw-r--r-- 1 root root 666559924 Jan 25 10:18 mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz
#创建用户
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
#设置环境变量并执行
[root@centos8-2 server]# vim /etc/profile.d/mysql.sh
export PATH=/server/mysql/bin:$PATH
source /etc/profile
#授权和创数据目录
chown -R mysql.mysql /server/*
mkdir /data/mysql/data -p
chown -R mysql.mysql /data
#安装依赖
[root@centos8-2 server]# yum install -y libaio-devel
初始化
# 5.6 版本 初始化命令 /application/mysql/scripts/mysql_install_db
# 5.7跳过密码初始化
[root@centos8-2 server]# mysqld --initialize-insecure --user=mysql --basedir=/server/mysql --datadir=/data/mysql/data
2022-01-26T02:57:10.811504Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-01-26T02:57:10.938434Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-01-26T02:57:10.960969Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-01-26T02:57:11.016304Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: a82719f7-7e53-11ec-8563-000c29ffc567.
2022-01-26T02:57:11.018223Z 0 [Warning] Gtid table is not ready to be used. Table mysql.gtid_executed cannot be opened.
2022-01-26T02:57:11.872502Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-01-26T02:57:11.872527Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-01-26T02:57:11.872974Z 0 [Warning] CA certificate ca.pem is self signed.
2022-01-26T02:57:12.288739Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
#复制启动脚本
[root@centos8-2 server]# cp /server/mysql/support-files/mysql.server /etc/init.d/mysqld
#配置文件
[root@centos8-2 server]# vim /etc/my.cnf
er=mysql
er=mysql
[mysqld]
user=mysql
basedir=/server/mysql
datadir=/data/mysql/data
server_id=2
port=3306
log_bin = mysql-bin
sync_binlog = 1
binlog_ignore_db = information_schema
binlog_ignore_db = performation_schema
binlog_ignore_db = sys
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[mysql]
port = 3306
default-character-set = utf8
[client]
port = 3306
default-character-set = utf8
#启动服务
[root@centos8-2 server]# /etc/init.d/mysqld start
Starting MySQL.Logging to /data/mysql/data/centos8-2.err.
[ OK ]
#登录数据库
[root@centos8-2 server]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 3
Server version: 5.7.36-log MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type help; or \\h for help. Type \\c to clear the current input statement.

mysql>

编译安装MYSQL5.7

#安装相关依赖包
yum install -y gcc gcc-c++ cmake ncurses ncurses-devel bison wget openssl-devel.x86_64
#创建用户和组
groupadd mysql
useradd mysql -s /sbin/nologin -M -g mysql
#下载下载的包导入centos
[root@centos8-2 local]# cd /usr/local/mysql/
[root@centos8-2 mysql]# ls
mysql-5.7.36.tar.gz
[root@centos8-2 mysql]# tar xf mysql-boost-5.7.29.tar.gz
#配置相关参数
[root@centos8-2 mysql]# cd mysql-5.7.36
[root@centos8-2 mysql]# cmake -DCMAKE_INSTALL_PREFIX=/application/mysql -DMYSQL_DATADIR=/application/mysql/data -DMYSQL_UNIX_ADDR=/application/mysql/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
#报错没有安装boostC++库
#解决方法方法
#在cmake命令参数最后增加-DDOWNLOAD_BOOST=1
#重新运行cmake命令报错
#报错Could not find rpcgen
#解决方案,访问github搜索rpcsvc
#选择thkukuk-rpcsvc下载源码
#导入centos
[root@centos8-2 ~]# tar -xvf rpcsvc-proto-1.4.1.tar
[root@centos8-2 ~]# cd rpcsvc-proto-1.4.1
[root@centos8-2 ~]# ./configure
[root@centos8-2 ~]# make
[root@centos8-2 ~]# make install
#安装完成后运行
[root@centos8-2 ~]# cmake -DCMAKE_INSTALL_PREFIX=/application/mysql -DMYSQL_DATADIR=/application/mysql/data -DMYSQL_UNIX_ADDR=/application/mysql/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boost
#编译安装(-j指定多核运行编译)
#虚拟机设置中调高CPU加快速度
[root@ctos3 mysql-5.7.29]# make -j 8 && make install
#安装到82%报错,类似于fatal error:Killed signal terminated program cc1plus
#原因为内存不足
#解决方法:调大虚拟机内存,发现只能调到3G,实际16G内存,此时需要关闭虚拟机
#在进行设置,设置为8G后,问题解决
#设置完成后再次运行
[root@ctos3 mysql-5.7.29]# make -j 8 && make install
#创建数据目录和修改权限
mkdir /application/mysql/data #存放数据目录
mkdir /application/mysql/tmp #存放sock目录
chown -R mysql.mysql /application/mysql/
#配置/etc/my.cnf文件
cat /etc/my.cnf
[mysqld]
port = 3306
socket = /application/mysql/tmp/mysql.sock
user = mysql
basedir = /application/mysql
datadir = /application/mysql/data
pid-file = /application/mysql/data/mysql.pid
sql_mode=ONLY_FULL_GROUP_BY
log_error = /application/mysql/mysql-error.log
!includedir /etc/my.cnf.d

[client]
port = 3306
socket = /application/mysql/tmp/mysql.sock
#初始化数据库
/application/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/application/mysql/dat
#报错[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defau
#在my.cnf文件的[mysqld]中增加explicit_defaults_for_timestamp=true
#设置环境变量
[root@centos8-2 support-files]# echo export PATH=/application/mysql/bin:$PATH >> /etc/profile
[root@centos8-2 support-files]# source /etc/profile
[root@centos8-2 support-files]# tail -1 /etc/profile
export PATH=/application/mysql/bin:$PATH
#生成启动脚本
[root@centos8-2 ~]# cd /application/mysql/support-files/
[root@centos8-2 support-files]# ls
magic mysqld_multi.server mysql-log-rotate mysql.server
[root@centos8-2 support-files]# cp mysql.server /etc/init.d/mysqld
#登录数据库
[root@centos8-2 support-files]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \\g.
Your MySQL connection id is 3
Server version: 5.7.36 Source distribution

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type help; or \\h for help. Type \\c to clear the current input statement.

mysql>

3、二进制安装mariadb10.4

cd /usr/local
tar xf mariadb-10.5.8-linux-systemd-x86_64.tar.gz
ln -s mariadb-10.5.8-linux-systemd-x86_64 mysql
cd mysql/
useradd -r -s/sbin/nologin mysql
chown -R mysql.mysql /usr/local/mysql/
echo PATH=/usr/local/mysql/bin/:$PATH >/etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh
./scripts/mysql_install_db --datadir=/data/mysql
#报错./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
yum install -y libaio
chown -R mysql.mysql /data/mysql
cp support-files/systemd/mariadb.service /usr/lib/systemd/system/
vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
mkdir /etc/my.cnf.d
vim /etc/my.cnf.d/mysql-clients.cnf
[mysql]
socket=/data/mysql/mysql.sock
systemctl start mariadb
ln -s /data/mysql/mysql.sock /tmp/
mysql_secure_installation
rm -f /tmp/mysql.sock


以上是关于Linux第十周(二进制安装MYSQL5.7,编译安装MYSQL5.7,二进制安装mariadb10.4)的主要内容,如果未能解决你的问题,请参考以下文章

第十周

2017-2018-1 20179205《Linux内核原理与设计》第十周作业

mysql5.7 基于二进制编译多实例安装

ansible-playbook实现MySQL的二进制部署

linux学习第十周总结

第十周网络安全作业