1. [mysqld_multi] 是否需要配置
- 可以直接配置[mysqld1]、[mysqld2]标签,使用mysqld_multi start可以启动数据库实例,但是没有mysqld_safe守护进程,所以该标签需要配置。
2. 停止mysqld实例
- 需要在[mysqld_multi]标签下需要配置user和password(5.7为pass)来进行关闭数据库实例。
- [client]标签
-
- 如果在[mysqld_multi]中没有配置user和password,但是在[client]中配置了,仍然可以关闭实例。因为配置文件会先读[client]标签。如果[client]标签和[mysqld_multi]有相同的参数,则以[mysqld_multi]为主。(存在精确匹配的标签,则优先使用精确匹配标签下的配置项)
3. 配置说明
- 配置的标签顺序没有关系,不会影响最终配置的有效性。
- 同类型标签中的配置项会合并,形成一个大的配置项。
- 匹配度高的标签中的配置项的值,会覆盖匹配度低的标签中的配置项的值
- [mysqldN]中的配置项会和[mysqld]中的配置项合并,并且[mysqldN]中已有的配置项的值,会覆盖掉[mysqld]中的配置项的值,如datadir、port等。
4. MySQL配置
[client]
user = root
password = 123
[mysqld_multi] # 这里使用了client标签中的user,故这里不再定义user
mysqld = /usr/local/mysql/bin/mysqld_safe
log= /var/log/mysqld_multi.log
[mysqld1]
server-id = 11
datadir = /data1
basedir = /usr/local/mysql # basedir定义使用了5.7的mysql版本
port = 3307
socket = /tmp/mysql.sock1
[mysqld2]
server-id = 22
datadir = /data2
basedir = /usr/local/mysql
port = 3308
socket = /tmp/mysql.sock2
[mysqld3]
server-id = 33
datadir = /data3
basedir = /usr/local/mysql56 # basedir定义了使用5.6的mysql版本
port = 3309
socket = /tmp/mysql.sock3
plugin_dir=/usr/local/mysql56/lib/plugin # plugin 目录也变了
#这里无需特别配置mysqld, 可以继承使用[mysqld_multi]中的配置,然后根据basedir找到对应的mysqld
[mysqld4]
server-id = 44
datadir = /data4
basedir = /usr/local/mysql56
port = 3310
socket = /tmp/mysql.sock4
plugin_dir=/usr/local/mysql56/lib/plugin
#--------------以下是参数模板,测试环境已经将个别size调小-----------
[mysqld]
########basic settings########
server-id = 100
port = 3306
user = mysql
bind_address = 0.0.0.0
#autocommit = 0
character_set_server=utf8mb4
skip_name_resolve = 1
max_connections = 800
max_connect_errors = 1000
datadir = /data/mysql_data
transaction_isolation = READ-COMMITTED
explicit_defaults_for_timestamp = 1
join_buffer_size = 134217728
tmp_table_size = 67108864
tmpdir = /tmp
max_allowed_packet = 16777216
sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"
interactive_timeout = 1800
wait_timeout = 1800
read_buffer_size = 16777216
read_rnd_buffer_size = 33554432
sort_buffer_size = 33554432
########log settings########
log_error = error.log
slow_query_log= 1
slow_query_log_file = slow.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_throttle_queries_not_using_indexes = 10
expire_logs_days = 90
long_query_time = 2
min_examined_row_limit= 100
########replication settings########
master_info_repository = TABLE
relay_log_info_repository = TABLE
log_bin = bin.log
sync_binlog = 1
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row
relay_log= relay.log
relay_log_recovery = 1
binlog_gtid_simple_recovery = 1
slave_skip_errors = ddl_exist_errors
########innodb settings########
innodb_page_size = 8192
innodb_buffer_pool_size = 1G # 该参数减小到1G
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 2000
innodb_lock_wait_timeout = 5
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
#innodb_log_group_home_dir = /redolog/
#innodb_undo_directory = /undolog/
innodb_undo_logs = 128
innodb_undo_tablespaces = 3
innodb_flush_neighbors = 1
innodb_log_file_size = 128M # 该参数减小到128M
innodb_log_buffer_size = 16777216
innodb_purge_threads = 4
innodb_large_prefix = 1
innodb_thread_concurrency = 64
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_sort_buffer_size = 67108864
########semi sync replication settings########
plugin_dir=/usr/local/mysql/lib/plugin
#plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
loose_rpl_semi_sync_master_enabled = 1
loose_rpl_semi_sync_slave_enabled = 1
loose_rpl_semi_sync_master_timeout = 5000
[mysqld-5.7]
innodb_buffer_pool_dump_pct = 40
innodb_page_cleaners = 4
innodb_undo_log_truncate = 1
innodb_max_undo_log_size = 1G # 该参数减小到1G
innodb_purge_rseg_truncate_frequency = 128
binlog_gtid_simple_recovery=1
log_timestamps=system
transaction_write_set_extraction=MURMUR32
show_compatibility_56=on
5. 安装操作
mkdir -p /data{1..3}
chown -R mysql.mysql /data{1..3}
#初始化
./mysqld --initialize --user=mysql --datadir=/data1/mysql_data #密码在error.log
./mysqld --initialize --user=mysql --datadir=/data2/mysql_data #密码在error.log
./script/mysql_install_db --user=mysql --datadir=/data3/mysql_data #无密码
cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multid
mysqld_multi report
mysqld_multi start 1
mysqld_multi stop 1
mysqld_multi start
mysqld_multi stop
-- 设置--login-path
mysql_config_editor set -G mysql1 -uroot -p -S /tmp/mysql.sock1
mysql_config_editor set -G mysql2 -uroot -p -S /tmp/mysql.sock2
mysql_config_editor set -G mysql3 -uroot -p -S /tmp/mysql.sock3
-- 登陆
mysql --login-path=mysql1
-- 开启ssl。ssl登陆需要通过tcp/ip方式的连接。默认使用ssl登陆,如使用--skip-ssl则禁用ssl登陆。
bin/mysql_ssl_rsa_setup --datadir=/data/mysql_data --user=mysql --uid=mysql #使用--uid后,就不需要chown mysql.mysql *.pem
alter user bingo@'%' require ssl; #开启ssl认证。开启ssl认证后使用--skip-ssl则登陆不上
mysql -ubingo -p -h192.168.44.22 -P 3306
alter user bingo@'%' require x509; #开启证书认证。开启之后需要将证书上传到对应服务器上才能登陆数据库
mysql -uwanghh -p -h192.168.44.22 -P 3306 --ssl-cert=/data/mysql_data/client-cert.pem --ssl-key=/data/mysql_data/client-key.pem
标签:multi,log,--,实例,innodb,版本,mysql,mysqld,安装 From: https://www.cnblogs.com/gavin-zheng/p/17284679.html