One time when I was helping my friends solve problems, their server's MySQL was multi-instance, on which I made a master-slave configuration. Before I used multiple instances, I used multiple configuration files. This article mainly describes how to start and close multiple instances in a configuration file.
Profile Content
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = root
password = 1qa2wswichina
[mysqld6]
socket = /data/mysql/3306/tmp/mysql.sock
port = 3306
pid-file = /data/mysql/3306/tmp/mysql.pid
datadir = /data/mysql/3306/data
tmpdir = /data/mysql/3306/tmp
server-id = 3306
log-bin = /data/mysql/3306/log/mysql-bin
log_error = /data/mysql/3306/log/mysql-error.log #Error log path
default-time-zone = '+8:00'
character-set-server=utf8
max_connections=5000
lower_case_table_names=0
skip-name-resolve
back_log = 600
open_files_limit = 999999
table_open_cache = 5000
max_allowed_packet = 20M
binlog_cache_size = 1M
max_heap_table_size = 1024M
tmp_table_size = 2048M
read_buffer_size = 10M
read_rnd_buffer_size = 32M
sort_buffer_size = 18M
join_buffer_size = 18M
thread_cache_size = 2048M
query_cache_size = 0
query_cache_type=0
query_cache_limit = 0M
key_buffer_size = 2048M
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30 #More than 30 days of binlog deletion
log_error = /data/mysql/3306/log/mysql-error.log #Error log path
slow_query_log = 1
long_query_time = 2 #Slow queries over a second are slow queries
slow_query_log_file = /data/mysql/3306/log/mysql-slow.log
performance_schema = 0
lower_case_table_names=0
skip-external-locking #MySQL option to avoid external locking.This option is turned on by default
default-storage-engine = InnoDB #Default Storage Engine
innodb_file_per_table = 1
innodb_buffer_pool_size = 40960M
innodb_force_recovery=0
innodb_write_io_threads = 12
innodb_read_io_threads = 12
innodb_thread_concurrency = 0
innodb_commit_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_table_locks = 0
innodb_log_buffer_size = 8M
innodb_log_file_size = 1024M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 10G
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 512M
myisam_repair_threads = 1
interactive_timeout = 7200
wait_timeout = 7200
[mysqld7]
socket = /data/mysql/3307/tmp/mysql.sock
port = 3307
pid-file = /data/mysql/3307/tmp/mysql.pid
datadir = /data/mysql/3307/data
tmpdir = /data/mysql/3307/tmp
server-id = 3307
log-bin = /data/mysql/3307/log/mysql-bin
log_error = /data/mysql/3307/log/mysql-error.log #Error log path
default-time-zone = '+8:00'
character-set-server=utf8
max_connections=5000
lower_case_table_names=0
skip-name-resolve
back_log = 600
open_files_limit = 100001
table_open_cache = 5000
max_allowed_packet = 20M
binlog_cache_size = 1M
max_heap_table_size = 1024M
tmp_table_size = 1024M
read_buffer_size = 10M
read_rnd_buffer_size = 32M
sort_buffer_size = 18M
join_buffer_size = 18M
thread_cache_size = 2048M
query_cache_size = 0
query_cache_type=0
query_cache_limit = 20M
key_buffer_size = 2048M
#log_bin = mysql-bin
##binlog_format = mixed
expire_logs_days = 30 #More than 30 days of binlog deletion
slow_query_log = 1
long_query_time = 2 #Slow queries over a second are slow queries
slow_query_log_file = /data/mysql/3307/log/mysql-slow.log
performance_schema = 0
lower_case_table_names=0
skip-external-locking #MySQL option to avoid external locking.This option is turned on by default
default-storage-engine = InnoDB #Default Storage Engine
innodb_file_per_table = 1
innodb_buffer_pool_size = 40960M
innodb_force_recovery=0
innodb_write_io_threads = 12
innodb_read_io_threads = 12
innodb_thread_concurrency = 0
innodb_commit_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_table_locks = 0
innodb_log_buffer_size = 8M
innodb_log_file_size = 1024M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 10G
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 512M
myisam_repair_threads = 1
interactive_timeout = 7200
wait_timeout = 7200
[mysqld8]
socket = /data/mysql/3308/tmp/mysql.sock
port = 3308
pid-file = /data/mysql/3308/tmp/mysql.pid
datadir = /data/mysql/3308/data
tmpdir = /data/mysql/3308/tmp
server-id = 3308
log-bin = /data/mysql/3308/log/mysql-bin
log_error = /data/mysql/3308/log/mysql-error.log #Error log path
default-time-zone = '+8:00'
character-set-server=utf8
max_connections=5000
lower_case_table_names=0
skip-name-resolve
back_log = 600
open_files_limit = 100001
table_open_cache = 5000
max_allowed_packet = 20M
binlog_cache_size = 1M
max_heap_table_size = 1024M
tmp_table_size = 1024M
read_buffer_size = 10M
read_rnd_buffer_size = 32M
sort_buffer_size = 18M
join_buffer_size = 18M
thread_cache_size = 2048M
query_cache_size = 0
query_cache_type=0
query_cache_limit = 20M
key_buffer_size = 2048M
#log_bin = mysql-bin
##binlog_format = mixed
expire_logs_days = 30 #More than 30 days of binlog deletion
slow_query_log = 1
long_query_time = 2 #Slow queries over a second are slow queries
slow_query_log_file = /data/mysql/3308/log/mysql-slow.log
performance_schema = 0
lower_case_table_names=0
skip-external-locking #MySQL option to avoid external locking.This option is turned on by default
default-storage-engine = InnoDB #Default Storage Engine
innodb_file_per_table = 1
innodb_buffer_pool_size = 40960M
innodb_force_recovery=0
innodb_write_io_threads = 12
innodb_read_io_threads = 12
innodb_thread_concurrency = 0
innodb_commit_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_table_locks = 0
innodb_log_buffer_size = 8M
innodb_log_file_size = 1024M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 10G
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 512M
myisam_repair_threads = 1
interactive_timeout = 7200
wait_timeout = 7200
[mysqldump]
#quick
max_allowed_packet = 128M #Maximum Packet Length Sent and Accepted by Server
[myisamchk]
#key_buffer_size = 8M
#sort_buffer_size = 8M
#read_buffer = 4M
#write_buffer = 4M
[mysql]
no-auto-rehash
default-character-set=utf8
Profile description
Profile path: /etc/my.cnf
There are three different configurations under the three tags [mysqld6] [mysqld7] [mysqld8], where [mysqld6] is master, binary logs are turned on, and two are slave s.
Multiple Instances Start, Close, and State
#Multi-Instance Startup
mysqld_multi --defaults-extra-file=/etc/my.cnf start 2,3,4
#Multi-Instance State Judgment
mysqld_multi --defaults-extra-file=/etc/my.cnf report
#Multi-Instance Shutdown
mysqld_multi --defaults-extra-file=/etc/my.cnf stop 2,3,4