美文网首页
编译安装MySQL-8.0.26

编译安装MySQL-8.0.26

作者: 古飞_数据 | 来源:发表于2021-08-18 06:38 被阅读0次
    #!/bin/bash
    #cmake >3.5.1   #默认2.8.12.2-2.el7  CMake 3.5.1
    #GCC 7.1 or Clang 5     #默认4.8.5-44.el7,MySQL 8.0 source code permits use of C++17 features
    #bison 2.1 or higher
    #SSL
    #boot c++
    #source code -> 
    #Generic Linux (Architecture Independent)
    #vi include/mysql_version.h.in 
    #1.清理环境&安装依赖
    yum install centos-release-scl -y
    yum -y remove `rpm -qa |grep mariadb`
    yum install libtirpc-devel -y
    yum install -y libaio-devel libaio necurses-devel necurses readline-devel.x86_64 readline.x86_64 openssl openssl-devel doxygen
    
    yum install -y devtoolset-10-gcc.x86_vi64 devtoolset-10-gcc-c++.x86_64 devtoolset-10-gdb.x86_64
    source /opt/rh/devtoolset-10/enable
    #gcc -v
    yum install -y cmake3   #3.17.5-1.el7   epel
    
    
    
    #2.下载和解压
    cd /usr/local/src/
    if [ ! -f "(mysql-boost-8.0.26.tar.gz" ];then
        wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.26.tar.gz
        tar xf mysql-boost-8.0.26.tar.gz
        elif [ ! -d "mysql-boost-8.0.26" ];then
            tar xf mysql-boost-8.0.26.tar.gz
        else
        echo "already exists"
    fi
    
    #3.编译&安装
    cd /usr/local/src/mysql-8.0.26
    cmake3 . \
    -DWITH_BOOST=/usr/local/src/mysql-8.0.26/boost/ \
    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-8.0.26 \
    -DMYSQL_DATADIR=/data/mysql/3306/data \
    -DWITHOUT_CSV_STORAGE_ENGINE=1 \
    -DWITHOUT_BLACKHOLD_STORAGE_ENGINE=1 \
    -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 \
    -DWITHOUT_ARCHIVE_STORAGE_ENGINE=1 \
    -DWITHOUT_MRG_MYISAM_STORAGE_ENGINE=1 \
    -DWITHOUT_NDBCLUSTER_STORAGE_ENGINE=1 \
    -DFORCE_INSOURCE_BUILD=1
    
    make -j 16
    make install
    #make test
    #4.添加用户名
    useradd -s /sbin/nologin -M mysql
    #5.创建软连接
    cd /usr/local/
    ln -s /usr/local/mysql-8.0.26/ mysql
    chown -R mysql:mysql mysql/
    #7.创建目录并授权
    mkdir /data/mysql/3306/{data,logs,tmp} -p
    cd /data/mysql/
    chown -R mysql:mysql 3306/
    #8.添加配置文件并授权
    cat >/data/mysql/3306/my3306.cnf <<EOF
    [client]
    port = 3306
    socket = /tmp/mysql3306.sock
    [mysql]
    prompt=(\\u@\\h) [\\d]>\\_
    #pager="less -i -n -s"
    #tee=/opt/mysql/query.log
    no-auto-rehash
    [mysqld]
    #misc
    user = mysql
    basedir = /usr/local/mysql
    datadir = /data/mysql/3306/data
    port = 3306
    socket = /tmp/mysql3306.sock
    mysqlx_port = 33060
    mysqlx_socket = /tmp/mysqlx3306.sock
    event_scheduler = 0
    tmpdir = /data/mysql/3306/tmp
    #timeout
    interactive_timeout = 300
    wait_timeout = 300
    
    #character set
    character-set-server = utf8mb4
    open_files_limit = 65535
    max_connections = 1000
    max_connect_errors = 100000
    #lower_case_table_names =1
    
    #logs
    log-output=file
    slow_query_log = 1
    slow_query_log_file = slow.log
    pid-file = mysql.pid
    long_query_time = 1
    #log-slaw-adnin-statements = 1
    #log-queries-not-using-indexes= 1
    #log-slow-slave-statements = 1     #8.0.26 以下
    log_slow_replica_statements = 1
    
    log-error = error.log
    log_error_verbosity=3
    
    #binlog
    #binlogformat = STATEMENT
    binlog_format = row
    server-id = 3306
    log-bin = /data/mysql/3306/logs/mysql-bin
    binlog_cache_size = 1M
    max_binlog_size = 256M
    max_binlog_cache_size = 4M
    sync_binlog = 0
    #expire_logs_days = 10  #5.7版本
    binlog_expire_logs_seconds = 864000 #8.0 新参数
    log_bin_trust_function_creators = 1
    
    gtid-mode = on
    enforce_gtid_consistency = on
    
    #myisam
    myisam_sort_buffer_size = 128M
    myisam_max_sort_file_size = 10G
    myisam_repair_threads = 1
    
    #innodb
    innodb_buffer_pool_size = 300M
    innodb_buffer_pool_instances = 1
    innodb_data_file_path = ibdata1:100M:autoextend
    innodb_flush_log_at_trx_commit = 2
    innodb_log_buffer_size = 16M
    innodb_log_file_size = 512M
    innodb_log_files_in_group = 3
    innodb_max_dirty_pages_pct = 50
    innodb_file_per_table = 1
    innodb_rollback_on_timeout
    innodb_status_file = 1
    innodb_io_capacity = 2000
    transaction_isolation = READ-COMMITTED
    innodb_flush_method = O_DIRECT
    innodb_thread_concurrency = 0
    innodb_read_io_threads = 4
    innodb_write_io_threads = 4
    innodb_print_all_deadlocks = on
    innodb_deadlock_detect = on
    innodb_lock_wait_timeout = 30
    
    
    ##for performance_schema
    performance_schema                                         = on
    performance_schema_consumer_global_instrumentation         = on  # on
    performance_schema_consumer_thread_instrumentation         = on  # on
    performance_schema_consumer_events_stages_current          = on  # off
    performance_schema_consumer_events_stages_history          = on  # off
    performance_schema_consumer_events_stages_history_long     =off   # off
    performance_schema_consumer_statements_digest              = on # on
    performance_schema_consumer_events_statements_current      = on # on
    performance_schema_consumer_events_statements_history      = on # on
    performance_schema_consumer_events_statements_history_long = off # off
    performance_schema_consumer_events_waits_current           = on # off
    performance_schema_consumer_events_waits_history           = on # off
    performance_schema_consumer_events_waits_history_long      = off # off
    performance-schema-instrument                              ='memory/%=COUNTED'
    EOF
    
    chown mysql:mysql /data/mysql/3306/my3306.cnf
    
    
    #6. 初始化MySQL
    /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/3306/my3306.cnf --initialize-insecure
    #cat /data/mysql/3306/data/error.log
    
    #8. 启动数据库
    /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/3306/my3306.cnf &
    #cat /data/mysql/3306/data/error.log
    
    #9. 添加环境变量
    cat >> /etc/profile << EOF
    export PATH=/usr/local/mysql/bin:\$PATH
    EOF
    
    source /etc/profile
    bash
    
    #10.修改数据库密码
    #mysql -S /tmp/mysql3306.sock -p
    #alter user user() identified by '123';
    #11.关机
    #mysqladmin -S /tmp/mysql3306.sock -p shutdown
    

    相关文章

      网友评论

          本文标题:编译安装MySQL-8.0.26

          本文链接:https://www.haomeiwen.com/subject/bdybbltx.html