centos7.4 源码安装 mysql-8.0.17

说明

centos 7.4
mysql-8.0.17

准备工作

1, 下载mysql源码包

https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.17.tar.gz

2, 创建mysql用户

useradd -s /bin/false mysql

3, 安装依赖

yum -y install  gcc gcc-c++ ncurses  ncurses-devel  libaio-devel  openssl openssl-devel

源码安装cmake3(本机yum源没有3版本)

  • 3.1, 下载至cmake3
    https://github.com/Kitware/CMake/releases/download/v3.15.2/cmake-3.15.2.tar.gz
  • 3.2, 解压进入,执行
./bootstrap --prefix=/usr/local/cmake 
gmake 
gmake install
ln -s /usr/local/cmake/bin/cmake /usr/bin/cmake

4, 解压mysql并进入执行,首次尝试安装

cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DWITH_BOOST=boost -DFORCE_INSOURCE_BUILD=1

这里的数据目录 /data/mysql 需要填你自己的目录

  • 4.1 报错 : GCC 5.3 or newer is required (-dumpversion says 4.8.5)

下载gcc源码包
http://ftp.gnu.org/gnu/gcc/gcc-9.2.0/gcc-9.2.0.tar.gz

  • 解压进入,执行
./configure 
  • 4.1.1 报错:configure: error: Building GCC requires GMP 4.2+, MPFR 2.4.0+ and MPC 0.8.0+.

下载 gmp、mpfr、mpc源码包
ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.2.tar.gz
ftp://ftp.gnu.org/gnu/gmp/gmp-5.0.1.tar.bz2
http://ftp.gnu.org/gnu/mpfr/mpfr-3.1.2.tar.gz

  • 安装 gmp
tar -jxvf gmp-5.0.1.tar.bz2
cd gmp-5.0.1
./configure --prefix=/usr/local/gmp-5.0.1
make
make install
  • 安装mpfr
tar -zxvf mpfr-3.1.2.tar.gz 
cd mpfr-3.1.2
./configure --prefix=/usr/local/mpfr-3.1.2 --with-gmp=/usr/local/gmp-5.0.1
make
make install
  • 安装mpc
tar -zxvf mpc-1.0.2.tar.gz
cd mpc-1.0.2
./configure --prefix=/usr/local/mpc-1.0.2 --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.2
make
make install

安装三个依赖库完毕之后记住一定要把库路径添加到 /etc/ld.so.conf文件中

vim /etc/ld.so.conf

/usr/local/gmp-5.0.1/lib
/usr/local/mpfr-3.1.2/lib
/usr/local/mpc-1.0.2/lib

添加路径完之后一定要执行
ldconfig

  • 再次安装gcc,先删除上次执行结果,这里需要很久。。。
rm -f CMakeCache.txt
./configure --prefix=/usr/local/gcc-9.2.0 --enable-threads=posix --disable-checking --enable--long-long --with-gmp=/usr/local/gmp-5.0.1 --with-mpfr=/usr/local/mpfr-3.1.2 --with-mpc=/usr/local/mpc-1.0.2 --disable-multilib
make
make install
  • gcc path设置,原机有一个低版本的gcc,将原gcc改名
mv /usr/bin/gcc /usr/bin/gcc4.8.5
mv /usr/bin/g++ /usr/bin/g++4.8.5

设置新版本gcc

ln -s /usr/local/gcc-9.2.0/bin/gcc /usr/bin/gcc
ln -s /usr/local/gcc-9.2.0/bin/g++ /usr/bin/g++

