链接:https://pan.baidu.com/s/17jrULkD006tcW0hv9CIxBg
提取码:w3yr
复制这段内容后打开百度网盘手机App,操作更方便哦
#!/bin/bash
# 只要发生错误,就终止执行
set -o errexit
GREEN=$(tput setaf 2; tput bold)
YELLOW=$(tput setaf 3)
RED=$(tput setaf 1)
NORMAL="$(tput sgr0)"
function red()
{
echo -e "$RED$(date "+%Y-%m-%d %H:%M:%S") $1$NORMAL"
}
function green()
{
echo -e "$GREEN$(date "+%Y-%m-%d %H:%M:%S") $1$NORMAL"
}
function yellow()
{
echo -e "$YELLOW$(date "+%Y-%m-%d %H:%M:%S") $1$NORMAL"
}
function normal()
{
echo -e "$NORMAL$(date "+%Y-%m-%d %H:%M:%S") $1$NORMAL"
}
function ready(){
echo 'mysql安装开始........'
echo '开始依赖包...........'
yum -y install libaio-devel.x86_64 numactl tar unzip > /dev/null
echo '依赖安装完成...........'
mysql_zip=$( find / -name mysql.zip )
echo '解压mysql_zip'
unzip -o $mysql_zip
mysql_tar=$( find / -name mysql*.tar.gz )
echo '开始解压mysql的tar.gz..........'
tar -zxf $mysql_tar -C /usr/local/
echo '解压完成mysql的tar.gz..........'
}
function mysql_install(){
cd /usr/local
ln -sv mysql* mysql
groupadd mysql
useradd -r -g mysql mysql
mkdir /usr/local/mysql/data
chown -R mysql:mysql /usr/local/mysql*
mkdir -p /app/bak
mv /etc/my.cnf /etc/my.cnf.bak
my_cnf=$(find / -name my.cnf )
mv $my_cnf /etc
echo ' skip-grant-tables ' >> /etc/my.cnf
cp /usr/local/mysql/support-files/mysql.server /usr/local/mysql/bin/
cd /usr/local/mysql/bin
echo 'export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib ' >> /etc/profile
echo 'export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib ' >> /root/.bash_profile
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
echo '-------------------------'$password'-----------------------------------'
}
function mysql_config(){
source /root/.bash_profile
source /etc/profile
/usr/local/mysql/support-files/mysql.server restart
cd /usr/local/mysql/bin
./mysql -u root -e " update mysql.user set authentication_string=password('root') where user='root' "
/usr/local/mysql/support-files/mysql.server stop
sed -i 's/skip-grant-tables/ /' /etc/my.cnf
/usr/local/mysql/support-files/mysql.server restart
echo 'source /etc/profile'
source /etc/profile
}
function clean_exit(){
rm -rf ${mysql_tar%/*}
}
function main(){
red "[1/4] ready...."
ready
green "[2/4] mysql_install...."
mysql_install
green "[3/4] mysql_config...."
mysql_config
yellow "[4/4] clean_exit...."
clean_exit
normal "...."
}
main