欢迎来到战五渣的博客

人生三重境界:昨夜西风凋碧树,独上高楼,望尽天涯路。 衣带渐宽终不悔,为伊消得人憔悴。 众里寻他千百度,蓦然回首,那人却在灯火阑珊处。

Centos7源码编译安装mysql8

前面介绍了很多关于mysql的文章,下面主要介绍一下mysql8的源码编译安装

一 基本环境

[root@CentOS-7-x86-64-Minimal-1810 ~]# cd /usr/local/src/

[root@CentOS-7-x86-64-Minimal-1810 src]# cat /etc/redhat-release

CentOS Linux release 7.6.1810 (Core)

[root@CentOS-7-x86-64-Minimal-1810 src]# uname -r

5.2.14-1.el7.elrepo.x86_64

二 准备

2.1 安装依赖包

[root@CentOS-7-x86-64-Minimal-1810 src]# yum -y install wget cmake gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel

2.2 下载包

[root@CentOS-7-x86-64-Minimal-1810 src]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.17.tar.gz

2.3 解压并创建用户和目录

[root@CentOS-7-x86-64-Minimal-1810 src]# tar -xf mysql-boost-8.0.17.tar.gz

[root@CentOS-7-x86-64-Minimal-1810 src]# cd mysql-8.0.17/

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# groupadd mysql

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# useradd -r -g mysql -s /sbin/nologin mysql

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# mkdir -p /usr/local/mysql

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# chown -R mysql.mysql /usr/local/mysql/

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# chown -R mysql.mysql /data/mysql/

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# chmod -R 755 /data/mysql/

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# chmod -R 755 /usr/local/mysql/

三 安装

3.1 编译安装

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

> -DMYSQL_DATADIR=/data/mysql \

> -DSYSCONFDIR=/etc \

> -DMYSQL_TCP_PORT=3306 \

> -DWITH_BOOST=~/mysql-8.0.12/boost \

> -DDEFAULT_CHARSET=utf8 \

> -DDEFAULT_COLLATION=utf8_general_ci \

> -DENABLED_LOCAL_INFILE=ON \

> -DWITH_INNODB_MEMCACHED=ON \

> -DWITH_INNOBASE_STORAGE_ENGINE=1 \

> -DWITH_FEDERATED_STORAGE_ENGINE=1 \

> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \

> -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \

> -DWITH_PERFSCHEMA_STORAGE_ENGINE=1

-- Running cmake version 2.8.12.2

3.2 安装cmake 3.5以上版本

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# yum -y remove cmake

下载二进制包

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# cd  /usr/local/src/

[root@CentOS-7-x86-64-Minimal-1810 src]# wget https://github.com/Kitware/CMake/releases/download/v3.15.3/cmake-3.15.3-Linux-x86_64.tar.gz

[root@CentOS-7-x86-64-Minimal-1810 src]# tar -xf cmake-3.15.3-Linux-x86_64.tar.g

[root@CentOS-7-x86-64-Minimal-1810 src]# cp -r cmake-3.15.3-Linux-x86_64  /usr/local/cmake

设置环境变量

[root@CentOS-7-x86-64-Minimal-1810 src]# vi /etc/profile

export CMAKE_PATH=/usr/local/cmake
export PATH=$PATH:$CMAKE_PATH/bin

[root@CentOS-7-x86-64-Minimal-1810 src]# source /etc/profile

[root@CentOS-7-x86-64-Minimal-1810 src]# cmake –version

 [root@CentOS-7-x86-64-Minimal-1810 src]# cd mysql-8.0.17/

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=~/mysql-8.0.12/boost -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNODB_MEMCACHED=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1

 [root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=~/mysql-8.0.12/boost -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNODB_MEMCACHED=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DFORCE_INSOURCE_BUILD=1

3.3 安装GCC高版本

下载源码包

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# cd /usr/local/src/

[root@CentOS-7-x86-64-Minimal-1810 src]# wget https://mirrors.ustc.edu.cn/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz

[root@CentOS-7-x86-64-Minimal-1810 src]# tar -xf gcc-9.2.0.tar.gz

[root@CentOS-7-x86-64-Minimal-1810 src]# cd gcc-9.2.0

[root@CentOS-7-x86-64-Minimal-1810 src]# ./contrib/download_prerequisites

2019-09-18 15:50:02 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840] -> "./gmp-6.1.0.tar.bz2" [1]
2019-09-18 15:50:12 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284] -> "./mpfr-3.1.4.tar.bz2" [2]
2019-09-18 15:50:22 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/mpc-1.0.3.tar.gz [669925] -> "./mpc-1.0.3.tar.gz" [2]
2019-09-18 15:50:32 URL: ftp://gcc.gnu.org/pub/gcc/infrastructure/isl-0.18.tar.bz2 [1658291] -> "./isl-0.18.tar.bz2" [2]
gmp-6.1.0.tar.bz2: OK
mpfr-3.1.4.tar.bz2: OK
mpc-1.0.3.tar.gz: OK
isl-0.18.tar.bz2: OK
All prerequisites downloaded successfully.

