#!/bin/bash# 编译安装mysqlyum install cmake ncurses ncurses-devel gcc gcc-c++ cmake -ymkdir -p /tools /applicationcd /tools/wget http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.50.tar.gztar -xf mysql-5.5.50.tar.gzcd mysql-5.5.50cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.50 \-DDEFAULT_CHARSET=utf8 \-DDEFAULT_COLLATION=utf8_general_ci \-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \-DENABLED_LOCAL_INFILE=ON \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_FEDERATED_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \-DWITH_FAST_MUTEXES=1 \-DWITH_ZLIB=bundled \-DENABLED_LOCAL_INFILE=1 \-DWITH_READLINE=1 \-DWITH_EMBEDDED_SERVER=1 \-DWITH_DEBUG=0make && make install[ $? -eq 0 ] && ln -s /application/mysql-5.5.50 /application/mysql || { echo "Installation fail." exit 1}cd# 添加系统用户useradd -M -s /sbin/nologin mysql##################################################################### 设置监听的端口(多实例)for port in {3307..3312}do # 部署数据目录 mkdir -p /data/mysql_multi_instances/${port} #初始化数据库文件 /application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/data/mysql_multi_instances/${port} --user=mysql &>/dev/null [ $? -eq 0 ] && echo "DB ${port} install success" || { echo "DB ${port} install failed" continue } #配置文件my.cnf cat >/data/mysql_multi_instances/${port}/my.cnf</dev/null &[ $? -eq 0 ] && echo "Instances ${port} install success" || echo "Instances ${port} install failed"done
以下为安装后检查端口监听情况
[root@localhost ~]# netstat -tulnp|grep mysql
tcp 0 0 0.0.0.0:3307 0.0.0.0:* LISTEN 45946/mysqld
tcp 0 0 0.0.0.0:3308 0.0.0.0:* LISTEN 46385/mysqld
tcp 0 0 0.0.0.0:3309 0.0.0.0:* LISTEN 46730/mysqld
tcp 0 0 0.0.0.0:3310 0.0.0.0:* LISTEN 47046/mysqld
tcp 0 0 0.0.0.0:3311 0.0.0.0:* LISTEN 47479/mysqld
tcp 0 0 0.0.0.0:3312 0.0.0.0:* LISTEN 47787/mysqld
登录其中之一
[root@localhost ~]# mysql -uroot -h 127.0.0.1 -P3307Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.5.50-log Source distributionCopyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>