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 下载包
2.3 解压并创建⽤户和⽬录
[root@CentOS-7-x86-64-Minimal-1810 src]# tar -xf mysql-boost-8.0.
[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 -sql /usr/local/mysql/
[root@CentOS-7-x86-64-Minimal-1810 mysql-8.0.17]# chown -sql /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]# 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 -DDEFA
ULT_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]# tar -xf gcc-9.2.
[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-1815:50:02 URL: ftp:///pub/gcc/infrastructure/gmp-6.1.0.tar.bz2 [2383840] -> "./gmp-6.1.0.tar.bz2" [1]
2019-09-1815:50:12 URL: ftp:///pub/gcc/infrastructure/mpfr-3.1.4.tar.bz2 [1279284] -> "./mpfr-3.1.4.tar.bz2" [2]
2019-09-1815:50:22 URL: ftp:///pub/gcc/infrastructure/mpc-1.0. [669925] -> "./mpc-1.0." [2]
2019-09-1815:50:32 URL: ftp:///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.: 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/l
ocal/mysql --datadir=/data/mysql [root@CentOS-7-x86-64-Minimal-1810 bin]# vi /etc/myf
[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=mysqlcentos vim命令
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
数据库初步安装完成,后续在做其他实验

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。