MySQL之——CentOS 6.8编译安装MySQL8.x

操作系统说明:CentOS 6.8
数据库版本:MySQL 8.0.18

一.环境准备

yum install ncurses-devel -y
yum install libaio -y
yum install glibc-devel.i686 glibc-devel -y
yum install gcc gcc-c++ -y

另外,MySQL8.0需要用gcc的版本为 4.8以上,而CentOS 6.8通过yum只能安装到4.4.7,所以在安装mysql8.0之前需要手动安装更高版本的gcc,我这里以gcc-4.8.2为例:

wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.8.2/gcc-4.8.2.tar.gz
tar xf gcc-4.8.2.tar.gz
cd  gcc-4.8.2
# 载编译需要的依赖包:./contrib/download_prerequisites
./configure --prefix=/usr/local/gcc-4.8.2/  --enable-bootstrap --enable-threads=posix --enable-languages=c,c++,objc,obj-c++
make &&make install

说明:make的时间会很长。
安装完后,还需要将原来的gcc环境用新版本的gcc替换掉,否则mysql在安装时还是用的原来的gcc:

mv /usr/bin/gcc /usr/bin/gcc447
mv /usr/bin/g++ /usr/bin/g++447
mv /usr/bin/c++ /usr/bin/c++447
mv /usr/bin/cc /usr/bin/cc447
ln -s /usr/local/gcc-4.8.2/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc-4.8.2/bin/g++ /usr/bin/g++
ln -s /usr/local/gcc-4.8.2/bin/c++ /usr/bin/c++
ln -s /usr/local/gcc-4.8.2/bin/gcc /usr/bin/cc
mv /usr/lib64/libstdc++.so.6 /usr/lib64/libstdc++.so.6.bak
ln -s /usr/local/gcc-4.8.2/lib64/libstdc++.so.6.0.18 /usr/lib64/libstdc++.so.6

接下来,安装boost库:

wget -c http://sourceforge.net/projects/boost/files/boost/1.60.0/boost_1_60_0.tar.bz2  --no-check-certificate
tar xf boost_1_60_0.tar.bz2\?r\=\&ts\=1479114685\&use_mirror\=ncu
cd boost_1_60_0
./bootstrap.sh
./b2 stage threading=multi link=shared
./b2 install threading=multi link=shared

二.安装mysql8.0.18

1.下载与解压MySQL

wget -c  https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.18.tar.gz
tar xf mysql-boost-8.0.18.tar.gz

2.编译安装mysql

cd mysql-8.0.18
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql  \
-DMYSQL_DATADIR=/usr/local/mysql/data/ -DSYSCONFDIR=\etc\mysql \
-DWITH_INNOBASE_STORAGE_ENGINE=1  \
-DMYSQL_TCP_PORT=3306  \
-DENABLED_LOCAL_INFILE=1  \
-DEXTRA_CHARSETS=all  \
-DDEFAULT_CHARSET=utf8  \
-DDEFAULT_COLLATION=utf8_general_ci  \
-DWITH_BOOST=/tmp/boost_1_60_0/
make
make install

3.新增mysql用户和组,并配置mysql用户对数据库目录的权限

groupadd mysql
useradd -g mysql mysql
chown mysql.mysql /usr/local/mysql -R
# 初始化mysql
cd  /usr/local/mysql
bin/mysqld --initialize --user=mysql  --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
bin/mysql_ssl_rsa_setup

4.配置文件

cp ./support-files/my-default.cnf /etc/my.cnf
vim /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data/
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
pid-file=/var/run/mysqld/mysqld.pid
log-error=/var/log/mysqld.log

5.创建进程文件目录

mkdir /var/run/mysqld
chown mysql /var/run/mysqld/ -R

6.设置环境变量

echo "export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/sbin" >> /etc/profile
source  /etc/profile

7.设置开机启动脚本

cd  /usr/local/mysql
cp support-files/mysql.server /etc/init.d/mysql.server
chkconfig mysql.server on
service mysql.server start

 

你可能感兴趣的:(mysql,MySQL)