• MySQL自动化安装脚本


     该脚本简单实现MySQL5.7.21的自动化安装,比较简单,但是基本能实现本公司MySQL的快速部署(滑稽脸)

    #!/bin/bash
    # author:颜海航
    # version:1.0
    # date:2019-04-25
    echo "#############################  MySQL  installing..........########################"
    
    echo "-----config my.cnf-----"
    mv /etc/my.cnf /etc/my.cnf_`date +%Y%m%d`
    SERVER_ID=`ifconfig eth0  |grep inet |awk '{print $2}'|awk -F. '{print $3$4}'`
    Mem=`free -m |grep Mem |awk '{print $2}'`
    SIZE=$[Mem*1/2]
    cat >>/etc/my$ipaddr.cnf<<EOF
    [mysql]
    default-character-set=utf8
    [client]
    port            = 3306
    socket          = /server/mysql_data/mysql.sock
    
    # Here follows entries for some specific programs
    # The MySQL server
    [mysqld]
    port            = 3306
    character-set-server = utf8
    socket          = /server/mysql_data/mysql.sock
    pid-file        = /server/mysql_data/mysql.pid
    basedir         = /usr/local/mysql
    datadir         = /server/mysql_data/
    log-error       =/server/mysql_data/error.log
    skip-name-resolve
    sql_mode        = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    
    server-id        = $SERVER_ID
    log-bin          = mysql-bin
    binlog_format    = row
    #binlog-ignore-db = mysql
    #binlog-ignore-db = information_schema
    #binlog-ignore-db = performance_schema
    #binlog-ignore-db = test
    sync-binlog       = 1
    #slave-skip-errors = all
    
    log-output               = FILE
    # slow query log
    slow_query_log           = 1
    long-query-time          = 1
    slow_query_log_file      =/server/mysql_data/slow.log
    #log-queries-not-using-indexes
    
    innodb_buffer_pool_size         = ${SIZE}M
    innodb_buffer_pool_instances    = 2
    innodb_data_home_dir            = /server/mysql_data/
    innodb_data_file_path           = ibdata1:512M:autoextend
    innodb_log_buffer_size          = 512M
    innodb_log_file_size            = 512M
    innodb_log_files_in_group       = 2
    innodb_log_group_home_dir       = /server/mysql_data/
    innodb_file_per_table           = 1
    innodb_temp_data_file_path      = ibtmp1:12M:autoextend:max:5G
    innodb_flush_log_at_trx_commit  = 1
    
    max_connections=4000
    back_log=200
    innodb_io_capacity=5000
    innodb_write_io_threads=8
    innodb_read_io_threads=8
    wait_timeout=1800
    interactive_timeout=1800
    expire_logs_days = 15
    
    #time
    log_timestamps = SYSTEM
    
    #gtid
    #gtid_mode=on
    #log_slave_updates=1
    #enforce_gtid_consistency=1
    
    #skip-external-locking
    table_open_cache = 512
    max_allowed_packet = 512M
    sort_buffer_size = 8M
    read_buffer_size = 8M
    read_rnd_buffer_size = 8M
    #myisam_sort_buffer_size = 64M
    thread_cache_size = 8
    # Try number of CPU's*2 for thread_concurrency
    #thread_concurrency = 8
    tmp_table_size           = 512M
    max_heap_table_size      = 512M
    
    [mysql]
    #auto-rehash
    #user=zabbix
    #password=zabbix
    #socket=/server/mysql_data/tmp/mysql.sock
    EOF
    
    
    echo "-----create group and user:mysql-----"
    groupadd mysql  
    useradd -r -g mysql -s /bin/false mysql 
    
    echo "----- install dependent package -----"
    yum -y install numactl  libaio lrzsz wget 
    
    echo "-----Download MySQL-----"
    if [ -d /soft ];then
    	echo "software dir is exist! Please check!"
    else 
    	mkdir -p /soft
    fi
    
    cd /soft
    wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
    
    echo  "-----Unzip MySQL-----"
    tar zxvf /soft/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
    mv /soft/mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql
    
    echo  "-----create datadir and change owner of dir-----"
    mkdir -p /server/mysql_data
    chown -R mysql.mysql /etc/my.cnf
    chown -R mysql.mysql /usr/local/mysql/
    chown -R mysql.mysql /server/mysql_data/
    
    echo  "-----config profile-----"
    echo 'PATH=/usr/local/mysql/bin/:$PATH' >> /etc/profile
    source /etc/profile
    
    echo  "-----initialize MySQL-----"
    /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/server/mysql_data/
    
    echo  "-----start  MySQL-----"
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    /etc/init.d/mysqld start
    
    #!/bin/bash
    # author:颜海航
    # version:1.0
    # date:2019-04-25
    echo "#############################  MySQL  installing..........########################"
    
    echo "-----config my.cnf-----"
    mv /etc/my.cnf /etc/my.cnf_`date +%Y%m%d`
    SERVER_ID=`ifconfig eth0  |grep inet |awk '{print $2}'|awk -F. '{print $3$4}'`
    Mem=`free -m |grep Mem |awk '{print $2}'`
    SIZE=$[Mem*1/2]
    cat >>/etc/my$ipaddr.cnf<<EOF
    [mysql]
    default-character-set=utf8
    [client]
    port            = 3306
    socket          = /server/mysql_data/mysql.sock
    
    # Here follows entries for some specific programs
    # The MySQL server
    [mysqld]
    port            = 3306
    character-set-server = utf8
    socket          = /server/mysql_data/mysql.sock
    pid-file        = /server/mysql_data/mysql.pid
    basedir         = /usr/local/mysql
    datadir         = /server/mysql_data/
    log-error       =/server/mysql_data/error.log
    skip-name-resolve
    sql_mode        = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    
    server-id        = $SERVER_ID
    log-bin          = mysql-bin
    binlog_format    = row
    #binlog-ignore-db = mysql
    #binlog-ignore-db = information_schema
    #binlog-ignore-db = performance_schema
    #binlog-ignore-db = test
    sync-binlog       = 1
    #slave-skip-errors = all
    
    log-output               = FILE
    # slow query log
    slow_query_log           = 1
    long-query-time          = 1
    slow_query_log_file      =/server/mysql_data/slow.log
    #log-queries-not-using-indexes
    
    innodb_buffer_pool_size         = ${SIZE}M
    innodb_buffer_pool_instances    = 2
    innodb_data_home_dir            = /server/mysql_data/
    innodb_data_file_path           = ibdata1:512M:autoextend
    innodb_log_buffer_size          = 512M
    innodb_log_file_size            = 512M
    innodb_log_files_in_group       = 2
    innodb_log_group_home_dir       = /server/mysql_data/
    innodb_file_per_table           = 1
    innodb_temp_data_file_path      = ibtmp1:12M:autoextend:max:5G
    innodb_flush_log_at_trx_commit  = 1
    
    max_connections=4000
    back_log=200
    innodb_io_capacity=5000
    innodb_write_io_threads=8
    innodb_read_io_threads=8
    wait_timeout=1800
    interactive_timeout=1800
    expire_logs_days = 15
    
    #time
    log_timestamps = SYSTEM
    
    #gtid
    #gtid_mode=on
    #log_slave_updates=1
    #enforce_gtid_consistency=1
    
    #skip-external-locking
    table_open_cache = 512
    max_allowed_packet = 512M
    sort_buffer_size = 8M
    read_buffer_size = 8M
    read_rnd_buffer_size = 8M
    #myisam_sort_buffer_size = 64M
    thread_cache_size = 8
    # Try number of CPU's*2 for thread_concurrency
    #thread_concurrency = 8
    tmp_table_size           = 512M
    max_heap_table_size      = 512M
    
    [mysql]
    #auto-rehash
    #user=zabbix
    #password=zabbix
    #socket=/server/mysql_data/tmp/mysql.sock
    EOF
    
    
    echo "-----create group and user:mysql-----"
    groupadd mysql  
    useradd -r -g mysql -s /bin/false mysql 
    
    echo "----- install dependent package -----"
    yum -y install numactl  libaio lrzsz wget 
    
    echo "-----Download MySQL-----"
    if [ -d /soft ];then
    	echo "software dir is exist! Please check!"
    else 
    	mkdir -p /soft
    fi
    
    cd /soft
    wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
    
    echo  "-----Unzip MySQL-----"
    tar zxvf /soft/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
    mv /soft/mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql
    
    echo  "-----create datadir and change owner of dir-----"
    mkdir -p /server/mysql_data
    chown -R mysql.mysql /etc/my.cnf
    chown -R mysql.mysql /usr/local/mysql/
    chown -R mysql.mysql /server/mysql_data/
    
    echo  "-----config profile-----"
    echo 'PATH=/usr/local/mysql/bin/:$PATH' >> /etc/profile
    source /etc/profile
    
    echo  "-----initialize MySQL-----"
    /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/server/mysql_data/
    
    echo  "-----start  MySQL-----"
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    /etc/init.d/mysqld start
    
    #!/bin/bash
    # author:颜海航
    # version:1.0
    # date:2019-04-25
    echo "#############################  MySQL  installing..........########################"
    
    echo "-----config my.cnf-----"
    mv /etc/my.cnf /etc/my.cnf_`date +%Y%m%d`
    SERVER_ID=`ifconfig eth0  |grep inet |awk '{print $2}'|awk -F. '{print $3$4}'`
    Mem=`free -m |grep Mem |awk '{print $2}'`
    SIZE=$[Mem*1/2]
    cat >>/etc/my$ipaddr.cnf<<EOF
    [mysql]
    default-character-set=utf8
    [client]
    port            = 3306
    socket          = /server/mysql_data/mysql.sock
    
    # Here follows entries for some specific programs
    # The MySQL server
    [mysqld]
    port            = 3306
    character-set-server = utf8
    socket          = /server/mysql_data/mysql.sock
    pid-file        = /server/mysql_data/mysql.pid
    basedir         = /usr/local/mysql
    datadir         = /server/mysql_data/
    log-error       =/server/mysql_data/error.log
    skip-name-resolve
    sql_mode        = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
    
    server-id        = $SERVER_ID
    log-bin          = mysql-bin
    binlog_format    = row
    #binlog-ignore-db = mysql
    #binlog-ignore-db = information_schema
    #binlog-ignore-db = performance_schema
    #binlog-ignore-db = test
    sync-binlog       = 1
    #slave-skip-errors = all
    
    log-output               = FILE
    # slow query log
    slow_query_log           = 1
    long-query-time          = 1
    slow_query_log_file      =/server/mysql_data/slow.log
    #log-queries-not-using-indexes
    
    innodb_buffer_pool_size         = ${SIZE}M
    innodb_buffer_pool_instances    = 2
    innodb_data_home_dir            = /server/mysql_data/
    innodb_data_file_path           = ibdata1:512M:autoextend
    innodb_log_buffer_size          = 512M
    innodb_log_file_size            = 512M
    innodb_log_files_in_group       = 2
    innodb_log_group_home_dir       = /server/mysql_data/
    innodb_file_per_table           = 1
    innodb_temp_data_file_path      = ibtmp1:12M:autoextend:max:5G
    innodb_flush_log_at_trx_commit  = 1
    
    max_connections=4000
    back_log=200
    innodb_io_capacity=5000
    innodb_write_io_threads=8
    innodb_read_io_threads=8
    wait_timeout=1800
    interactive_timeout=1800
    expire_logs_days = 15
    
    #time
    log_timestamps = SYSTEM
    
    #gtid
    #gtid_mode=on
    #log_slave_updates=1
    #enforce_gtid_consistency=1
    
    #skip-external-locking
    table_open_cache = 512
    max_allowed_packet = 512M
    sort_buffer_size = 8M
    read_buffer_size = 8M
    read_rnd_buffer_size = 8M
    #myisam_sort_buffer_size = 64M
    thread_cache_size = 8
    # Try number of CPU's*2 for thread_concurrency
    #thread_concurrency = 8
    tmp_table_size           = 512M
    max_heap_table_size      = 512M
    
    [mysql]
    #auto-rehash
    #user=zabbix
    #password=zabbix
    #socket=/server/mysql_data/tmp/mysql.sock
    EOF
    
    
    echo "-----create group and user:mysql-----"
    groupadd mysql  
    useradd -r -g mysql -s /bin/false mysql 
    
    echo "----- install dependent package -----"
    yum -y install numactl  libaio lrzsz wget 
    
    echo "-----Download MySQL-----"
    if [ -d /soft ];then
    	echo "software dir is exist! Please check!"
    else 
    	mkdir -p /soft
    fi
    
    cd /soft
    wget https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
    
    echo  "-----Unzip MySQL-----"
    tar zxvf /soft/mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz
    mv /soft/mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql
    
    echo  "-----create datadir and change owner of dir-----"
    mkdir -p /server/mysql_data
    chown -R mysql.mysql /etc/my.cnf
    chown -R mysql.mysql /usr/local/mysql/
    chown -R mysql.mysql /server/mysql_data/
    
    echo  "-----config profile-----"
    echo 'PATH=/usr/local/mysql/bin/:$PATH' >> /etc/profile
    source /etc/profile
    
    echo  "-----initialize MySQL-----"
    /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/server/mysql_data/
    
    echo  "-----start  MySQL-----"
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
    /etc/init.d/mysqld start
    
    echo  "-----init  password of MySQL-----"
    OLD_PWD=`cat /server/mysql_data/error.log | grep password |awk -F: '{print $5}' |awk '{print $1}'`
    echo 'old password:$OLD_PWD'
    NEW_PWD=`openssl rand -base64 9`
    echo 'set password for 'root'@'localhost' =password('$NEW_PWD');'
    
    
    
    
    
    
  • 相关阅读:
    VC++ error C2248: “CObject::CObject”: 无法访问 private 成员(在“CObject”类中声明)
    VC++ 在使用 CImage 的Draw 输入一个图像时,有时候会造成图像失真严重,解决的方法如下
    VC++ 中CDC与HDC的区别以及二者之间的转换
    BASE64编码和解码(VC源代码) 并 内存加载 CImage 图像
    VC 使用OnCtlColor函数来改变控件颜色(引用)
    VC++ 对话框程序响应键盘消息的处理方法的说明(非常重要)
    VC++ 迭代器 iterator, const_iterator, const iterator
    VC++ 解决在鼠标移动时,光标闪烁的问题。其实本质是 ON_SETCURSOR的用法
    SQL练习题-50道SQL练习题及答案与详细分析
    Windows Essentials Movie Maker 安装失败报错 ——问题解决
  • 原文地址:https://www.cnblogs.com/DBABlog/p/12926909.html
Copyright © 2020-2023  润新知