码迷,mamicode.com
首页 > 数据库 > 详细

MySQL 5.6 多实例部署

时间:2018-08-23 00:29:53      阅读:185      评论:0      收藏:0      [点我收藏+]

标签:配置   tar   mit   defaults   int   server   ica   safe   func   

1.安装MySQL

# useradd -s /sbin/nologin -M mysql

# tar -xvf mysql-5.6.41-linux-glibc2.12-x86_64.tar.gz -C /usr/local

# mv mysql-5.6.41-linux-glibc2.12-x86_64  mysql

# chown -R mysql:mysql  /usr/local/mysql

 

2.配置多实例配置文件目录

# mkdir /data/{3306,3307}/data

# chown -R mysql:mysql /data

3.MySQL多实例3306配置文件

# vim /data/3306/my.cnf

[client]
port = 3306
socket = /data/3306/mysql.sock

[mysqld]
port = 3306
socket = /data/3306/mysql.sock
datadir = /data/3306/data
open_files_limit = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_open_cache = 512
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
thread_stack = 192K
tmp_table_size = 2M
max_heap_table_size = 2M
long_query_time = 1
pid-file = /data/3306/mysql.pid
log-bin = /data/3306/mysql-bin
relay-log = /data/3306/relay-bin
relay-log-info-file = /data/3306/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db=mysql
server-id = 3306

4.MySQL多实例3307配置文件

# vim /data/3306/my.cnf

[client]
port = 3307
socket = /data/3307/mysql.sock

[mysqld]
port = 3306
socket = /data/3307/mysql.sock
datadir = /data/3307/data
open_files_limit = 1024
back_log = 600
max_connections = 800
max_connect_errors = 3000
table_open_cache = 512
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 100
thread_concurrency = 2
query_cache_size = 2M
query_cache_limit = 1M
query_cache_min_res_unit = 2k
thread_stack = 192K
tmp_table_size = 2M
max_heap_table_size = 2M
long_query_time = 1
pid-file = /data/3307/mysql.pid
log-bin = /data/3307/mysql-bin
relay-log = /data/3307/relay-bin
relay-log-info-file = /data/3307/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days = 7
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
lower_case_table_names = 1
skip-name-resolve
slave-skip-errors = 1032,1062
replicate-ignore-db=mysql
server-id = 3307

5.初始化多实例数据库

# /usr/local/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/data/3306/data/ --user=mysql

# /usr/local/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/data/3307/data/ --user=mysql

6.MySQL多实例启动

# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf 2>&1 > /dev/null &

# /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf 2>&1 > /dev/null &

7.MySQL多实例设置密码

# /usr/local/mysql/bin/mysqladmin -uroot password 123456 -S /data/3306/mysql.sock

# /usr/local/mysql/bin/mysqladmin -uroot password 123456 -S /data/3307/mysql.sock

8.测试MySQL多实例设置密码

# mysql -uroot -p123456 -S /data/3306/mysql.sock
# mysql -uroot -p123456 -S /data/3307/mysql.sock

9.查看MySQL多实例监听端口

# netstat -lntup|grep 330
tcp 0 0 :::3306 :::* LISTEN 3848/mysqld
tcp 0 0 :::3307 :::* LISTEN 4885/mysqld

10.MySQL多实例启动命令脚本

# vim /etc/init.d/mysqld_multi

#!/bin/sh

port=$3
mysql_user="root"
mysql_pwd="123456"
CmdPath="/usr/local/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 &
else
printf "MySQL is running...\n"
exit
fi
}

#stop function
function_stop_mysql()
{
if [ ! -e "$mysql_sock" ];then
printf "MySQL is stopped...\n"
exit
else
printf "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
sleep 2
function_start_mysql
}

case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage: /etc/init.d/mysql_multi {start|stop|restart} {3306|3307}\n"
esac

MySQL 5.6 多实例部署

标签:配置   tar   mit   defaults   int   server   ica   safe   func   

原文地址:https://www.cnblogs.com/deploy/p/9520896.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!