美文网首页程序员MySQL(总)
MySQL5.7二进制安装脚本

MySQL5.7二进制安装脚本

作者: 飞翔的Tallgeese | 来源:发表于2018-06-04 19:05 被阅读3次

    ###################################################

    脚本使用说明

    1.该脚本的数据存储路径为/data,请确认你的/data盘为单独挂载,或者有足够的空间

    2.脚本默认开启GTID

    3.脚本下载的MySQL来源为官网,版本为linux下的64位5.7.22,链接地址为:MySQL5.7.22版本确认

    4.脚本关闭了Selinux,但并没关闭防火墙,所以确认wget能成功执行下载

    5.脚本会使用yum下载部分工具,确认yum源配置正确

    ###################################################

    #!/bin/bash

    #      FlyDido

    #      2018.6.4

    #      部署MySQL5.7,请提前为数据存储路径"/data"划分好空间

    #关闭SeLinux

    sed -i 's/enforcing/disabled/g' /etc/sysconfig/selinux

    setenforce=0

    #用户及路径创建

    groupadd mysql

    useradd -g mysql -s /sbin/nologin -d /usr/local/mysql -MN mysql

    mkdir /data/mysql/mysql3306/{data,tmp,logs} -p

    mkdir /opt/mysql -p

    #部署前置环境

    yum install -y numactl vim wget &> /tmp/install.log &&

    M=mysql-5.7.22-linux-glibc2.12-x86_64

    #开始下载MySQL,如果下载失败,请检查官网版本是否为脚本中版本

    echo -e "开始下载5.7.22\n如果下载失败,请登陆:https://dev.mysql.com/downloads/mysql/5.7.html#downloads\n检查当前可下载版本是否为5.7.22\n然后把脚本中第29行的M值设置成可下载版本\n"

    echo -e  "3\n"

    sleep 1

    echo -e  "2\n"

    sleep 1

    echo -e  "1\n"

    sleep 1

    echo -e  "Ready,Go!\n"

    sleep 1

    cd /opt/mysql

    wget https://dev.mysql.com/get/Downloads/MySQL-5.7/$M.tar.gz

    #下载情况判定

    if [ $? == 0 ];then

        echo -e "下载完成\n正在解压\n..."

    else

        echo -e "下载失败,请检查版本\n"

        exit 1

    fi

    tar -xf $M.tar.gz

    echo -e "解压完成\n"

    #制作软链接

    ln -s /opt/mysql/$M /usr/local/mysql

    #更改权限

    chown -R mysql.mysql /data

    chown -R mysql.mysql /opt/mysql

    chown -R mysql.mysql /usr/local/mysql

    #定义server-id相关因子

    echo -e "开始定义server-id\n请确认当前IP是否使用eth0,如果不是请将脚本中IP变量定义中的eth0改成当前使用的网卡\n确认端口是否为3306,如果不是请将变量PORT定义的3306改成需要的端口"

    IP=`ip addr show|grep eth0|grep inet|awk '{print $2}'|awk -F '/' '{print $1}'|awk -F '.' '{print $4}'`

    PORT=3306

    echo -e "server-id生成完成,server-id为:$IP$PORT\n"

    #生成cnf

    echo -e "正在/data/mysql/mysql3306/下生成本次初始化使用的cnf\n"

    cat << EOF > /data/mysql/mysql3306/my3306.cnf

    [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/mysql3306/data

    port = 3306

    socket = /tmp/mysql3306.sock

    event_scheduler = 0

    tmpdir = /data/mysql/mysql3306/tmp

    #timeout

    interactive_timeout = 300

    wait_timeout = 300

    #character set

    character-set-server = utf8

    open_files_limit = 65535

    max_connections = 100

    max_connect_errors = 100000

    lower_case_table_names =1

    #

    explicit_defaults_for_timestamp=1

    #symi replication

    #rpl_semi_sync_master_enabled=1

    #rpl_semi_sync_master_timeout=1000 # 1 second

    #rpl_semi_sync_slave_enabled=1

    #logs

    log-output=file

    slow_query_log = 1

    slow_query_log_file = slow.log

    log-error = error.log

    pid-file = mysql.pid

    long_query_time = 1

    #log-slow-admin-statements = 1

    #log-queries-not-using-indexes = 1

    log-slow-slave-statements = 1

    #binlog

    #binlog_format = STATEMENT

    binlog_format = row

    server-id = $IP$PORT

    log-bin = /data/mysql/mysql3306/logs/mysql-bin

    binlog_cache_size = 1M

    max_binlog_size = 256M

    sync_binlog = 0

    expire_logs_days = 10

    #procedure

    log_bin_trust_function_creators=1

    #GTID

    gtid-mode = on

    enforce-gtid-consistency=on

    log-slave-updates=1

    #relay log

    skip_slave_start = 1

    max_relay_log_size = 128M

    relay_log_purge = 1

    relay_log_recovery = 1

    relay-log=relay-bin

    relay-log-index=relay-bin.index

    #slave-skip-errors=1032,1053,1062

    #skip-grant-tables

    #buffers & cache

    table_open_cache = 2048

    table_definition_cache = 2048

    table_open_cache = 2048

    max_heap_table_size = 96M

    sort_buffer_size = 128K

    join_buffer_size = 128K

    thread_cache_size = 200

    query_cache_size = 0

    query_cache_type = 0

    query_cache_limit = 256K

    query_cache_min_res_unit = 512

    thread_stack = 192K

    tmp_table_size = 96M

    key_buffer_size = 8M

    read_buffer_size = 2M

    read_rnd_buffer_size = 16M

    bulk_insert_buffer_size = 32M

    #myisam

    myisam_sort_buffer_size = 128M

    myisam_max_sort_file_size = 10G

    myisam_repair_threads = 1

    #innodb

    innodb_buffer_pool_size = 100M

    innodb_buffer_pool_instances = 1

    innodb_data_file_path = ibdata1:100M:autoextend

    innodb_flush_log_at_trx_commit = 2

    innodb_log_buffer_size = 8M

    innodb_log_file_size = 1G

    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

    loose_tokudb_cache_size=100M

    loose_tokudb_directio=ON

    loose_tokudb_fsync_log_period=1000

    loose_tokudb_commit_sync=0

    EOF

    #创建一个配置在/etc下

    rm -rf /etc/my.cnf

    cp -f /data/mysql/mysql3306/my3306.cnf /etc/my.cnf

    echo -e "开始执行初始化\n"

    #初始化

    /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf --initialize &> /tmp/install.log

    if [ $? == 0 ];then

        echo -e "初始化成功\n"

    else

        echo -e "初始化失败\n"

        exit 1

    fi

    #更新环境变量

    echo -e "export PATH=\$PATH:/usr/local/mysql/bin" >> /etc/profile

    echo -e "开始启动MySQL服务\n"

    #启动MySQL服务

    /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf &

    if [ $? == 0 ];then

        echo -e "MySQL启动成功\n"

    else

        echo -e "启动失败,请检查日志/data/mysql/mysql3306/data/error.log\n"

        exit 1

    fi

    PD=`cat /data/mysql/mysql3306/data/error.log |grep 'temporary password'|awk '{print $NF}'`

    #后续需要的操作

    echo -e "仔细阅读接下来你需要做的操作\n"

    echo -e "1.环境变量设置完毕,请手动执行:source /etc/profile\n"

    echo -e "2.初始密码为$PD\n在完成第1步的基础上执行mysql -uroot -p$PD进行登陆\n登陆后执行:alter user user() identified by '密码';\n注意密码需要打上引号,初次登陆必须更改密码\n"

    echo -e "3.日志路径:/data/mysql/mysql3306/logs\n数据存储路径:/data/mysql/mysql3306/data\nMySQL部署路径:/usr/local/mysql\n"

    echo -e "4.初始log_file_size设置为1G\n日志组设置为3\n初始buffer_pool_size设置为100M\n请尽快按需修改cnf配置\n"

    echo -e "5.numa并没有关闭,请参照度娘/谷哥对numa进行设置\n                                                                                        Done!"

    相关文章

      网友评论

        本文标题:MySQL5.7二进制安装脚本

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