系统共用,实例之间具有不同的datadir、server_id、port、日志文件、socket文件

innodb_buffer_pool_size分配的总量要小于物理内存的80%

1、创建数据目录

mkdir -p /data/mysql/mysql3307/{data,logs}

2、配置文件整理

vi /data/mysql/mysql3307/my3307.cnf
[client]
#password       = your_password
port            = 3307
socket          = /data/mysql/mysql3307/mysql.sock
default-character-set=utf8

[mysqld]
collation-server = utf8_general_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
binlog_cache_size=20M
thread_stack = 512K
join_buffer_size=2M
query_cache_type = 1
max_heap_table_size = 2048M
port=3307
socket=/data/mysql/mysql3307/mysql.sock
user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql/mysql3307/data
default_storage_engine = InnoDB
performance_schema_max_table_instances = 400
table_definition_cache = 400
key_buffer_size = 1024M
max_allowed_packet=100G
table_open_cache = 4096
sort_buffer_size=4M
net_buffer_length = 4K
read_buffer_size = 4096K
read_rnd_buffer_size = 2048K
myisam_sort_buffer_size = 128M
thread_cache_size = 512
query_cache_size = 384M
tmp_table_size = 2048M
max_connections=1024
max_connect_errors = 100
open_files_limit = 65535
log-bin=mysql-bin
binlog_format=mixed
server_id=2
expire_logs_days=7
slow_query_log=on
slow_query_log_file=/data/mysql/mysql3307/logs/slow.log
long_query_time=0.5
log_queries_not_using_indexes=1
log_error=/data/mysql/mysql3307/logs/error.log
log_bin=/data/mysql/mysql3307/logs/mysql-bin
gtid_mode=on
enforce_gtid_consistency=true
log_slave_updates=1
wait_timeout=1800
innodb_buffer_pool_size=8096M
innodb_log_file_size=256M
innodb_log_buffer_size=64M
innodb_flush_log_at_trx_commit=1
innodb_log_files_in_group=2
max_binlog_cache_size=8M
max_binlog_size=512M
secure_file_priv=/tmp/
binlog_group_commit_sync_delay=100 #主库
binlog_group_commit_sync_no_delay_count=20 #主库
slave_parallel_type=logical_clock #从库
slave_parallel_workers=4 #从库
transaction_write_set_extraction=XXHASH64 #从库
binlog_transaction_dependency_tracking=writeset #从库
slave_preserve_commit_order=1 #从库
sql-mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash
default-character-set=utf8

[myisamchk]
key_buffer_size = 128M
sort_buffer_size = 2M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

3、更改MySQL相关目录的用户组

chown -R mysql:mysql /data/mys*

4、初始化数据库

a、没有密码
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3307/my3307.cnf --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3307/data
b、生成临时密码(临时密码生成在logs/error.log文件中)
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3307/my3307.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/mysql3307/data
**如果生成了临时密码,第一次是需要修改密码的,获取临时密码 grep 'temporary password' /data/mysql/mysql3307/logs/error.log 
**alter user root@'localhost' identified by '123456'; //第一次修改密码
**mysqladmin -uroot -p123456 -S /data/mysql/mysql3307/mysql.sock password '123' //知道密码而在修改密码

5、启动MySQL

mysqld --defaults-file=/data/mysql/mysql3307/my3307.cnf &

6、查看是否启动成功

netstat -lntup | grep mysql

7、连接MySQL

mysql -S /data/mysql/mysql3307/mysql.sock
mysql -uroot -p -S /data/mysql/mysql3307/mysql.sock

前提是3306的已经安装过了,在同一台机器上。多实例一般是加快存储速度,更合理使用资源。