[root@CentOS-7-x86-64-Minimal-1810 gcc-9.2.0]# ./configure --prefix=/usr/local/gcc  --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib

[root@CentOS-7-x86-64-Minimal-1810 gcc-9.2.0]# time make -j4

花费时间比较久

[root@CentOS-7-x86-64-Minimal-1810 gcc-9.2.0]# make install

设置环境变量

[root@CentOS-7-x86-64-Minimal-1810 gcc-9.2.0]# echo  "export PATH=/usr/local/gcc/bin:$PATH" >> /etc/profile.d/gcc.sh

[root@CentOS-7-x86-64-Minimal-1810 gcc-9.2.0]# source /etc/profile.d/gcc.sh

[root@CentOS-7-x86-64-Minimal-1810 gcc-9.2.0]# ln -sv /usr/local/gcc/include/ /usr/include/gcc

[root@CentOS-7-x86-64-Minimal-1810 gcc-9.2.0]# ldconfig –v

[root@CentOS-7-x86-64-Minimal-1810 gcc-9.2.0]# ldconfig -p |grep gcc

[root@CentOS-7-x86-64-Minimal-1810 gcc-9.2.0]# gcc –v

[root@CentOS-7-x86-64-Minimal-1810 gcc-9.2.0]# cd /usr/local/src/mysql-8.0.17/

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=~/mysql-8.0.12/boost -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNODB_MEMCACHED=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DFORCE_INSOURCE_BUILD=1

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# yum –y remove gcc

报错

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# ln -s /usr/local/gcc/bin/c++   /usr/bin/

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# ln -s /usr/local/gcc/bin/gcc  /usr/bin/cc

3.4 再次编译安装

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 -DWITH_BOOST=/usr/local/src/mysql-8.0.17/boost -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DENABLED_LOCAL_INFILE=ON -DWITH_INNODB_MEMCACHED=ON -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DFORCE_INSOURCE_BUILD=1

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]#make

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]#make Install

3.5 初始化数据库

[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# cd /usr/local/mysql/bin/

[root@CentOS-7-x86-64-Minimal-1810 bin]# ./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql

[root@CentOS-7-x86-64-Minimal-1810 bin]# vi /etc/my.cnf

[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8
#user=root
#password=123
[mysqld]
server-id=1
#skip-grant-tables
port=3306
user=mysql
max_connections=200
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql
pid-file=/data/mysql/mysql.pid
init-connect='SET NAMES utf8'
character-set-server=utf8
default-storage-engine=INNODB
log_error=/data/mysql/mysql-error.log
slow_query_log_file=/data/mysql/mysql-slow.log
[mysqldump]
quick
max_allowed_packet=16M

[root@CentOS-7-x86-64-Minimal-1810 bin]# echo "PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile

[root@CentOS-7-x86-64-Minimal-1810 bin]# source /etc/profile

[root@CentOS-7-x86-64-Minimal-1810 bin]# cp /usr/local/src/mysql-8.0.17/support-files/mysql.server /etc/init.d/mysqld

[root@CentOS-7-x86-64-Minimal-1810 bin]# vim /etc/init.d/mysqld

basedir=/usr/local/mysql

datadir=/data/mysql

[root@CentOS-7-x86-64-Minimal-1810 bin]# chmod +x /etc/init.d/mysqld

[root@CentOS-7-x86-64-Minimal-1810 bin]# /etc/init.d/mysqld start

3.6 登陆

可以无密码登录

[root@CentOS-7-x86-64-Minimal-1810 bin]# mysql -u root -p

数据库初步安装完成,后续在做其他实验

posted @ 2019-11-20 20:45  梦中泪  阅读(7782)  评论(0编辑  收藏  举报