[root@mysql ~]# yum install ncurses-devel libaio-devel -y
[root@mysql cmake-3.6.1]# tar -xf cmake-3.6.1.tar.gz
[root@mysql cmake-3.6.1]# cd cmake-3.6.1
[root@mysql cmake-3.6.1]# gmake
[root@mysql cmake-3.6.1]# gmake install
[root@mysql cmake-3.6.1]# which cmake
/usr/local/bin/cmake
[root@mysql tools]# cd mysql-5.5.49
[root@mysql mysql-5.5.49]# useradd -s /sbin/nologin -M mysql
[root@mysql mysql-5.5.49]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)
[root@mysql mysql-5.5.49]# ./configure
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.5.49 \
-DMYSQL_DATADIR=/application/mysql-5.5.49/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.5.49/tmp/mysql.sock \
-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=0
[root@mysql mysql-5.5.49]# make
[root@mysql mysql-5.5.49]# make install
[root@mysql /]# ln -s /application/mysql-5.5.49/ /application/mysql
root@mysql mysql-5.5.49]# mkdir -p /data/{3306,3307}/data
为了配置多实例需要,需要每个实例建立一个my.cnf配置文件和一个启动文件mysql
配置my.cnf
[root@mysql mysql-5.5.49]# cp support-files/my-small.cnf /data/3306/my.cnf
[root@mysql mysql-5.5.49]# cp support-files/my-small.cnf /data/3307/my.cnf
[root@mysql 3307]# cat my.cnf
[client]
port= 3307socket= /data/3307/mysql.sock
[mysqld]
port= 3307socket= /data/3307/mysql.sock
basedir= /application/mysql
datadir= /data/3307/data
skip-external-locking
key_buffer_size=16M
max_allowed_packet=1M
table_open_cache= 64sort_buffer_size=512K
net_buffer_length=8K
read_buffer_size=256K
read_rnd_buffer_size=512K
myisam_sort_buffer_size=8M
skip-name-resolve
log-bin=mysql-bin
binlog_format=mixed
max_binlog_size=500M
server-id = 1[mysqld_safe]
log-error=/data/3307/ilanni.err
pid-file=/data/3307/ilanni.pid
[mysqldump]
quick
max_allowed_packet=16M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size=20M
sort_buffer_size=20M
read_buffer=2M
write_buffer=2M
[mysqlhotcopy]
interactive-timeout
#初始化mysql多实例
[root@mysql 3306]#/application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/data/3306/data --user=mysql
[root@mysql3307]#/application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/data/3307/data --user=mysql
[root@mysql3307]# tree /data
[root@mysql3307]# chown -R mysql:mysql /data/3306[root@mysql3307]# chown -R mysql:mysql /data/3307
#配置环境变量
[root@mysql 3307]# echo 'export PATH=/application/mysql/bin:$PATH' >> /etc/profile
[root@mysql3307]# source /etc/profile
[root@mysql3307]# echo $PATH/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
#启动实例
[root@mysql 3307]# /application/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf &[root@mysql3307]# /application/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf &[root@mysql3307]# ps -ef | egrep "3306|3307"root39045 1323 0 08:44 pts/0 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf
mysql39358 39045 0 08:44 pts/0 00:00:00 /application/mysql-5.5.49/bin/mysqld --defaults-file=/data/3306/my.cnf --basedir=/application/mysql --datadir=/data/3306/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/data/3306/ilanni.err --pid-file=/data/3306/ilanni.pid --socket=/data/3306/mysql.sock --port=3306root39383 1323 0 08:46 pts/0 00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf
mysql39694 39383 1 08:46 pts/0 00:00:00 /application/mysql-5.5.49/bin/mysqld --defaults-file=/data/3307/my.cnf --basedir=/application/mysql --datadir=/data/3307/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/data/3307/ilanni.err --pid-file=/data/3307/ilanni.pid --socket=/data/3307/mysql.sock --port=3307
#关闭实例
[root@mysql 3307]# mysqladmin -uroot -S /data/3306/mysql.sock shutdown
[root@mysql3307]# mysqladmin -uroot -S /data/3307/mysql.sock shutdown
#配置MySQL多实例开机自动启动
[root@mysql3306]# echo "#mysql multi instances" >> /etc/rc.local
[root@mysql3306]# echo "/data/3306/mysql start" >> /etc/rc.local
[root@mysql3306]# echo "/data/3307/mysql start" >> /etc/rc.local
[root@mysql3306]# tail -3 /etc/rc.local
#mysql multi instances/data/3306/mysql start/data/3307/mysql start
#编写MySQL启动脚本/data/${port}/mysql {start|stop|restart}
[root@mysql 3307]# pwd
/data/3307
[root@mysql 3307]# cat mysql
#!/bin/sh
#init
port=3307mysql_user="root"mysql_pwd="redhat"CmdPath="/application/mysql/bin"mysql_sock="/data/${port}/mysql.sock"#startup function
function_start_mysql()
{if [ ! -e "$mysql_sock"];then
printf"Starting MySQL...\n"
/bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &
elseprintf"MySQL is running...\n"exit
fi
}
#stop function
function_stop_mysql()
{if [ ! -e "$mysql_sock"];then
printf"MySQL is stopped...\n"exitelseprintf"Stoping MySQL...\n"${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdown
fi
}
#restart function
function_restart_mysql()
{
printf"Restarting MySQL...\n"function_stop_mysql
sleep2function_start_mysql
}case $1 instart)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;*)
printf"Usage: /data/${port}/mysql {start|stop|restart}\n"esac