1. 程式人生 > >Mysql 5.6,5.7 基於shell 的一鍵安裝

Mysql 5.6,5.7 基於shell 的一鍵安裝

 

參考文件:https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html 、https://dev.mysql.com/doc/refman/5.6/en/binary-installation.html

環境要求:

src_dir=/usr/local/src/$version  // mysql二進位制壓縮包目錄
 1 #!/bin/bash
 2 echo "********add group,user **************"
 3 if id -g mysql > /dev/null 2>&1;then
 4         echo
"mysql group is exits;" 5 else 6 groupadd mysql >/dev/null 2>&1 && echo "creating mysqlgroup success;" 7 fi 8 9 if id -u mysql > /dev/null 2>&1;then 10 echo "mysql user is exits;" 11 else 12 useradd -r -g mysql -s /bin/false mysql > /dev/null 2>&1
&& echo "creating mysqluser success;" 13 fi 14 15 rpm -qa libaio || yum install libaio -y > /dev/null 2>&1 16 read -p "enter mysql version eg:5.7 :" version 17 datadir=/data/mysql/mysql_$version 18 src_dir=/usr/local/src/$version 19 ins_dir=/usr/local/ 20 [ -d $datadir ] || mkdir -p $datadir
21 cd $src_dir 22 tar -xf $(ls mysql-*) -C $ins_dir 23 cd $ins_dir 24 ln -s $ins_dir/$(ls |grep mysql-$version*) /usr/local/mysql$version 25 echo "export PATH=$PATH:/usr/local/mysql$version/bin" >> /etc/profile 26 27 cat << EOF >/etc/my.cnf 28 [mysqld] 29 port = 3306 30 user = mysql 31 datadir = $datadir 32 log_error = error.log 33 [mysql] 34 prompt = (\[email protected]\h) [\d]>\_ 35 EOF 36 37 case $version in 38 "5.7") 39 cd /usr/local/mysql$version 40 mkdir mysql-files 41 chmod 755 mysql-files 42 chown mysql.mysql mysql-files 43 bin/mysqld --initialize --user=mysql 44 [ $? -eq 0 ] && echo " installing mysql-server success" 45 chown -R mysql.mysql /usr/local/mysql$version 46 cp support-files/mysql.server /etc/init.d/mysql.server 47 bin/mysqld_safe --user=mysql & > /dev/null 2>&1 48 pass=grep "temporary password" $datadir/error.log |awk -F " " '{print $11}' 49 mysql -uroot -p$pass -e "set password = '123'" > /dev/null 2&>1 50 ;; 51 "5.6") 52 cd /usr/local/mysql$version 53 scripts/mysql_install_db --user=mysql >/dev/null 54 bin/mysqld_safe --user=mysql & > /dev/null 2&>1 55 cp support-files/mysql.server /etc/init.d/mysql.server 56 ;; 57 esac