You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
mysql/mysql-5.7.38/install-db.sh

993 lines
36 KiB

#!/usr/bin/env bash
Install_LSB() {
echo "[+] Installing lsb..."
if [ "$PM" = "yum" ]; then
yum -y install redhat-lsb
elif [ "$PM" = "apt" ]; then
apt-get update
apt-get --no-install-recommends install -y lsb-release
fi
}
Get_Dist_Version() {
if command -v lsb_release >/dev/null 2>&1; then
DISTRO_Version=$(lsb_release -sr)
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
DISTRO_Version="$DISTRIB_RELEASE"
elif [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO_Version="$VERSION_ID"
fi
if [[ "${DISTRO}" == "" || "${DISTRO_Version}" == "" ]]; then
if command -v python2 >/dev/null 2>&1; then
DISTRO_Version=$(python2 -c 'import platform; print platform.linux_distribution()[1]')
elif command -v python3 >/dev/null 2>&1; then
DISTRO_Version=$(python3 -c 'import platform; print(platform.linux_distribution()[1])')
else
Install_LSB
DISTRO_Version=$(lsb_release -rs)
fi
fi
printf -v "${DISTRO}_Version" '%s' "${DISTRO_Version}"
}
Get_RHEL_Version() {
Get_Dist_Name
if [ "${DISTRO}" = "RHEL" ]; then
if grep -Eqi "release 5." /etc/redhat-release; then
echo "Current Version: RHEL Ver 5"
RHEL_Ver='5'
elif grep -Eqi "release 6." /etc/redhat-release; then
echo "Current Version: RHEL Ver 6"
RHEL_Ver='6'
elif grep -Eqi "release 7." /etc/redhat-release; then
echo "Current Version: RHEL Ver 7"
RHEL_Ver='7'
elif grep -Eqi "release 8." /etc/redhat-release; then
echo "Current Version: RHEL Ver 8"
RHEL_Ver='8'
fi
RHEL_Version="$(cat /etc/redhat-release | sed 's/.*release\ //' | sed 's/\ .*//')"
fi
}
Get_OS_Bit() {
if [[ $(getconf WORD_BIT) == '32' && $(getconf LONG_BIT) == '64' ]]; then
Is_64bit='y'
ARCH='x86_64'
DB_ARCH='x86_64'
else
Is_64bit='n'
ARCH='i386'
DB_ARCH='i686'
fi
if uname -m | grep -Eqi "arm|aarch64"; then
Is_ARM='y'
if uname -m | grep -Eqi "armv7|armv6"; then
ARCH='armhf'
elif uname -m | grep -Eqi "aarch64"; then
ARCH='aarch64'
else
ARCH='arm'
fi
fi
}
Get_Dist_Name() {
if grep -Eqi "CentOS" /etc/issue || grep -Eq "CentOS" /etc/*-release; then
DISTRO='CentOS'
PM='yum'
if grep -Eq "CentOS Stream" /etc/*-release; then
isCentosStream='y'
fi
elif grep -Eqi "Alibaba" /etc/issue || grep -Eq "Alibaba Cloud Linux" /etc/*-release; then
DISTRO='Alibaba'
PM='yum'
elif grep -Eqi "Aliyun" /etc/issue || grep -Eq "Aliyun Linux" /etc/*-release; then
DISTRO='Aliyun'
PM='yum'
elif grep -Eqi "Amazon Linux" /etc/issue || grep -Eq "Amazon Linux" /etc/*-release; then
DISTRO='Amazon'
PM='yum'
elif grep -Eqi "Fedora" /etc/issue || grep -Eq "Fedora" /etc/*-release; then
DISTRO='Fedora'
PM='yum'
elif grep -Eqi "Oracle Linux" /etc/issue || grep -Eq "Oracle Linux" /etc/*-release; then
DISTRO='Oracle'
PM='yum'
elif grep -Eqi "Red Hat Enterprise Linux" /etc/issue || grep -Eq "Red Hat Enterprise Linux" /etc/*-release; then
DISTRO='RHEL'
PM='yum'
elif grep -Eqi "rockylinux" /etc/issue || grep -Eq "Rocky Linux" /etc/*-release; then
DISTRO='Rocky'
PM='yum'
elif grep -Eqi "almalinux" /etc/issue || grep -Eq "AlmaLinux" /etc/*-release; then
DISTRO='Alma'
PM='yum'
elif grep -Eqi "openEuler" /etc/issue || grep -Eq "openEuler" /etc/*-release; then
DISTRO='openEuler'
PM='yum'
elif grep -Eqi "Anolis OS" /etc/issue || grep -Eq "Anolis OS" /etc/*-release; then
DISTRO='Anolis'
PM='yum'
elif grep -Eqi "Kylin Linux Advanced Server" /etc/issue || grep -Eq "Kylin Linux Advanced Server" /etc/*-release; then
DISTRO='Kylin'
PM='yum'
elif grep -Eqi "Debian" /etc/issue || grep -Eq "Debian" /etc/*-release; then
DISTRO='Debian'
PM='apt'
elif grep -Eqi "Ubuntu" /etc/issue || grep -Eq "Ubuntu" /etc/*-release; then
DISTRO='Ubuntu'
PM='apt'
elif grep -Eqi "Raspbian" /etc/issue || grep -Eq "Raspbian" /etc/*-release; then
DISTRO='Raspbian'
PM='apt'
elif grep -Eqi "Deepin" /etc/issue || grep -Eq "Deepin" /etc/*-release; then
DISTRO='Deepin'
PM='apt'
elif grep -Eqi "Mint" /etc/issue || grep -Eq "Mint" /etc/*-release; then
DISTRO='Mint'
PM='apt'
elif grep -Eqi "Kali" /etc/issue || grep -Eq "Kali" /etc/*-release; then
DISTRO='Kali'
PM='apt'
elif grep -Eqi "UnionTech OS" /etc/issue || grep -Eq "UnionTech OS" /etc/*-release; then
DISTRO='UOS'
if command -v apt >/dev/null 2>&1; then
PM='apt'
elif command -v yum >/dev/null 2>&1; then
PM='yum'
fi
elif grep -Eqi "Kylin Linux Desktop" /etc/issue || grep -Eq "Kylin Linux Desktop" /etc/*-release; then
DISTRO='Kylin'
PM='yum'
else
DISTRO='unknow'
fi
Get_OS_Bit
}
Check_DB() {
if [[ -s /usr/local/mariadb/bin/mysql && -s /usr/local/mariadb/bin/mysqld_safe && -s /etc/my.cnf ]]; then
MySQL_Bin="/usr/local/mariadb/bin/mysql"
MySQL_Config="/usr/local/mariadb/bin/mysql_config"
MySQL_Dir="/usr/local/mariadb"
Is_MySQL="n"
DB_Name="mariadb"
elif [[ -s /usr/local/mysql/bin/mysql && -s /usr/local/mysql/bin/mysqld_safe && -s /etc/my.cnf ]]; then
MySQL_Bin="/usr/local/mysql/bin/mysql"
MySQL_Config="/usr/local/mysql/bin/mysql_config"
MySQL_Dir="/usr/local/mysql"
Is_MySQL="y"
DB_Name="mysql"
else
Is_MySQL="None"
DB_Name="None"
fi
}
Press_Install() {
Boost_Ver='boost_1_59_0'
Boost_New_Ver='boost_1_67_0'
Openssl_Ver='openssl-1.0.2u'
Openssl_New_Ver='openssl-1.1.1o'
if [ "${DBSelect}" = "1" ]; then
Mysql_Ver='mysql-5.1.73'
elif [ "${DBSelect}" = "2" ]; then
Mysql_Ver='mysql-5.5.62'
elif [ "${DBSelect}" = "3" ]; then
Mysql_Ver='mysql-5.6.51'
elif [ "${DBSelect}" = "4" ]; then
Mysql_Ver='mysql-5.7.38'
elif [ "${DBSelect}" = "5" ]; then
Mysql_Ver='mysql-8.0.30'
elif [ "${DBSelect}" = "6" ]; then
Mariadb_Ver='mariadb-5.5.68'
elif [ "${DBSelect}" = "7" ]; then
Mariadb_Ver='mariadb-10.3.35'
elif [ "${DBSelect}" = "8" ]; then
Mariadb_Ver='mariadb-10.4.25'
elif [ "${DBSelect}" = "9" ]; then
Mariadb_Ver='mariadb-10.5.16'
elif [ "${DBSelect}" = "10" ]; then
Mariadb_Ver='mariadb-10.6.8'
fi
}
Database_Selection() {
#which MySQL Version do you want to install?
if [ -z ${DBSelect} ]; then
Echo_Yellow "You have 11 options for your DataBase install."
echo "1: Install ${DB_Info[0]}"
echo "2: Install ${DB_Info[1]}"
echo "3: Install ${DB_Info[2]}"
echo "4: Install ${DB_Info[3]}"
echo "5: Install ${DB_Info[4]}"
echo "6: Install ${DB_Info[5]}"
echo "7: Install ${DB_Info[6]}"
echo "8: Install ${DB_Info[7]}"
echo "9: Install ${DB_Info[8]}"
echo "10: Install ${DB_Info[9]}"
echo "0: DO NOT Install MySQL/MariaDB"
#read -p "Enter your choice (1, 2, 3, 4, 5, 6, 7, 8, 9, 10 or 0): " DBSelect
DBSelect='4'
Bin='n'
fi
case "${DBSelect}" in
1)
echo "You will install ${DB_Info[0]}"
;;
2)
echo "You will install ${DB_Info[1]}"
;;
3)
echo "You will Install ${DB_Info[2]}"
;;
4)
if [[ "${ARCH}" == "x86_64" || "${ARCH}" == "i386" ]]; then
if [ -z ${Bin} ]; then
read -p "Using Generic Binaries [y/n]: " Bin
fi
case "${Bin}" in
[yY][eE][sS] | [yY])
echo "You will install ${DB_Info[3]} Using Generic Binaries."
Bin="y"
;;
[nN][oO] | [nN])
echo "You will install ${DB_Info[3]} from Source."
Bin="n"
;;
*)
if [ "${CheckMirror}" != "n" ]; then
echo "Default install ${DB_Info[3]} Using Generic Binaries."
Bin="y"
else
echo "Default install ${DB_Info[3]} from Source."
Bin="n"
fi
;;
esac
else
Bin="n"
fi
;;
5)
if [[ "${ARCH}" == "x86_64" || "${ARCH}" == "i386" ]]; then
if [ -z ${Bin} ]; then
read -p "Using Generic Binaries [y/n]: " Bin
fi
case "${Bin}" in
[yY][eE][sS] | [yY])
echo "You will install ${DB_Info[4]} Using Generic Binaries."
Bin="y"
;;
[nN][oO] | [nN])
echo "You will install ${DB_Info[4]} from Source."
Bin="n"
;;
*)
if [ "${CheckMirror}" != "n" ]; then
echo "Default install ${DB_Info[4]} Using Generic Binaries."
Bin="y"
else
echo "Default install ${DB_Info[4]} from Source."
Bin="n"
fi
;;
esac
else
Bin="n"
fi
;;
6)
echo "You will install ${DB_Info[5]}"
;;
7)
echo "You will install ${DB_Info[6]}"
;;
8)
echo "You will install ${DB_Info[7]}"
;;
9)
echo "You will install ${DB_Info[8]}"
;;
10)
echo "You will install ${DB_Info[9]}"
;;
0)
echo "Do not install MySQL/MariaDB!"
;;
*)
echo "No input,You will install ${DB_Info[1]}"
DBSelect="2"
;;
esac
if [ "${Bin}" != "y" ] && [[ "${DBSelect}" =~ ^5|[7-9]|10$ ]] && [ $(free -m | grep Mem | awk '{print $2}') -le 1024 ]; then
echo "Memory less than 1GB, can't install MySQL 8.0 or MairaDB 10.3+!"
exit 1
fi
if [[ "${DBSelect}" =~ ^[6789]|10$ ]]; then
MySQL_Bin="/usr/local/mariadb/bin/mysql"
MySQL_Config="/usr/local/mariadb/bin/mysql_config"
MySQL_Dir="/usr/local/mariadb"
elif [[ "${DBSelect}" =~ ^[12345]$ ]]; then
MySQL_Bin="/usr/local/mysql/bin/mysql"
MySQL_Config="/usr/local/mysql/bin/mysql_config"
MySQL_Dir="/usr/local/mysql"
fi
}
Download_Files() {
local URL=$1
local FileName=$2
if [ -s "${FileName}" ]; then
echo "${FileName} [found]"
else
echo "Notice: ${FileName} not found!!!download now..."
wget -c --progress=bar:force --prefer-family=IPv4 --no-check-certificate ${URL}
fi
}
Check_PowerTools() {
if ! yum -v repolist all | grep "PowerTools"; then
echo "PowerTools repository not found!"
fi
repo_id=$(yum repolist all | grep -Ei "PowerTools" | head -n 1 | awk '{print $1}')
}
Check_Codeready() {
repo_id=$(yum repolist all | grep -E "CodeReady" | head -n 1 | awk '{print $1}')
[ -z "${repo_id}" ] && repo_id="ol8_codeready_builder"
}
Tar_Cd() {
local FileName=$1
local DirName=$2
cd ${cur_dir}/src
[[ -d "${DirName}" ]] && rm -rf ${DirName}
echo "Uncompress ${FileName}..."
tar zxf ${FileName}
if [ -n "${DirName}" ]; then
echo "cd ${DirName}..."
cd ${DirName}
fi
}
Color_Text() {
echo -e " \e[0;$2m$1\e[0m"
}
Echo_Red() {
echo $(Color_Text "$1" "31")
}
Echo_Green() {
echo $(Color_Text "$1" "32")
}
Echo_Yellow() {
echo $(Color_Text "$1" "33")
}
Echo_Blue() {
echo $(Color_Text "$1" "34")
}
DB_Dependent() {
if [ "$PM" = "yum" ]; then
yum -y remove mysql-server mysql mysql-libs mariadb-server mariadb mariadb-libs
rpm -qa | grep mysql
if [ $? -ne 0 ]; then
rpm -e mysql mysql-libs --nodeps
rpm -e mariadb mariadb-libs --nodeps
fi
for packages in make cmake gcc gcc-c++ gcc-g77 flex bison wget zlib zlib-devel openssl openssl-devel ncurses ncurses-devel libaio-devel rpcgen libtirpc-devel patch cyrus-sasl-devel pkg-config pcre-devel libxml2-devel hostname ncurses-libs numactl-devel libxcrypt; do yum -y install $packages; done
if echo "${CentOS_Version}" | grep -Eqi "^8" || echo "${RHEL_Version}" | grep -Eqi "^8" || echo "${Rocky_Version}" | grep -Eqi "^8" || echo "${Alma_Version}" | grep -Eqi "^8"; then
Check_PowerTools
dnf --enablerepo=${repo_id} install rpcgen -y
dnf install libarchive -y
dnf install gcc-toolset-10 -y
fi
if [ "${DISTRO}" = "Oracle" ] && echo "${Oracle_Version}" | grep -Eqi "^8"; then
Check_Codeready
dnf --enablerepo=${repo_id} install rpcgen re2c -y
dnf install libarchive -y
fi
if [ "${DISTRO}" = "Fedora" ] || echo "${CentOS_Version}" | grep -Eqi "^9" || echo "${Alma_Version}" | grep -Eqi "^9" || echo "${Rocky_Version}" | grep -Eqi "^9"; then
dnf install chkconfig -y
fi
if [ -s /usr/lib64/libtinfo.so.6 ]; then
ln -sf /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5
elif [ -s /usr/lib/libtinfo.so.6 ]; then
ln -sf /usr/lib/libtinfo.so.6 /usr/lib/libtinfo.so.5
fi
if [ -s /usr/lib64/libncurses.so.6 ]; then
ln -sf /usr/lib64/libncurses.so.6 /usr/lib64/libncurses.so.5
elif [ -s /usr/lib/libncurses.so.6 ]; then
ln -sf /usr/lib/libncurses.so.6 /usr/lib/libncurses.so.5
fi
elif [ "$PM" = "apt" ]; then
export DEBIAN_FRONTEND=noninteractive
apt-get update -y
[[ $? -ne 0 ]] && apt-get update --allow-releaseinfo-change -y
apt-get purge -y mysql-client mysql-server mysql-common mysql-server-core-5.5 mysql-client-5.5 mariadb-client mariadb-server mariadb-common
dpkg -l | grep mysql
dpkg -P mysql-server mysql-common libmysqlclient15off libmysqlclient15-dev
dpkg -P mariadb-client mariadb-server mariadb-common
apt-get --no-install-recommends install -y debian-keyring debian-archive-keyring build-essential gcc g++ make cmake
apt-get --no-install-recommends install -y autoconf automake wget openssl libssl-dev zlib1g zlib1g-dev libncurses5
apt-get --no-install-recommends install -y libncurses5-dev bison libaio-dev libtirpc-dev libsasl2-dev pkg-config
apt-get --no-install-recommends install -y libpcre2-dev libxml2-dev libtinfo-dev libnuma-dev gnutls-dev tzdata
fi
}
Check_Openssl() {
if ! command -v openssl >/dev/null 2>&1; then
Echo_Blue "[+] Installing openssl..."
if [ "${PM}" = "yum" ]; then
yum install -y ntpdate
elif [ "${PM}" = "apt" ]; then
apt-get update -y
[[ $? -ne 0 ]] && apt-get update --allow-releaseinfo-change -y
apt-get install -y openssl
fi
fi
openssl version
if openssl version | grep -Eqi "OpenSSL 3.*"; then
isOpenSSL3='y'
fi
}
Download_Boost() {
echo "[+] Download or use exist boost..."
if [ "${DBSelect}" = "4" ] || echo "${mysql_version}" | grep -Eqi '^5.7.'; then
if [ -s "${cur_dir}/src/${Boost_Ver}.tar.bz2" ]; then
[[ -d "${cur_dir}/src/${Boost_Ver}" ]] && rm -rf "${cur_dir}/src/${Boost_Ver}"
tar jxf ${cur_dir}/src/${Boost_Ver}.tar.bz2 -C ${cur_dir}/src
MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/${Boost_Ver}"
else
cd ${cur_dir}/src/
Download_Files ${Download_Mirror}/lib/boost/${Boost_Ver}.tar.bz2 ${Boost_Ver}.tar.bz2
tar jxf ${cur_dir}/src/${Boost_Ver}.tar.bz2
cd -
MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/${Boost_Ver}"
fi
elif [ "${DBSelect}" = "5" ] || echo "${mysql_version}" | grep -Eqi '^8.0.'; then
Get_Boost_Ver=$(grep 'SET(BOOST_PACKAGE_NAME' cmake/boost.cmake | grep -oP '\d+(\_\d+){2}')
if [ -s "${cur_dir}/src/boost_${Get_Boost_Ver}.tar.bz2" ]; then
[[ -d "${cur_dir}/src/boost_${Get_Boost_Ver}" ]] && rm -rf "${cur_dir}/src/boost_${Get_Boost_Ver}"
tar jxf ${cur_dir}/src/boost_${Get_Boost_Ver}.tar.bz2 -C ${cur_dir}/src
MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/boost_${Get_Boost_Ver}"
else
MySQL_WITH_BOOST="-DDOWNLOAD_BOOST=1 -DWITH_BOOST=${cur_dir}/src"
fi
fi
}
Install_Boost() {
echo "[+] Download or use exist boost..."
if [ "${DBSelect}" = "4" ] || [ "${DBSelect}" = "5" ]; then
if [ -d "${cur_dir}/src/${Mysql_Ver}/boost" ]; then
MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/${Mysql_Ver}/boost"
else
Download_Boost
fi
elif echo "${mysql_version}" | grep -Eqi '^5.7.' || echo "${mysql_version}" | grep -Eqi '^8.0.'; then
if [ -d "${cur_dir}/src/mysql-${mysql_version}/boost" ]; then
MySQL_WITH_BOOST="-DWITH_BOOST=${cur_dir}/src/mysql-${mysql_version}/boost"
else
Download_Boost
fi
fi
}
Make_Install() {
make -j $(grep 'processor' /proc/cpuinfo | wc -l)
if [ $? -ne 0 ]; then
make
fi
make install
}
MySQL_Sec_Setting() {
if [ -d "/proc/vz" ]; then
ulimit -s unlimited
fi
if [ -d "/etc/mysql" ]; then
mv /etc/mysql /etc/mysql.backup.$(date +%Y%m%d)
fi
ln -sf /usr/local/mysql/bin/* /usr/local/bin/
#ln -sf /usr/local/mysql/bin/mysqld /usr/bin/mysqld
#ln -sf /usr/local/mysql/bin/mysql /usr/bin/mysql
#ln -sf /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
#ln -sf /usr/local/mysql/bin/myisamchk /usr/bin/myisamchk
# ln -sf /usr/local/mysql/bin/mysqld_safe /usr/bin/mysqld_safe
# ln -sf /usr/local/mysql/bin/mysqlcheck /usr/bin/mysqlcheck
}
Check_MySQL_Data_Dir() {
if [ -d "${MySQL_Data_Dir}" ]; then
datetime=$(date +"%Y%m%d%H%M%S")
mkdir -p /root/mysql-data-dir-backup${datetime}/
\cp ${MySQL_Data_Dir}/* /root/mysql-data-dir-backup${datetime}/
rm -rf ${MySQL_Data_Dir}/*
else
mkdir -p ${MySQL_Data_Dir}
fi
}
Install_MySQL_51() {
echo "[+] Installing ${Mysql_Ver}..."
rm -f /etc/my.cnf
Tar_Cd ${Mysql_Ver}.tar.gz ${Mysql_Ver}
MySQL_Gcc7_Patch
if [ "${InstallInnodb}" = "y" ]; then
./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=innobase ${MySQL51MAOpt}
else
./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-assembler --with-mysqld-ldflags=-all-static --with-charset=utf8 --enable-thread-safe-client --with-big-tables --with-readline --with-ssl --with-embedded-server --enable-local-infile ${MySQL51MAOpt}
fi
sed -i '/set -ex;/,/done/d' Makefile
Make_Install
Check_MySQL_Data_Dir
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql ${MySQL_Data_Dir}
cat >/etc/ld.so.conf.d/mysql.conf <<EOF
/usr/local/mysql/lib/mysql
/usr/local/lib
EOF
ldconfig
ln -sf /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -sf /usr/local/mysql/include/mysql /usr/include/mysql
MySQL_Sec_Setting
}
Install_MySQL_55() {
echo "[+] Installing ${Mysql_Ver}..."
rm -f /etc/my.cnf
Tar_Cd ${Mysql_Ver}.tar.gz ${Mysql_Ver}
MySQL_ARM_Patch
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1
Make_Install
Check_MySQL_Data_Dir
cat >/etc/ld.so.conf.d/mysql.conf <<EOF
/usr/local/mysql/lib
/usr/local/lib
EOF
ldconfig
ln -sf /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -sf /usr/local/mysql/include/mysql /usr/include/mysql
MySQL_Sec_Setting
}
Install_MySQL_56() {
echo "[+] Installing ${Mysql_Ver}..."
rm -f /etc/my.cnf
Tar_Cd ${Mysql_Ver}.tar.gz ${Mysql_Ver}
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1
Make_Install
Check_MySQL_Data_Dir
chown -R mysql:mysql /usr/local/mysql
cat >/etc/ld.so.conf.d/mysql.conf <<EOF
/usr/local/mysql/lib
/usr/local/lib
EOF
ldconfig
ln -sf /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -sf /usr/local/mysql/include/mysql /usr/include/mysql
MySQL_Sec_Setting
}
Install_MySQL_57() {
rm -f /etc/my.cnf
if [ "${Bin}" = "y" ]; then
echo "[+] Installing ${Mysql_Ver} Using Generic Binaries..."
Tar_Cd ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz
mkdir /usr/local/mysql
mv ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}/* /usr/local/mysql/
else
echo "[+] Installing ${Mysql_Ver} Using Source code..."
Tar_Cd ${Mysql_Ver}.tar.gz ${Mysql_Ver}
Install_Boost
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 ${MySQL_WITH_BOOST}
Make_Install
fi
Check_MySQL_Data_Dir
chown -R mysql:mysql /usr/local/mysql
cat >/etc/ld.so.conf.d/mysql.conf <<EOF
/usr/local/mysql/lib
/usr/local/lib
EOF
ldconfig
ln -sf /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -sf /usr/local/mysql/include/mysql /usr/include/mysql
MySQL_Sec_Setting
}
Install_MySQL_80() {
rm -f /etc/my.cnf
if [ "${Bin}" = "y" ]; then
echo "[+] Installing ${Mysql_Ver} Using Generic Binaries..."
TarJ_Cd ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz
mkdir /usr/local/mysql
mv ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}/* /usr/local/mysql/
else
echo "[+] Installing ${Mysql_Ver} Using Source code..."
Tar_Cd ${Mysql_Ver}.tar.gz ${Mysql_Ver}
if openssl version | grep -Eqi "OpenSSL 3.*"; then
echo "OpenSSL 3.x"
patch -p1 <${cur_dir}/src/patch/mysql-openssl3.patch
fi
Install_Boost
mkdir build && cd build
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/var/lib/mysql -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 ${MySQL_WITH_BOOST}
Make_Install
fi
Check_MySQL_Data_Dir
chown -R mysql:mysql /usr/local/mysql
cat >/etc/ld.so.conf.d/mysql.conf <<EOF
/usr/local/mysql/lib
/usr/local/lib
EOF
ldconfig
ln -sf /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -sf /usr/local/mysql/include/mysql /usr/include/mysql
MySQL_Sec_Setting
}
TempMycnf_Clean() {
if [ -s ~/.my.cnf ]; then
rm -f ~/.my.cnf
fi
if [ -s /tmp/.mysql.tmp ]; then
rm -f /tmp/.mysql.tmp
fi
rm -rf /usr/local/src/* /usr/local/mysql/bin/mysqltest_embedded /usr/local/mysql/bin/mysql_embedded /usr/local/mysql/bin/mysql_client_test_embedded /usr/local/mysql/mysql-test
}
Modify_Source()
{
if [ "${DISTRO}" = "RHEL" ]; then
RHEL_Modify_Source
elif [ "${DISTRO}" = "Ubuntu" ]; then
Ubuntu_Modify_Source
echo install wget curl
apt-get update
apt-get install -y --no-install-recommends ca-certificates wget curl
elif [ "${DISTRO}" = "CentOS" ]; then
CentOS6_Modify_Source
CentOS8_Modify_Source
fi
}
RHEL_Modify_Source()
{
Get_RHEL_Version
if [ "${RHELRepo}" = "local" ]; then
echo "DO NOT change RHEL repository, use the repository you set."
else
echo "RHEL ${RHEL_Ver} will use aliyun centos repository..."
if [ ! -s "/etc/yum.repos.d/Centos-${RHEL_Ver}.repo" ]; then
if command -v curl >/dev/null 2>&1; then
curl http://mirrors.aliyun.com/repo/Centos-${RHEL_Ver}.repo -o /etc/yum.repos.d/Centos-${RHEL_Ver}.repo
else
wget --prefer-family=IPv4 http://mirrors.aliyun.com/repo/Centos-${RHEL_Ver}.repo -O /etc/yum.repos.d/Centos-${RHEL_Ver}.repo
fi
fi
if echo "${RHEL_Version}" | grep -Eqi "^6"; then
sed -i "s#centos/\$releasever#centos-vault/\$releasever#g" /etc/yum.repos.d/Centos-${RHEL_Ver}.repo
sed -i "s/\$releasever/${RHEL_Version}/g" /etc/yum.repos.d/Centos-${RHEL_Ver}.repo
elif echo "${RHEL_Version}" | grep -Eqi "^7"; then
sed -i "s/\$releasever/7/g" /etc/yum.repos.d/Centos-${RHEL_Ver}.repo
elif echo "${RHEL_Version}" | grep -Eqi "^8"; then
sed -i "s#centos/\$releasever#centos-vault/8.5.2111#g" /etc/yum.repos.d/Centos-${RHEL_Ver}.repo
fi
yum clean all
yum makecache
fi
sed -i "s/^enabled[ ]*=[ ]*1/enabled=0/" /etc/yum/pluginconf.d/subscription-manager.conf
}
Ubuntu_Modify_Source()
{
country=''
if [ "${country}" = "CN" ]; then
OldReleasesURL='http://mirrors.aliyun.com/oldubuntu-releases/ubuntu/'
else
OldReleasesURL='http://old-releases.ubuntu.com/ubuntu/'
fi
CodeName=''
if grep -Eqi "10.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^10.10'; then
CodeName='maverick'
elif grep -Eqi "11.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^11.04'; then
CodeName='natty'
elif grep -Eqi "11.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^11.10'; then
CodeName='oneiric'
elif grep -Eqi "12.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^12.10'; then
CodeName='quantal'
elif grep -Eqi "13.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^13.04'; then
CodeName='raring'
elif grep -Eqi "13.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^13.10'; then
CodeName='saucy'
elif grep -Eqi "10.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^10.04'; then
CodeName='lucid'
elif grep -Eqi "14.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^14.10'; then
CodeName='utopic'
elif grep -Eqi "15.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^15.04'; then
CodeName='vivid'
elif grep -Eqi "12.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^12.04'; then
CodeName='precise'
elif grep -Eqi "15.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^15.10'; then
CodeName='wily'
elif grep -Eqi "16.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^16.10'; then
CodeName='yakkety'
elif grep -Eqi "14.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^14.04'; then
Ubuntu_Deadline trusty
elif grep -Eqi "17.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^17.04'; then
CodeName='zesty'
elif grep -Eqi "17.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^17.10'; then
CodeName='artful'
elif grep -Eqi "16.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^16.04'; then
Ubuntu_Deadline xenial
elif grep -Eqi "16.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^16.10'; then
CodeName='yakkety'
elif grep -Eqi "14.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^14.04'; then
Ubuntu_Deadline trusty
elif grep -Eqi "17.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^17.04'; then
CodeName='zesty'
elif grep -Eqi "17.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^17.10'; then
CodeName='artful'
elif grep -Eqi "16.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^16.04'; then
Ubuntu_Deadline xenial
elif grep -Eqi "16.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^16.10'; then
CodeName='yakkety'
elif grep -Eqi "18.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^18.10'; then
CodeName='cosmic'
elif grep -Eqi "19.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^19.04'; then
CodeName='disco'
elif grep -Eqi "19.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^19.10'; then
CodeName='eoan'
elif grep -Eqi "20.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^20.04'; then
CodeName='focal'
elif grep -Eqi "20.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^20.10'; then
CodeName='groovy'
elif grep -Eqi "21.04" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^21.04'; then
Ubuntu_Deadline hirsute
elif grep -Eqi "21.10" /etc/*-release || echo "${Ubuntu_Version}" | grep -Eqi '^21.10'; then
Ubuntu_Deadline impish
fi
echo ${OldReleasesURL} ${CodeName} ======================
if [ "${CodeName}" != "" ]; then
\cp /etc/apt/sources.list /etc/apt/sources.list.$(date +"%Y%m%d")
cat > /etc/apt/sources.list<<EOF
deb ${OldReleasesURL} ${CodeName} main restricted universe multiverse
deb ${OldReleasesURL} ${CodeName}-security main restricted universe multiverse
deb ${OldReleasesURL} ${CodeName}-updates main restricted universe multiverse
deb ${OldReleasesURL} ${CodeName}-proposed main restricted universe multiverse
deb ${OldReleasesURL} ${CodeName}-backports main restricted universe multiverse
deb-src ${OldReleasesURL} ${CodeName} main restricted universe multiverse
deb-src ${OldReleasesURL} ${CodeName}-security main restricted universe multiverse
deb-src ${OldReleasesURL} ${CodeName}-updates main restricted universe multiverse
deb-src ${OldReleasesURL} ${CodeName}-proposed main restricted universe multiverse
deb-src ${OldReleasesURL} ${CodeName}-backports main restricted universe multiverse
EOF
fi
}
Check_Old_Releases_URL()
{
OR_Status=`wget --spider --server-response ${OldReleasesURL}/dists/$1/Release 2>&1 | awk '/^ HTTP/{print $2}'`
if [ "${OR_Status}" = "200" ]; then
echo "Ubuntu old-releases status: ${OR_Status}";
CodeName="$1"
fi
}
Ubuntu_Deadline()
{
trusty_deadline=`date -d "2022-4-30 00:00:00" +%s`
xenial_deadline=`date -d "2024-4-30 00:00:00" +%s`
hirsute_deadline=`date -d "2022-1-30 00:00:00" +%s`
impish_deadline=`date -d "2022-7-30 00:00:00" +%s`
cur_time=`date +%s`
case "$1" in
trusty)
if [ ${cur_time} -gt ${trusty_deadline} ]; then
echo "${cur_time} > ${trusty_deadline}"
Check_Old_Releases_URL trusty
fi
;;
xenial)
if [ ${cur_time} -gt ${xenial_deadline} ]; then
echo "${cur_time} > ${xenial_deadline}"
Check_Old_Releases_URL xenial
fi
;;
eoan)
if [ ${cur_time} -gt ${eoan_deadline} ]; then
echo "${cur_time} > ${eoan_deadline}"
Check_Old_Releases_URL eoan
fi
;;
hirsute)
if [ ${cur_time} -gt ${hirsute_deadline} ]; then
echo "${cur_time} > ${hirsute_deadline}"
Check_Old_Releases_URL hirsute
fi
;;
impish)
if [ ${cur_time} -gt ${impish_deadline} ]; then
echo "${cur_time} > ${impish_deadline}"
Check_Old_Releases_URL impish
fi
;;
esac
}
CentOS6_Modify_Source()
{
if echo "${CentOS_Version}" | grep -Eqi "^6"; then
echo "CentOS 6 is now end of life, use vault repository."
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/
\cp ${cur_dir}/conf/CentOS6-Base-Vault.repo /etc/yum.repos.d/CentOS-Base.repo
fi
}
CentOS8_Modify_Source()
{
if echo "${CentOS_Version}" | grep -Eqi "^8" && [ "${isCentosStream}" != "y" ]; then
echo "CentOS 8 is now end of life, use vault repository."
if [ ! -s /etc/yum.repos.d/CentOS8-vault.repo ]; then
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/
\cp ${cur_dir}/conf/CentOS8-vault.repo /etc/yum.repos.d/CentOS8-vault.repo
fi
fi
}
Install_Database() {
echo "============================check files=================================="
cd ${cur_dir}/src
if [[ "${DBSelect}" =~ ^[12345]$ ]]; then
if [[ "${Bin}" == "y" && "${DBSelect}" == "4" ]]; then
Get_Country
if [ "${country}" = "CN" ]; then
Download_Files http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz
[[ $? -ne 0 ]] && Download_Files https://cdn.mysql.com/Downloads/MySQL-5.7/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz
else
Download_Files https://cdn.mysql.com/Downloads/MySQL-5.7/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz
fi
[[ $? -ne 0 ]] && Download_Files https://cdn.mysql.com/archives/mysql-5.7/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz
if [ ! -s ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.gz ]; then
Echo_Red "Error! Unable to download MySQL 5.7 Generic Binaries, please download it to src directory manually."
sleep 5
exit 1
fi
elif [[ "${Bin}" == "y" && "${DBSelect}" == "5" ]]; then
Get_Country
if [ "${country}" = "CN" ]; then
Download_Files http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-8.0/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz
[[ $? -ne 0 ]] && Download_Files https://cdn.mysql.com/Downloads/MySQL-8.0/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz
else
Download_Files https://cdn.mysql.com/Downloads/MySQL-8.0/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz
fi
[[ $? -ne 0 ]] && Download_Files https://cdn.mysql.com/archives/mysql-8.0/${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz
if [ ! -s ${Mysql_Ver}-linux-glibc2.12-${DB_ARCH}.tar.xz ]; then
Echo_Red "Error! Unable to download MySQL 8.0 Generic Binaries, please download it to src directory manually."
sleep 5
exit 1
fi
else
Download_Files ${Download_Mirror}/datebase/mysql/${Mysql_Ver}.tar.gz ${Mysql_Ver}.tar.gz
if [ ! -s ${Mysql_Ver}.tar.gz ]; then
Echo_Red "Error! Unable to download MySQL source code, please download it to src directory manually."
sleep 5
exit 1
fi
fi
elif [[ "${DBSelect}" =~ ^[6789]|10$ ]]; then
Download_Files ${Download_Mirror}/datebase/mariadb/${Mariadb_Ver}.tar.gz ${Mariadb_Ver}.tar.gz
if [ ! -s ${Mariadb_Ver}.tar.gz ]; then
Echo_Red "Error! Unable to download MariaDB source code, please download it to src directory manually."
sleep 5
exit 1
fi
fi
echo "============================check files=================================="
Echo_Blue "Install dependent packages..."
#DB_Dependent
Check_Openssl
if [ "${DBSelect}" = "1" ]; then
Install_MySQL_51
elif [ "${DBSelect}" = "2" ]; then
Install_MySQL_55
elif [ "${DBSelect}" = "3" ]; then
Install_MySQL_56
elif [ "${DBSelect}" = "4" ]; then
Install_MySQL_57
elif [ "${DBSelect}" = "5" ]; then
Install_MySQL_80
elif [ "${DBSelect}" = "6" ]; then
Install_MariaDB_5
elif [ "${DBSelect}" = "7" ]; then
Install_MariaDB_103
elif [ "${DBSelect}" = "8" ]; then
Install_MariaDB_104
elif [ "${DBSelect}" = "9" ]; then
Install_MariaDB_105
elif [ "${DBSelect}" = "10" ]; then
Install_MariaDB_106
fi
TempMycnf_Clean
}
Install_Only_Database() {
clear
echo "+-----------------------------------------------------------------------+"
echo "| Install MySQL/MariaDB database for LNMP, Written by Licess |"
echo "+-----------------------------------------------------------------------+"
echo "| A tool to install MySQL/MariaDB for LNMP |"
echo "+-----------------------------------------------------------------------+"
echo "| For more information please visit https://lnmp.org |"
echo "+-----------------------------------------------------------------------+"
Check_DB
if [ "${DB_Name}" != "None" ]; then
echo "You have install ${DB_Name}!"
exit 1
fi
DB_Info=('MySQL 5.1.73' 'MySQL 5.5.62' 'MySQL 5.6.51' 'MySQL 5.7.38' 'MySQL 8.0.30' 'MariaDB 5.5.68' 'MariaDB 10.3.35' 'MariaDB 10.4.25' 'MariaDB 10.5.16' 'MariaDB 10.6.8')
Database_Selection
if [ "${DBSelect}" = "0" ]; then
echo "DO NOT Install MySQL or MariaDB."
exit 1
fi
Echo_Red "The script will REMOVE MySQL/MariaDB installed via yum or apt-get and it's databases!!!"
Press_Install
Install_Database 2>&1 | tee /root/install_database.log
}
# Check if user is root
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install db"
exit 1
fi
mkdir -p /usr/local/src/src
cd /usr/local/src
cur_dir=$(pwd)
Download_Mirror='https://soft.vpser.net'
MySQL_Data_Dir='/var/lib/mysql'
Get_Dist_Name
Get_Dist_Version
#Modify_Source
#DB_Dependent
#Install_Only_Database
$1
$2