首页 > 数据库 >rocky二进制安装mysql8.0

rocky二进制安装mysql8.0

时间:2022-08-23 15:13:18浏览次数:70  
标签:rocky 二进制 local dev etc mysql8.0 mysql null root

(ubuntu的有点问题)

点击查看代码
#!/bin/bash

Version=`cat /etc/os-release  |awk -F'"| ' '/^NAME/{print $2}'`
SQLSERVER=mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
dir=/usr/local
datadir=/data/mysql
rocky_install_mysql(){
    groupadd -r -g 199 mysql &> /dev/null
    useradd -r -g mysql -u 199 -s /sbin/nologin -d /data/mysql mysql &> /dev/null
    [ -d $datadir ] || mkdir -p $datadir
    cd $dir 
    wget https://downloads.mysql.com/archives/get/p/23/file/$SQLSERVER || echo "下载失败,请检查网络"
    tar xf $SQLSERVER &> /dev/null 
    ln -s $SQLSERVER mysql &> /dev/null
    chown -R root.root /usr/local/mysql/ 
    echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh && . /etc/profile.d/mysql.sh
    cat > /etc/mysql.cnf <<EOF
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
EOF
    mysqld --initialize-insecure --user=mysql --datadir=/data/mysql && mysqladmin password 123456 && echo "密码已设置:123456" 
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld &> /dev/null  && chkconfig --add mysqld &> /dev/null 
    service mysqld start && echo "服务已启动"
}

ubuntu_install_mysql(){
    groupadd -r -g 199 mysql &> /dev/null
    useradd -r -g mysql -u 199 -s /sbin/nologin -d /data/mysql mysql &> /dev/null
    [ -d $datadir ] || mkdir -p $datadir
    cd $dir 
    wget https://downloads.mysql.com/archives/get/p/23/file/$SQLSERVER || echo "下载失败,请检查网络"
    tar xf $SQLSERVER &> /dev/null
    ln -s $SQLSERVER mysql &> /dev/null
    chown -R root.root /usr/local/mysql/
    echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh && . /etc/profile.d/mysql.sh
    cat > /etc/mysql.cnf <<EOF
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
EOF
    mysqld --initialize-insecure --user=mysql --datadir=/data/mysql && mysqladmin password 123456 && echo "密码已设置:123456"
    ln -s /lib/x86_64-linux-gnu/libtinfo.so.6.2 /lib/x86_64-linux-gnu/libtinfo.so.5 &> /dev/null
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/ && /etc/init.d/mysql.server start
}
Rocky_local_install_SQL(){
    if  [ ! -e /usr/local/$SQLSERVER ] ;then
        echo "找不到安装包"
        exit
    else

    groupadd -r -g 199 mysql &> /dev/null
    useradd -r -g mysql -u 199 -s /sbin/nologin -d /data/mysql mysql &> /dev/null
    [ -d $datadir ] || mkdir -p $datadir
    cd $dir
    tar xf $SQLSERVER &> /dev/null
    ln -s $SQLSERVER mysql &> /dev/null
    chown -R root.root /usr/local/mysql/
    echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh && . /etc/profile.d/mysql.sh
    cat > /etc/mysql.cnf <<EOF
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
EOF
    mysqld --initialize-insecure --user=mysql --datadir=/data/mysql && mysqladmin password 123456 && echo "密码已设置:123456" 
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld && chkconfig --add mysqld
    service mysqld start && echo "服务已启动"
    fi
}
######ubuntu脚本有点问题
Ubuntu_local_install_mysql(){
    if  [ ! -e /usr/local/$SQLSERVER ] ;then  find / -name "$afa" 
        echo "找不到安装包"
        exit
    else
    groupadd -r -g 199 mysql &> /dev/null
    useradd -r -g mysql -u 199 -s /sbin/nologin -d /data/mysql mysql &> /dev/null
    [ -d $datadir ] || mkdir -p $datadir
    cd $dir
    tar xf $SQLSERVER &> /dev/null
    ln -s $SQLSERVER mysql &> /dev/null
    chown -R root.root /usr/local/mysql/
    echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh && . /etc/profile.d/mysql.sh
    cat > /etc/mysql.cnf <<EOF
[mysqld]
datadir=/data/mysql
skip_name_resolve=1
socket=/data/mysql/mysql.sock
log-error=/data/mysql/mysql.log
pid-file=/data/mysql/mysql.pid
[client]
socket=/data/mysql/mysql.sock
EOF
    mysqld --initialize-insecure --user=mysql --datadir=/data/mysql && mysqladmin password 123456 && echo "密码已设置:123456" 
    ln -s /lib/x86_64-linux-gnu/libtinfo.so.6.2 /lib/x86_64-linux-gnu/libtinfo.so.5 &> /dev/null
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/ && /etc/init.d/mysql.server start
    fi

}
    PS3="请选择:"
    select MENU in 本地安装 网络安装 退出 ;do
        case $MENU in
            本地安装)
                if  [[ $Version == Rocky ]];then
                    [[ `whoami` != root  ]] && { echo "您的用户不是root,请切换root重试" ; exit; }
                    Rocky_local_install_SQL
                else [[ $Version == Ubuntu ]] 
                     [[ `whoami` != root  ]] && { echo "您的用户不是root,请切换root重试" ; exit; }
                    Ubuntu_local_install_mysql
                fi 
            ;;
            网络安装)
                if  [[ $Version == Rocky ]];then
                    [[ `whoami` != root  ]] && { echo "您的用户不是root,请切换root重试" ; exit; } 
                    rocky_install_mysql 
                else [[ $Version == Ubuntu ]]
                     [[ `whoami` != root  ]] && { echo "您的用户不是root,请切换root重试" ; exit; }
                    ubuntu_install_mysql
                fi
            ;;
           退出)
                exit
            ;;
        esac
    done








标签:rocky,二进制,local,dev,etc,mysql8.0,mysql,null,root
From: https://www.cnblogs.com/wdy001/p/16616229.html

相关文章