mysql 5.72 安装_mysql 5.7安装脚本

1 [root@HE2 ~]# cat mysql_auto_install.sh

2 ###### 二进制自动安装数据库脚本root密码MANAGER将脚本和安装包放在/root目录即可###############3 ######数据库目录/usr/local/mysql############4 ######数据目录/data/mysql############5 ######慢日志目录/data/slowlog############6 ######端口号默认3306其余参数按需自行修改############7

8 ##################9 #author10 ##################11 #!/bin/bash12

13

14 # Check ifuser is root15 if [ $(id -u) != "0" ]; then

16 echo "Error: You must be root to run this script, please use root to install"

17 exit 1

18 fi

19

20 clear

21 echo "========================================================================="

22 echo "A tool to auto-compile & install MySQL 5.7.15 on Redhat/CentOS Linux"

23 echo "========================================================================="

24 cur_dir=$(pwd)25

26 #set mysql root password27 echo "==========================="

28

29 mysqlrootpwd="MANAGER"

30 echo -e "Please input the root password of mysql:"

31 read -p "(Default password: MANAGER):"mysqlrootpwd32 if [ "$mysqlrootpwd" = "" ]; then

33 mysqlrootpwd="MANAGER"

34 fi

35 echo "==========================="

36 echo "MySQL root password:$mysqlrootpwd"

37 echo "==========================="

38

39 #which MySQL Version do you want to install?

40 echo "==========================="

41

42

43 isinstallmysql57="n"

44 echo "Install MySQL 5.7.15,Please input y"

45 read -p "(Please input y , n):"isinstallmysql5746

47

48 case "$isinstallmysql57" in

49 y|Y|Yes|YES|yes|yES|yEs|YeS|yeS)50 echo "You will install MySQL 5.7.15"

51

52 isinstallmysql57="y"

53 ;;54 *)55 echo "INPUT error,You will exit install MySQL 5.7.15"

56

57 isinstallmysql57="n"

58 exit59 esac

60

61 get_char()62 {63 SAVEDSTTY=`stty -g`64 stty -echo

65 stty cbreak66 #dd if=/dev/tty bs=1 count=1 2> /dev/null

67 stty -raw68 stty echo

69 stty $SAVEDSTTY70 }71 echo ""

72 echo "Press any key to start...or Press Ctrl+c to cancel"

73 char=`get_char`74

75 # Initialize the installation related content.76 functionInitInstall()77 {78 cat /etc/issue79 uname -a80 MemTotal=`free -m | grep Mem | awk '{print $2}'`81 echo -e "\n Memory is: ${MemTotal} MB"

82 #Set timezone83 #rm -rf /etc/localtime84 #ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime85

86

87 #Delete Old Mysql program88 rpm -qa|grepmysql89 rpm -e mysql90

91

92

93

94

95

96 #Disable SeLinux97 if [ -s /etc/selinux/config ]; then

98 sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config99 fi

100 setenforce 0

101

102

103 }104

105

106 #Installation of depend on and optimization options.107 functionInstallDependsAndOpt()108 {109 cd $cur_dir110

111 cat >>/etc/security/limits.conf<

113 * hard nproc 65535

114 * soft nofile 65535

115 * hard nofile 65535

116 EOF117

118 echo "fs.file-max=65535" >> /etc/sysctl.conf119 }120

121 #Install MySQL122 functionInstallMySQL57()123 {124 echo "============================Install MySQL 5.7.15=================================="

125 cd $cur_dir126

127 #Backup old my.cnf128 #rm -f /etc/my.cnf129 if [ -s /etc/my.cnf ]; then

130 mv /etc/my.cnf /etc/my.cnf.`date +%Y%m%d%H%M%S`.bak131 fi

132

133 echo "============================MySQL 5.7.15 installing…………========================="

134 #mysql directory configuration135 tar xvf /root/mysql-5.7.15-linux-glibc2.5-x86_64.tar.gz136 mv /root/mysql-5.7.15-linux-glibc2.5-x86_64 /usr/local/mysql137 groupadd mysql -g 512

138 useradd -u 512 -g mysql -s /sbin/nologin -d /home/mysql mysql139 mkdir -p /data/mysql140 mkdir -p /data/slowlog141 chown -R mysql:mysql /data/mysql142 chown -R mysql:mysql /usr/local/mysql143 chown -R mysql:mysql /data/slowlog144

145

146 #edit /etc/my.cnf147 SERVERID=`ifconfig eth0 | grep "inet addr" | awk '{ print $2}'| awk -F. '{ print $3$4}'`148 cat >>/etc/my.cnf<

151 socket=/tmp/mysql.sock152 default-character-set=utf8153

154 [mysql]155 no-auto-rehash156 default-character-set=utf8157

