#!/bin/bash
#
#********************************************************************
#Author: wangxiaochun
#Date: 2022-08-22
#FileName: automysql.sh
#URL: http://www.wangxiaochun.com
#Description: The test script
#Copyright (C): 2022 All rights reserved
#********************************************************************
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/my.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/my.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/my.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/my.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
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
MySQL5.7.36安装-二进制(源码)版本
MySQL5.7.36安装-二进制(源码)版本
mysql MySQL sed -
MYSQL安装之二进制
二进制快速安装MYSQL
MYSQL 安装 二进制 -
MySQL8.0.28之二进制包安装
MySQL8.0安装
mysql linux 微信公众号 -
二进制安装docker脚本
二进制安装docker CE
docker -
mysql主从搭建(二进制脚本安装)
mysql主从搭建(二进制脚本安装)
mysql主从搭建(二进制脚本安装) -
脚本二进制安装Mysql mysql二进制安装教程
一、上传MySQL二进制安装包到服务器
MySQL 数据库 数据目录