• MySQL安装脚本最佳实践


     

    MySQL安装脚本最佳实践
    2018年9月19日
    17:01
    #!/bin/bash
     
    export host_ip=192.168.7.206
     
    echo '#1.取master主机ip的后三位作为master的server_id'
    export host_server_id=`echo $host_ip |awk -F . '{print $4}'`
     
     
     
    echo '1.屏蔽当前的MySQL环境'
    service mysql stop
    rm -f /etc/my.cnf
     
    echo '2.检查并卸载系统中低版本的mysql'
    #rpm -e mariadb-libs --nodeps
     
    echo '3.添加用户和组'
    rm -rf /home/mysql/
    userdel mysql
    #groupdel mysql
    groupadd  mysql
    useradd -g mysql mysql
     
    echo '4.创建目录及授权'
    rm -rf /data
    mkdir -p /data/mysql
    mkdir -p /data/my3309/data
    mkdir -p /data/my3309/log/iblog
    mkdir -p /data/my3309/log/binlog
    mkdir -p /data/my3309/log/relaylog
    mkdir -p /data/my3309/run
    mkdir -p /data/my3309/tmp
    chown -R mysql:mysql /data/my3309
    chmod -R 755 /data/my3309
     
    echo '5.上传解压软件包'
    cd /software
    tar zxf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
    cd mysql-5.7.23-linux-glibc2.12-x86_64
    cp -R * /data/mysql/
    chown -R mysql:mysql /data/
     
    echo '6.修改配置文件my.cnf参数'
    #手动上传写好的my.cnf配置文件
    cp /scripts/my.cnf /etc/
    ##cp /data/mysql/support-files/my-default.cnf  /data/mysql/my.cnf
    #chown -R mysql:mysql /data/my3309
    #cd /data/my3309/data
    #rm -rf *
    #cd /data/my3309/log
    #rm -f binlog/*
    #rm -f iblog/*
    #rm -rf relaylog/
    #rm -rf slow.log
     
    echo '7.执行MySQL安装脚本'
    cd /data/mysql/
    bin/mysqld --initialize-insecure  --user=mysql --datadir=/data/my3309/data/ --basedir=/data/my3309  #必须到脚本的父目录执行哦
    #./scripts/mysql_install_db  --defaults-file=/data/mysql/my.cnf  --user=mysql --datadir=/data/my3309/data
     
     
    echo '#1.取master主机ip的后三位作为master的server_id'
    export host_server_id=`echo $host_ip |awk -F . '{print $4}'`
    #echo $host_server_id
     
    eval sed -i 's/server_id=128/server_id=${host_server_id}/g' /etc/my.cnf
    cat /etc/my.cnf |grep server_id
     
     
     
    echo '8.修改系统环境变量'
    echo "PATH=/data/mysql/bin:$PATH:/sbin" >> /etc/profile
    source /etc/profile
     
    echo '9.自启动脚本'
    #cp /data/mysql/my.cnf /etc/my.cnf
    cp /data/mysql/support-files/mysql.server /etc/init.d/mysql
    sed -i 's#^basedir=#basedir=/data/mysql#g' /etc/init.d/mysql
    sed -i 's#^datadir=#datadir=/data/mysql/data#g' /etc/init.d/mysql
    sed -i 's#^mysqld_pid_file_path=#mysqld_pid_file_path=/data/my3309/run/mysqld.pid#g' /etc/init.d/mysql
    chkconfig --add mysql
    /etc/init.d/mysql start
    /etc/init.d/mysql stop
    service mysql start
     
    echo '10.删除默认匿名账户'
    #mysql -h127.0.0.1 -uroot -P3309 -e "flush privileges;"
    mysql  -uroot -P3309 <<EOF
    flush privileges;
    update mysql.user set authentication_string='password(123456)' where user='root';
    delete from mysql.user where user='';
    set old_passwords=0;
    create user 'replusr'@'%' identified by '123456';
    create user 'root'@'192.168.7.206' identified by '123456';
    create user 'root'@'192.168.7.207' identified by '123456';
    grant replication slave on *.* to 'replusr'@'%';
    grant super on *.* to 'replusr'@'%';
    grant all privileges on *.* to 'root'@'%' identified by '&password' with grant option;
    update mysql.user set authentication_string='password(123456)' where user='root';
    flush privileges;
    EOF
    service mysql restart
    exit
  • 相关阅读:
    Win7 64位下ProxyCap代理Java
    kafka一个诡异错误
    linux下oracle修改、新建用户并授权
    es常用查询
    linux 下启动tomcat报错 Cannot find ./catalina.sh
    linux虚拟机添加端口访问
    Linux下启动Oracle服务和监听程序
    es基础
    mysql授权远程任意人登录
    添加POI导出excel通用工具类
  • 原文地址:https://www.cnblogs.com/iyoume2008/p/9675546.html
Copyright © 2020-2023  润新知