158 [mysqld]159 port=3306

160 character-set-server=utf8161 socket=/tmp/mysql.sock162 basedir=/usr/local/mysql163 datadir=/data/mysql164 explicit_defaults_for_timestamp=true

165 lower_case_table_names=1

166 back_log=103

167 max_connections=3000

168 max_connect_errors=100000

169 table_open_cache=512

170 external-locking=FALSE171 max_allowed_packet=32M172 sort_buffer_size=2M173 join_buffer_size=2M174 thread_cache_size=51

175 query_cache_size=32M176 #query_cache_limit=4M177 transaction_isolation=REPEATABLE-READ178 tmp_table_size=96M179 max_heap_table_size=96M180

181 ###***slowqueryparameters182 long_query_time=1

183 slow_query_log = 1

184 slow_query_log_file=/data/slowlog/slow.log185

186 ###***binlogparameters187 log-bin=mysql-bin188 binlog_cache_size=4M189 max_binlog_cache_size=4096M190 max_binlog_size=1024M191 binlog_format=MIXED192 expire_logs_days=7

193

194 ###***relay-logparameters195 #relay-log=/data/3307/relay-bin196 #relay-log-info-file=/data/3307/relay-log.info

197 #master-info-repository=table198 #relay-log-info-repository=table199 #relay-log-recovery=1

200

201 #***MyISAMparameters202 key_buffer_size=16M203 read_buffer_size=1M204 read_rnd_buffer_size=16M205 bulk_insert_buffer_size=1M206

207 #skip-name-resolve208

209 ###***master-slavereplicationparameters210 server-id=$SERVERID211 #slave-skip-errors=all212

213 #***Innodbstorageengineparameters214 innodb_buffer_pool_size=512M215 innodb_data_file_path=ibdata1:10M:autoextend216 #innodb_file_io_threads=8

217 innodb_thread_concurrency=16

218 innodb_flush_log_at_trx_commit=1

219 innodb_log_buffer_size=16M220 innodb_log_file_size=512M221 innodb_log_files_in_group=2

222 innodb_max_dirty_pages_pct=75

223 innodb_buffer_pool_dump_pct=50

224 innodb_lock_wait_timeout=50

225 innodb_file_per_table=on226

227 [mysqldump]228 quick229 max_allowed_packet=32M230

231 [myisamchk]232 key_buffer=16M233 sort_buffer_size=16M234 read_buffer=8M235 write_buffer=8M236

237 [mysqld_safe]238 open-files-limit=8192

239 log-error=/data/mysql/error.log240 pid-file=/data/mysql/mysqld.pid241

242 EOF243

244

245

246

247 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql --initialize-insecure248

249 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld250 chmod 700 /etc/init.d/mysqld251 chkconfig --add mysqld252 chkconfig --level 2345mysqld on253

254 cat >> /etc/ld.so.conf.d/mysql-x86_64.conf<

259 if [ -d "/proc/vz" ];then

260 ulimit -s unlimited261 fi

262

263 /etc/init.d/mysqld start264

265

266 cat >> /etc/profile <

271 /usr/local/mysql/bin/mysqladmin -u root password $mysqlrootpwd272

273 cat > /tmp/mysql_sec_script<

280 /usr/local/mysql/bin/mysql -u root -p$mysqlrootpwd -h localhost < /tmp/mysql_sec_script281

282 #rm -f /tmp/mysql_sec_script283

284

285 #/etc/init.d/mysqld restart286

287

288

289

290 echo "============================MySQL 5.7.15 install completed========================="

291 }292

293

294

295 functionCheckInstall()296 {297 echo "===================================== Check install ==================================="

298 clear

299 ismysql=""

300 echo "Checking..."

301

302 if [ -s /usr/local/mysql/bin/mysql ] && [ -s /usr/local/mysql/bin/mysqld_safe ] && [ -s /etc/my.cnf ]; then

303 echo "MySQL: OK"

304 ismysql="ok"

305 else

306 echo "Error: /usr/local/mysql not found!!!MySQL install failed."

307 fi

308

309 if [ "$ismysql" = "ok" ]; then

310 echo "Install MySQL 5.7.15 completed! enjoy it."

311 echo "========================================================================="

312 netstat -ntl313 else

314 echo "Sorry,Failed to install MySQL!"

315 echo "You can tail /root/mysql-install.log from your server."

316 fi

317 }318

319 #The installation log320 InitInstall 2>&1 | tee /root/mysql-install.log321 InstallDependsAndOpt 2>&1 | tee -a /root/mysql-install.log322 InstallMySQL57 > /dev/null

323 CheckInstall 2>&1 | tee -a /root/mysql-install.log

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值