安装多实例之前首先需要先安装mysql,这里就不介绍如何安装mysql了,参考前面的博客:https://www.cnblogs.com/hei-ma/p/9505509.html
安装多实例之前需要将之前安装好的mysql停掉。
# /etc/init.d/mysqld stop
开始正式安装mysql-5.7.19多实例
1、创建多实例目录
# mkdir -p /data/mysql{,}/data
2、编辑多实例配置文件
3308端口的需要将3307修改为3308,server-id也需要改
# cat /data/mysql3307/my.cnf
[client]
port =
socket = /data/mysql3307/mysql.sock [mysql]
no-auto-rehash [mysqld]
secure_file_priv =
user = mysql
port =
socket = /data/mysql3307/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysql3307/data
open_files_limit =
back_log =
max_connections =
max_connect_errors =
table_open_cache =
external-locking = FALSE
max_allowed_packet =8M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size =
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
pid-file = /data/mysql3307/mysql.pid
log-bin = /data/mysql/mysql-bin
relay-log = /data/mysql3307/relay-bin
relay-log-info-file = /data/mysql3307/relay-log.info
binlog_cache_size = 1M
max_binlog_cache_size = 1M
max_binlog_size = 2M
expire_logs_days =
key_buffer_size = 16M
read_buffer_size = 1M
read_rnd_buffer_size = 1M
bulk_insert_buffer_size = 1M
lower_case_table_names =
skip-name-resolve
slave-skip-errors = ,
replicate-ignore-db=mysql
server-id =
innodb_buffer_pool_size = 32M
innodb_data_file_path = ibdata1:128M:autoextend
innodb_thread_concurrency =
innodb_flush_log_at_trx_commit =
innodb_log_buffer_size = 2M
innodb_log_file_size = 4M
innodb_log_files_in_group =
innodb_max_dirty_pages_pct =
innodb_lock_wait_timeout =
innodb_file_per_table =
[mysqldump]
quick
max_allowed_packet = 2M [mysqld_safe]
log-error=/data/mysql3307/mysql_3307.err
pid-file=/data/mysql3307/mysqld.pid
3、创建用户并授权
# useradd -s /sbin/nologin -M mysql
# chown -R mysql.mysql /data/mysql330*
4、初始化
# cd /mysql-path/bin #进入到你的mysql安装路径
# ./mysqld --defaults-file=/data/mysql3307/my.cnf --basedir=/usr/local/mysql --user=mysql --initialize-insecure --explicit_defaults_for_timestamp
# echo $? #确认初始化是否成功,返回0则成功
5、启动多实例
# cd /mysql-path/bin #mysql的安装路径
# ./mysqld_safe --defaults-file=/data/mysql3307/my.cnf & #启动mysql
6、确认进程
# ps -ef|grep /data/mysql3307 #查看进程
root : pts/ :: /bin/sh ./mysqld_safe --defaults-file=/data/mysql3307/my.cnf
mysql : pts/ :: /usr/local/mysql/bin/mysqld --defaults-file=/data/mysql3307/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql3307/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql3307/mysql_3307.err --open-files-limit= --pid-file=/data/mysql3307/mysqld.pid --socket=/data/mysql3307/mysql.sock --port=
root : pts/ :: grep --color=auto /data/mysql3307
# netstat -lnutp|grep #查看端口
tcp6 ::: :::* LISTEN /mysqld
至此3307的多实例就配置完成了!!
3308的配置和3307一样,但是需要修改配置文件