• 分享一个Ubuntu16.0.4安装MySQL5.7脚本


    好久没写脚本了,今天为了测试做了下mysql同时也写了一个小小的安装脚本 不过这还是第一次在Ubuntu环境写脚本 如下:

    #!/bin/bash
    ###########################################################
    #Ubuntu16.0.4 Install MySQL5.7
    ###########################################################
    Catalog=/usr/local/src
    function Internet(){
        wget --spider -q -o /dev/null --tries=1 -T 5 http://www.baidu.com
            if [ "$?" -ne 0 ]
                then
                    echo "Please check your network"
            return 1
            fi
    }
    
    function package(){
        sudo apt-get install -y vim && sudo apt-get install -y wget  && apt-get install libaio* -y
    }
    
    function Install_MySQL(){
        cd $Catalog && {
             wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz &>/dev/null
                if [ "$?" -ne 0 ];then
                    echo "wget MySQL ERROR!!!"
                    return 1
                else
                    tar zxf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz &&  
                    mv mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql && 
                        cd /usr/local/mysql/ && mkdir data && mkdir log && echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile &&  
                             source /etc/profile && groupadd mysql && useradd -r -g mysql -s /bin/false mysql 
        }
    }
    
    function conf(){
    
    cat << Daasbank > /etc/my.cnf  
    [client]      
    socket=/usr/local/mysql/mysql.sock      
    [mysqld]      
    basedir=/usr/local/mysql      
    datadir=/usr/local/mysql/data      
    pid-file=/usr/local/mysql/data/mysqld.pid      
    socket=/usr/local/mysql/mysql.sock      
    log_error=/usr/local/mysql/log/mysql.err    
    Daasbank
    if [ -f /etc/my.cnf ]
        then
          chmod 750 data/ && chown -R mysql . && chgrp -R mysql . && /usr/local/mysql/bin/mysqld --initialize --user=mysql && cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld && systemctl enable mysqld  && /etc/init.d/mysqld start &> /dev/null 
        else
          ln -s /usr/local/mysql/bin/mysql /usr/local/bin
          ln -s /usr/local/mysql/bin/mysqladmin /usr/local/bin
    fi
    }
    
    function main(){
        Internet
        package
        Install_MySQL
        conf
    }
    main

    谢谢观看~ 

  • 相关阅读:
    java运行时异常与一般异常有何异同?
    B+树原理及mysql的索引分析
    ibatis in的用法
    brython的问题
    限流算法的原理
    Java8的CompletionService使用与原理
    命令行相关快捷键
    Java8 异步编排类CompletableFuture
    分布式系统ID生成方案
    curl 命令简介
  • 原文地址:https://www.cnblogs.com/YankaiJY/p/8857688.html
Copyright © 2020-2023  润新知