shell mysql5.6安装

时间:2023-02-23 15:56:57


#/bin/bash
# mysql install for linux
# copy to linux

# if /usr/local/mysql exists

if [ -e /usr/local/mysql ]
then
#mv /usr/local/mysql mysql.bak
rm -rf mysql*
fi

if [ -f $HOME/mysql*tar.gz ]
then
cp $HOME/mysql*tar.gz /usr/local
cd /usr/local
tar -xvf mysql*tar.gz
mv /usr/local/mysql-5.6.23-linux-glibc2.5-x86_64/ mysql
else
echo "the mysql install package is not exists"
fi

# create mysql user
testuser=mysql
if grep $testuser /etc/passwd
then
echo "you are $testuser!!"
userdel -r mysql
# rm -rf /home/mysql
else
useradd -r -g dba mysql
chown -R mysql:dba /usr/local/mysql/
mysqlpath='export PATH=/usr/local/mysql/bin:$PATH'
echo $mysqlpath >> /root/.bash_profile
# . ./.bash_profile
# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
echo "user mysql is created !"
fi

if [ -d /usr/local/mysql ]
then
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
echo "mysql install successful"
else
echo "mysql install filed"
fi

if [ -f /etc/my.cnf ]
then
echo "my.cnf exists!"
rm -f /etc/my.cnf
cp /usr/local/mysql/my.cnf /etc/my.cnf
addtest='basedir = /usr/local/mysql\n
datadir = /usr/local/mysql/data\n
port = 3306\n
server_id = 1\n
log-bin=mysql-bin'
echo -e $addtest >> /etc/my.cnf

else
echo "my.conf file is configure filed!"
fi

if [ -f /usr/local/mysql/support-files/mysql.server ]
then
rm -f /etc/init.d/mysql/mysql.server
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
else
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

fi

if [ -f /usr/local/mysql/support-files/mysql.server ]
then
service mysql restart
echo "mysql start successful"
else
echo "mysql start failed"
fi