Mysql8源码安装


环境

  • 操作系统 centos
  • mysql8.3
  • cmake版本大于3.5
  • gcc版本大于7.1

准备工作

  • 更新系统

    yum update
    
  • 升级cmake

    • 安装OpenSSL或者 -DCMAKE_USE_OPENSSL=OFF
      yum install openssl openssl-devel -y
      

    升级文档

    export CMAKE_ROOT=/usr/local/bin/cmake
    
  • 升级gcc

    # 下载gcc
    wget http://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.gz
    
    yum -y install gmp-devel
    yum -y install mpfr-devel
    yum -y install libmpc-devel
    
    tar -zxvf gcc-11.2.0.tar.gz
    cd gcc-11.2.0
    
    # 下载四个依赖包
    ./contrib/download_prerequisites
    
    # 编译
    mkdir build
    cd build/
    
    ../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
    make -j16
    make install
    
    # 卸载旧版本
    yum -y remove gcc g++
    
    # 配置新版本全局可用
    ln -s /usr/local/bin/gcc /usr/bin/gcc
    ln -s /usr/local/bin/g++ /usr/bin/g++
    ln -s /usr/local/bin/c++ /usr/bin/c++
    #  更新动态库
    # 查看当前的动态库
    strings /usr/lib64/libstdc++.so.6 | grep CXXABI
    # 更新
    rm -f /usr/lib64/libstdc++.so.6
    ln -s /usr/local/lib64/libstdc++.so.6.0.29 /usr/lib64/libstdc++.so.6
    # 查看更新后的动态库
    strings /usr/lib64/libstdc++.so.6 | grep CXXABI
    
    

开始安装

yum install -y ncurses-devel
tar zxvf mysql-boost-8.0.36.tar.gz

cd mysql-8.0.36/
cd build/

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DSYSCONFDIR=/etc \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
make && make install
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql /usr/local/mysql
cd /usr/local/mysql
 mysqld --initialize --user=mysql
cp support-files/mysql.server /etc/init.d/mysql

chkconfig mysql on
service mysql start
ln -s /usr/local/mysql/bin/mysql /usr/bin/