centos7-install-mysql8-from-source

2019-05-10

mysql8编译安装需要GCC 5.3 or later (Linux) ,CentOS7默认的GCC版本是4.8.5,不支持C++14,对C++11支持也不完善,编译时需要加上-std=c++11才能勉强支持C++11,所以需要先升级GCC。

0、 yum install centos-release-scl
yum search devtoolset
yum install devtoolset-8包含下面全部
Install 1 Package (+44 Dependent packages)
Upgrade ( 8 Dependent packages)
或者
yum -y install devtoolset-8-binutils devtoolset-8-make.x86_64 devtoolset-8-gcc-c++.x86_64 devtoolset-8-gcc.x86_64 devtoolset-8-binutils.x86_64 devtoolset-8-binutils-devel.x86_64
source /opt/rh/devtoolset-8/enable

1、Mysql5.7版本更新后有很多变化,比如json等,连安装都有变化,他安装必须要boost库

mysql5.7之后,mysql版本直接跳到了8.0;mysql8官网源码有带boost库的源码和不带boost库的源码两种,
因此有两种安装方式,其实都是一样的,仅仅是不带boost库源码的需要单独安装boost
Boost库是为C++语言标准库提供扩展的一些C++程序库的总称
-DDOWNLOAD_BOOST=1 \ 下载boost库并解压到指定路径
-DWITH_BOOST=${LNMP}/mysql-8.0.17/boost \

2、下载链接
https://dev.mysql.com/downloads/mysql/
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.17.tar.gz
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-8.0/mysql-8.0.17.tar.gz -P /opt/LNMP/untar
3、安装脚本

export LNMP=/opt/LNMP
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-8.0/mysql-8.0.17.tar.gz -P /opt/LNMP/untar
#yum -y install make git gcc gcc-c++ cmake3 bison bison-devel ncurses-devel perl perl-devel
#yum -y remove mariadb

cd $LNMP
if [ -z "$(grep ^mysql /etc/passwd)" ];then
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
fi

if [ ! -d /usr/local/mysql ];then
mkdir -p /usr/local/mysql
chown -R mysql.mysql /usr/local/mysql
fi
if [ ! -d /var/lib/mysql ];then
mkdir -p /var/lib/mysql
chown -R mysql.mysql /var/lib/mysql
fi

#tar zxf untar/mysql-boost-8.0.17.tar.gz
pushd mysql-8.0.17
#make clean
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/var/lib/mysql \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DWITH_BOOST=./boost \
-DFORCE_INSOURCE_BUILD=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_USER=mysql

#make -j 12;
#/etc/init.d/mysqld stop
#make install;
popd
5 make错误
/lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found

sudo strings /lib64/libstdc++.so.6 | grep CXXABI(红色部分换成提示错误的地址)
CXXABI_1.3.7

因为升级gcc8.3时,生成的动态库没有替换老版本gcc的动态库

rpm -qf /lib64/libstdc++.so.6
libstdc++-4.8.5-36.el7_6.2.x86_64

locate libstdc++.so.6
/usr/local/gcc8.3/lib64/libstdc++.so.6
/usr/local/gcc8.3/lib64/libstdc++.so.6.0.25

cp /usr/local/gcc8.3/lib64/libstdc++.so.6.0.25 /lib64
ln -s libstdc++.so.6.0.24 libstdc++.so.6
再次strings /lib64/libstdc++.so.6 | grep CXXABI
重新执行make编译

5、初始化Mysql

#!/bin/bash

cat >> /etc/security/limits.conf << EOF
mysql soft nproc 65536
mysql hard nproc 65536
mysql soft nofile 65536
mysql hard nofile 65536
EOF

cp /opt/LNMP/untar/conf/my.cnf /usr/local/mysql
#cp /opt/LNMP/mysql-8.0.16/support-files/my-small.cnf /usr/local/mysql/my.cnf

cd /usr/local/mysql
#./scripts/mysql_install_db --datadir=/var/lib/mysql --user=mysql
./bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql

如果不加--initialize-insecure,mysql会产生随机密码,例如:d_wpblR#o9Hd
./bin/mysql_ssl_rsa_setup  --user=mysql --basedir=/usr/local/mysql --datadir=/var/lib/mysql

cp /opt/LNMP/mysql-8.0.16/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig mysqld on
/etc/init.d/mysqld start

./bin/mysqladmin -u root password '123456'
#./bin/mysqld_safe &

netstat -ntlp |grep 3306

cat >>  ~/.bash_profile << EOF
export PATH=$PATH:/usr/local/mysql/bin
EOF
source ~/.bash_profile

cat >> /etc/ld.so.conf.d/mysql.conf << EOF
/usr/local/mysql/lib
EOF

cat >> ~/my.sh << EOF
mysql -uroot -p123456 -Dmysql
EOF
chmod 755 ~/my.sh

mysql -uroot -p123456 -e"drop user ''@'localhost'"
mysql -uroot -p123456 -e"drop user ''@'`hostname`'"
mysql -uroot -p123456 -e"drop user 'root'@'`hostname`'"
mysql -uroot -p123456 -e"drop user root@'::1'"

mysql -uroot -p123456 -e"CREATE USER 'postfix'@'localhost' IDENTIFIED BY '123456';"
mysql -uroot -p123456 -e"GRANT ALL ON postfix.* TO 'postfix'@'localhost';"
mysql -uroot -p123456 -e"CREATE USER 'discuz'@'localhost' IDENTIFIED BY '123456';"
mysql -uroot -p123456 -e"GRANT ALL ON looyubbs.* TO 'discuz'@'localhost';"
mysql -uroot -p123456 -e"GRANT ALL ON discuzx.* TO 'discuz'@'localhost';"

mysql -uroot -p123456 -e"commit"
mysql -uroot -p123456 -e"flush privileges;"

chown -R root:root *

分类:Linux | 标签: |

相关日志

评论被关闭!