MySQL5.5.5安装脚本

2020-07-31 11:57:20 浏览数 (1)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163

#!/bin/bash mysql_data_dir="/data/mysql" mysql_binlog_file="/data/mysql_binlog/mysql-bin" DownloadFileDir="$(pwd)" InstallLogFile="$(pwd)/install.log" tmp="n" fun_failed() { printf "%-59s" "$1" echo -e "[33[31mFAILED33[0m]" echo -e "33[31msee ./install.log for detail33[0m" exit 1 } fun_ok() { printf "%-59s" "$1" echo -e "[33[32m OK 33[0m]" } while [[ $# != 0 ]];do case $1 in -y) tmp="y" shift 1 ;; -d) mysql_data_dir=$2 shift 2 ;; -b) mysql_binlog_file=$2 shift 2 ;; -h) echo "usage: script that auto install mysqld srv" echo " -y :answer to any question which would be asked is yes" echo " -d <data dir> :set mysql data dir [default: $mysql_data_dir]" echo " -b <data dir> :set mysql bin log file [default: $mysql_binlog_file]" echo " NOT in /root,mysql don't have authority " exit ;; *) echo "wrong option" exit esac done echo "=========================" echo "datadir: $mysql_data_dir" echo "binlog: $mysql_binlog_file" if [[ $tmp = "n" ]];then read -p "Confirm set is right [y/n]: " tmp [[ $tmp != "y" ]] && exit 2 fi echo ss -tnpl | grep -q mysqld [[ $? -eq 0 ]] && fun_failed "mysqld process is running:" useradd -r mysql -s /sbin/nologin &>> $InstallLogFile [[ $? -ne 0 && $? -ne 9 ]] && fun_failed "useradd mysql:" # $? -eq 0 || $? -eq 9 通过,取反退出 fun_ok "useradd mysql:" yum -y install gcc gcc-c gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* make cmake curl freetype libjpeg-turbo libjpeg-turbo-devel openjpeg-libs libpng gd ncurses git bison openssl-devel libaio-devel &>> $InstallLogFile || fun_failed "install rpm:" fun_ok "install rpm:" #[[ -e mysql-5.5.55.tar.gz ]] && mv mysql-5.5.55.tar.gz mysql-5.5.55.tar.gz.bak-$(date %M) #wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.55.tar.gz -O mysql-5.5.55.tar.gz &>> $InstallLogFile || fun_failed "wget mysqld:" #wget https://andyblog.org/files/20170625-6810431146.gz -O mysql-5.5.55.tar.gz &>> $InstallLogFile || fun_failed "wget mysqld:" #fun_ok "wget mysqld:" [[ -e mysql-5.5.55 ]] && mv mysql-5.5.55 mysql-5.5.55.bak-$(date %M) tar xf mysql-5.5.55.tar.gz &>> $InstallLogFile || fun_failed "tar xf mysqld:" fun_ok "tar xf mysqld:" [[ -e /usr/local/mysql ]] && fun_failed "bin dir has exist:" mkdir -p /usr/local/mysql/run/lock mkdir -p /usr/local/mysql/conf mkdir -p /var/log/mysqld chown -R mysql /usr/local/mysql/run chown -R mysql /var/log/mysqld cd mysql-5.5.55 cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/run/mysql.sock -DMYSQL_DATADIR=$mysql_data_dir -DSYSCONFDIR=/usr/local/mysql/conf -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci &>> $InstallLogFile || fun_failed "configure mysqld:" fun_ok "configure mysqld:" CpuCount=$(cat /proc/cpuinfo| grep "processor"| wc -l) make -j $CpuCount &>> $InstallLogFile || fun_failed "make mysqld:" fun_ok "make mysqld:" make install &>> $InstallLogFile || fun_failed "make install mysqld:" fun_ok "make install mysqld:" cd /usr/local/mysql cp $DownloadFileDir/file/mysql.conf ./conf/my.cnf sed -i "s#^datadir.*#datadir = $mysql_data_dir#g" ./conf/my.cnf sed -i "s#^log-bin.*#log-bin=$mysql_binlog_file#g" ./conf/my.cnf /usr/local/mysql/bin/my_print_defaults --defaults-file=/usr/local/mysql/conf/my.cnf &>> $InstallLogFile [[ -e /etc/my.cnf ]] && mv /etc/my.cnf{,.bak} [[ -e $mysql_data_dir ]] && fun_failed "data dir has exist:" mkdir -p $(dirname $mysql_binlog_file) chown -R mysql $(dirname $mysql_binlog_file) /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --user=mysql --datadir=$mysql_data_dir &>> $InstallLogFile || fun_failed "init db file:" fun_ok "init db file:" cat > /etc/profile.d/mysql.sh << EOF PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH export PATH EOF source /etc/profile.d/mysql.sh cp $DownloadFileDir/file/mysql.init /etc/init.d/mysqld chmod x /etc/init.d/mysqld chkconfig --add mysqld chkconfig mysqld on cp $DownloadFileDir/file/mysql.logrotate /etc/logrotate.d/mysqld fun_ok "config mysqld:" service mysqld start &>> $InstallLogFile || fun_failed "start mysqld:" fun_ok "start mysqld:" sleep 1 ss -tnlp | grep mysqld &>> $InstallLogFile || fun_failed "listen port:" fun_ok "listen port:" cd $DownloadFileDir rm -rf mysql-5.5.55* &>> $InstallLogFile || fun_failed "rm download file:" fun_ok "rm download file:" echo -e "33[32mservice mysqld started 33[0m" echo echo "bindir: /usr/local/mysql" echo "service: /etc/init.d/mysqld" echo "datadir: $mysql_data_dir" echo "logdir: /var/log/mysqld" echo

0 人点赞