• MySQL从源码编译安装


    作者:Grey

    原文地址:

    MySQL从源码编译安装

    基于版本

    CentOS-7-x86_64-Minimal-2009

    mysql-boost-8.0.25.tar.gz

    注:wget下载如果不稳定,可以手动下载好mysql-boost-8.0.25.tar.gz

    下载地址见:https://dev.mysql.com/downloads/mysql/

    新建用户和用户组

    groupadd mysql
    useradd -r -g mysql -s /bin/false mysql
    

    准备必要文件夹并赋予相应的权限

    # 准备必要文件夹
    mkdir -p /usr/local/mysql /data/mysql/
    
    # 赋予相应的权限
    chown -R mysql.mysql /usr/local/mysql/
    chown -R mysql.mysql /data/mysql/
    chmod -R 755 /data/mysql/
    chmod -R 755 /usr/local/mysql/
    

    安装必要依赖

    yum -y install wget gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel git bison
    yum install -y centos-release-scl-rh 
    yum install -y centos-release-scl
    yum install -y devtoolset-10-gcc 
    yum install -y devtoolset-10-gcc-c++
    

    执行

    source /opt/rh/devtoolset-10/enable
    

    通过wget下载cmake3,如果不稳定,可以手动下载cmake-3.20.2-Linux-x86_64.tar.gz并上传到/usr/local/src目录下

    # 卸载原有的cmake
    yum -y remove cmake
    
    cd /usr/local/src
    # 下载,如果不稳定,可以手动下载好并上传到/usr/local/src目录
    wget https://github.com/Kitware/CMake/releases/download/v3.20.2/cmake-3.20.2-Linux-x86_64.tar.gz
    

    解压并安装cmake3

    tar -xf cmake-3.20.2-linux-x86_64.tar.gz
    mv cmake-3.20.2-linux-x86_64 /usr/local/cmake
    
    vi /etc/profile
    

    在文件末尾加上

    export CMAKE_PATH=/usr/local/cmake
    export PATH=$PATH:$CMAKE_PATH/bin
    

    然后执行

    source /etc/profile
    

    验证cmake

    [root@db01 src]# cmake -version
    cmake version 3.20.2
    
    CMake suite maintained and supported by Kitware (kitware.com/cmake).
    
    

    编译安装MySQL

    将mysql-boost-8.0.25.tar.gz放到/usr/local/src目录下

    cd /usr/local/src
    
    # 解压
    tar -xf mysql-boost-8.0.25.tar.gz
    
    cd mysql-8.0.25/
    

    执行cmake,注意boost的路径要修改正确

    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.25/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
    

    漫长等待后.......

    如果执行无误,最后会提示

    ...
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /usr/local/src/mysql-8.0.25
    

    执行make

    cd /usr/local/src/mysql-8.0.25/
    
    make
    

    漫长等待后.......

    执行make可能会报如下错误

    during RTL pass: vartrack
    /usr/local/src/mysql-8.0.25/sql/opt_range.cc: In function ‘TRP_RANGE* get_key_scans_params(PARAM*, SEL_TREE*, bool, bool, const Cost_estimate*)’:
    /usr/local/src/mysql-8.0.25/sql/opt_range.cc:5232:1: internal compiler error: Segmentation fault
     5232 | }
          | ^
    Please submit a full bug report,
    with preprocessed source if appropriate.
    See <http://bugzilla.redhat.com/bugzilla> for instructions.
    The bug is not reproducible, so it is likely a hardware or OS problem.
    make[2]: *** [sql/CMakeFiles/sql_main.dir/opt_range.cc.o] Error 1
    make[1]: *** [sql/CMakeFiles/sql_main.dir/all] Error 2
    make: *** [all] Error 2
    
    

    可以先忽略,重新执行

    make
    

    然后make install

    make install
    

    初始化

    /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
    

    修改mysql配置(可选)

    cd /etc
    cp my.cnf my.cnf.backup
    
    vi /etc/my.cnf
    

    修改成以下内容:

    [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=mysql
    log_bin=mysql-bin
    binlog_format=mixed
    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
    
    

    配置环境变量和启动脚本

    环境变量

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

    启动脚本

    cp /usr/local/src/mysql-8.0.25/support-files/mysql.server /etc/init.d/mysqld
    
    chmod +x /etc/init.d/mysqld
    

    启动

    service mysqld restart
    

    登录

    mysql -u root -p
    

    按回车,即可无密码登录

    如果想配置root的密码,可以在无密码登录后执行:

    # 创建一个用户,用户名/密码:young/0320
    create user 'young'@'%' identified by '0320';
    
    # 赋予权限
    grant all privileges on *.* to 'young'@'%';
    
    flush privileges;
    

    增加到开机启动

    chkconfig --level 345 mysqld on
    

    测试是否开机启动,执行reboot

    reboot
    

    重启完毕后

    ps -ef|grep mysqld
    

    显示mysql已经启动了

    root       1094      1  0 12:57 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
    mysql      1452   1094  9 12:57 ?        00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql-error.log --pid-file=/data/mysql/mysql.pid --socket=/tmp/mysql.sock --port=3306
    
    

    卸载

    如果要完全卸载Linux,可以通过如下的方式:

    停止服务

    service mysqld stop
    

    然后执行

    find / -name mysql
    

    找到所有mysql相关的文件夹

    /run/lock/subsys/mysql
    /etc/selinux/targeted/active/modules/100/mysql
    /usr/lib64/mysql
    /usr/share/mysql
    /usr/local/src/mysql-8.0.25/include/mysql
    /usr/local/src/mysql-8.0.25/plugin/group_replication/libmysqlgcs/include/mysql
    /usr/local/src/mysql-8.0.25/router/src/harness/include/mysql
    /usr/local/src/mysql-8.0.25/router/src/harness/include/CMakeFiles/harness_net_ts.dir/mysql
    /usr/local/src/mysql-8.0.25/router/include/mysql
    /usr/local/src/mysql-8.0.25/runtime_output_directory/mysql
    /usr/local/mysql
    /usr/local/mysql/include/mysql
    /usr/local/mysql/bin/mysql
    /data/mysql
    /data/mysql/mysql
    

    然后执行 rm -rf 删掉这些文件即可。

    当然你确保

    find / -name mysql
    

    出来的文件没有需要保留的文件,也可以执行

    rm -rf `find / -name mysql`
    

    批量删除

    参考文档

    Installing MySQL Using a Standard Source Distribution

    Centos7源码编译安装mysql8

    CentOS7.2 源码安装MySQL8.0

    linux设置mysql开机启动

  • 相关阅读:
    Windows 任务调度程序定时执行Python脚本
    sklearn 学习 第三篇:knn分类
    sklearn 学习 第二篇:特征预处理
    sklearn 学习 第一篇:分类
    DAX 第六篇:统计函数(描述性统计)
    DAX 第四篇:CALCULATE详解
    DAX 第三篇:过滤器函数
    DAX 第二篇:计算上下文
    DAX 第一篇:数据模型
    Git 第二篇:基本操作
  • 原文地址:https://www.cnblogs.com/greyzeng/p/14789224.html
Copyright © 2020-2023  润新知