5, 第二次尝试安装mysql

 cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc -DWITH_BOOST=boost -DFORCE_INSOURCE_BUILD=1 -DCMAKE_CXX_COMPILER=/usr/bin/g++
 make
  • 5.1 ,make报错:/lib64/libstdc++.so.6: version `CXXABI_1.3.9’ not found

    此处参考链接:https://blog.csdn.net/ZX714311728/article/details/69628836

6, 解决上面问题,再次执行make(第三次尝试安装mysql)
make -j 10

  • 6.1 报错:
    在函数‘void buf_pool_create(buf_pool_t*, ulint, ulint, std::mutex*, dberr_t&)’中: /root/mysql-8.0.17/storage/innobase/buf/buf0buf.cc:1220:44: 错误:‘SYS_gettid’在此作用域中尚未声明 setpriority(PRIO_PROCESS, (pid_t)syscall(SYS_gettid), -20);

解决办法:在文件buf0buf.cc的开头添加: #include “sys/syscall.h”

7,第四次尝试安装mysql

  • 7.1 报错:

    [ 97%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/log/log0write.cc.o
    /data/packages/mysql-8.0.17/storage/innobase/lock/lock0lock.cc: 在函数‘void lock_mark_trx_for_rollback(hit_list_t&, trx_id_t, trx_t*)’中:
    /data/packages/mysql-8.0.17/storage/innobase/lock/lock0lock.cc:1596:9: 错误:‘os_compare_and_swap_thread_id’ was not declared in this scope; did you mean ‘os_compare_and_swap_uint64’?
    1596 | cas = os_compare_and_swap_thread_id(&trx->killed_by, 0, thread_id);
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    | os_compare_and_swap_uint64
    make[2]: *** [storage/innobase/CMakeFiles/innobase.dir/lock/lock0lock.cc.o] 错误 1
    make[2]: *** 正在等待未完成的任务…
    make[1]: *** [storage/innobase/CMakeFiles/innobase.dir/all] 错误 2
    make: *** [all] 错误 2

解决办法:将lock0lock.cc.o 中 “os_compare_and_swap_thread_id” 修改为 os_compare_and_swap_lint

8, 第五次尝试安装mysql

  • 8.1 报错

    [ 96%] Building CXX object storage/innobase/CMakeFiles/innobase.dir/ut/ut0rnd.cc.o
    /data/packages/mysql-8.0.17/storage/innobase/trx/trx0trx.cc: 在函数‘void trx_init(trx_t*)’中:
    /data/packages/mysql-8.0.17/storage/innobase/trx/trx0trx.cc:220:5: 错误:‘os_compare_and_swap_thread_id’ was not declared in this scope; did you mean ‘os_compare_and_swap_lint’?
    220 | os_compare_and_swap_thread_id(&trx->killed_by, thread_id, 0);
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    | os_compare_and_swap_lint
    /data/packages/mysql-8.0.17/storage/innobase/trx/trx0trx.cc: 在函数‘void trx_kill_blocking(trx_t*)’中:
    /data/packages/mysql-8.0.17/storage/innobase/trx/trx0trx.cc:3223:5: 错误:‘os_compare_and_swap_thread_id’ was not declared in this scope; did you mean ‘os_compare_and_swap_lint’?
    3223 | os_compare_and_swap_thread_id(&victim_trx->killed_by, thread_id, 0);
    | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    | os_compare_and_swap_lint

解决办法: 将trx0trx.cc 中 “os_compare_and_swap_thread_id” 修改为 os_compare_and_swap_lint
注意: 这里有两处需要替换

9, 第六次尝试安装mysql

make
make install

通过了!!!

10 ,下面做些常规配置

配置 mysql

vim /etc/my.conf

[mysqld]
basedir=/usr/local/mysql
datadir=/data/mysql

[client]
socket=/var/lib/mysql/mysql.sock

保存退出

chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /data/mysql
chmod -R 755 /usr/local/mysql
chmod -R 755 /data/mysql

配置启动脚本

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on

11, 启动mysql

service mysqld start

  • 11.1 我这里报错了,根据报错信息,了解是权限问题,需要手动创建一些目录文件
mkdir /var/log/mariadb
touch mariadb.log
chown mysql:mysql /var/log/mariadb/ -R
chmod 755 /var/log/mariadb/ -R

service mysqld start    # success!!!

12, 登录mysql

设置mysql 快捷方式

ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql

开始登录

mysql -uroot -p

这里很懵逼,因为安装过程中没有要求我输入密码的地方,这里却让我输入密码。。。
此处解决办法:https://blog.csdn.net/rdisme/article/details/54599569

参考链接

https://blog.csdn.net/lwbeyond/article/details/77718040
https://blog.csdn.net/ZX714311728/article/details/69628836
https://www.nmirage.com/database/492.html
https://www.cnblogs.com/jjg0519/p/9034713.html
https://www.cnblogs.com/NanZhiHan/p/11017158.html

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