小潘杂谈

MySQL 多实例的安装

字号+ 作者:admin 来源:seo博客 2020-09-22 18:40 我要评论( )

Step 1 . 准备工作 关闭防火墙; 安装 MySQL依赖于libaio 库;下载,解压,重命名 MySQL的执行文件;新建用户组和用户 等准备工作在此不再赘述。 可执行文件目录为 ......

Step 1 . 准备工作

关闭防火墙; 安装 MySQL依赖于libaio 库;下载,解压,重命名 MySQL的执行文件;新建用户组和用户 等准备工作在此不再赘述。

可执行文件目录为 /data/mysql57

MySQL 多实例的安装

添加用户和组的指令groupadd mysqluseradd mysql -g mysqlStep 2 .添加环境变量

在/etc/profile文件中,追加 PATH=${PATH}:/data/mysql57/bin/

保存后,如需要立即生效,可执行 source /etc/profile 。step 3 . 创建目录并授权在data根目录下执行mkdir -p mysql3306/data mysql3306/mysql_log mysql3306/tmp mysql3307/datamysql3307/mysql_logmysql3307/tmp mysqld_multi/logMySQL 多实例的安装

创建记录log的文件,此步骤不可少。touch /data/mysql3306/mysql_log/mysql3306.errtouch /data/mysql3307/mysql_log/mysql3307.err赋予目录和文件权限chown -R mysql.mysql mysql3* mysqld_multi在本测试案例中,mysql57是从其它服务上copy来的,不是直接下载解压的,所以多了下面的两步授权操作。chmod -R 755 /data/mysql57/binchmod -R 755 /data/mysql57/support-filesstep 4 . 编辑my.cnf[client]host=localhostsocket = /tmp/mysql.sock default-character-set=utf8mb4#loose-local-infile=0[mysqld]user=mysqllog_bin_trust_function_creators=1secure_file_priv='/tmp'########server setting#######sql_mode = "ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"character-set-server=utf8mb4collation_server=utf8mb4_unicode_cilower_case_table_names = 0skip_name_resolve = 1#max_connect_errors = 1000max_connections = 2000thread_cache_size=256#thread_stack= 262144#back_log=80max_allowed_packet = 134217728event_scheduler = 1 local-infile=0#lower_case_table_names = 1explicit_defaults_for_timestamp = 1expire_logs_days = 7log_bin_trust_function_creators =1####.frm/.ibd files qty relatedopen_files_limit=65535innodb_open_files=65535table_open_cache=65535table_definition_cache=65535#### seesion buffer relatedread_buffer_size = 262144read_rnd_buffer_size = 524288sort_buffer_size = 8388608join_buffer_size = 8388608####memory table size tmp_table_size =67108864max_heap_table_size=67108864####timeoutinteractive_timeout = 1800wait_timeout = 1800# connect_timeout=10########slow query ########slow_query_log = 1log_slow_slave_statements = 1#log_queries_not_using_indexes = 1log_throttle_queries_not_using_indexes = 10long_query_time = 1#min_examined_row_limit = 10000########innodb settings########innodb_buffer_pool_size = 10737418240innodb_buffer_pool_instances = 16 innodb_buffer_pool_dump_pct = 40innodb_lru_scan_depth = 2048innodb_page_cleaners = 16#innodb_purge_threads = 4innodb_sort_buffer_size = 67108864#innodb_file_per_table = 1#innodb_flush_log_at_trx_commit = 1innodb_undo_log_truncate = 1innodb_undo_tablespaces = 3 innodb_max_undo_log_size = 2147483648innodb_purge_rseg_truncate_frequency = 128innodb_log_file_size = 1073741824innodb_log_files_in_group = 3innodb_log_buffer_size = 16777216innodb_flush_method = O_DIRECTinnodb_flush_neighbors = 0innodb_print_all_deadlocks = 1innodb_strict_mode = 1#innodb_lock_wait_timeout = 50innodb_io_capacity = 32768innodb_io_capacity_max = 65536innodb_thread_concurrency = 32innodb_write_io_threads = 8innodb_read_io_threads = 8########replication settings########master_info_repository = TABLErelay_log_info_repository = TABLEgtid_mode = onenforce_gtid_consistency = 1binlog_gtid_simple_recovery=1relay_log_recovery = 1slave-parallel-type = LOGICAL_CLOCKslave-parallel-workers = 16slave_transaction_retries=128slave_preserve_commit_order=1log_slave_updates=1binlog_format = ROWlog_timestamps=systembinlog_rows_query_log_events = 1binlog_row_image='full' slave_skip_errors = ddl_exist_errors########semi sync replication settings##########plugin_dir=/data/mysql/plugin/#plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"#rpl_semi_sync_master_enabled = 1#rpl_semi_sync_master_timeout = 5000#rpl_semi_sync_slave_enabled = 1[mysqld_multi]mysqld = /data/mysql57/bin/mysqld_safemysqladmin = /data/mysql57/bin/mysqladminlog = /data/mysqld_multi/log/mysqld_multi.log[mysqld3306]basedir = /data/mysql57mysqladmin=mysqladmindatadir=/data/mysql3306/dataport=3306server_id=102473306socket= /tmp/mysql_3306.socktmpdir = /data/mysql3306/tmppid-file = /data/mysql3306/mysql_log/mysql3306.pidslow_query_log_file = /data/mysql3306/mysql_log/mysql3306_slow_new.loglog-error = /data/mysql3306/mysql_log/mysql3306.errgeneral_log_file= /data/mysql3306/mysql_log/mysql3306.genloglog-bin = /data/mysql3306/mysql_log/mysql3306_binrelay_log = /data/mysql3306/mysql_log/relay3306.loginnodb_buffer_pool_size = 90Ginnodb_buffer_pool_instances = 8[mysqld3307]basedir = /data/mysql57mysqladmin=mysqladmindatadir=/data/mysql3307/dataport=3307server_id=102473307socket= /tmp/mysql_3307.socktmpdir = /data/mysql3307/tmppid-file = /data/mysql3307/mysql_log/mysql3307.pidslow_query_log_file = /data/mysql3307/mysql_log/mysql3307_slow_new.loglog-error = /data/mysql3307/mysql_log/mysql3307.errgeneral_log_file= /data/mysql3307/mysql_log/mysql3307.genloglog-bin = /data/mysql3307/mysql_log/mysql3307_binrelay_log = /data/mysql3307/mysql_log/relay3307.loginnodb_buffer_pool_size = 90Ginnodb_buffer_pool_instances = 8[mysqldump]quickstep 5 . 初始化实例

初始化3306端口的实例,注意产生的临时密码。/data/mysql57/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/data/mysql57--datadir=/data/mysql3306/data初始化3307端口的实例,注意产生的临时密码。/data/mysql57/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/data/mysql57--datadir=/data/mysql3307/datastep 6 . 复制生成mysqld_multi并添加到开机启动cp /data/mysql57/support-files/mysqld_multi.server /etc/init.d/mysqld_multichkconfig--add mysqld_multistep 7 . 多实例Mysqld的开启

开启全部实例mysqld_multi start查看开启情况(查看全部实例状态)mysqld_multi report开启指定实例

开启/etc/my.cnf中[mysqld3306]其中mysqld后面的数字为标签,例如3306标签mysqld_multi start 3306同样开启3307标签实例mysqld_multi start 3307(注意:此处没有说通过 mysqld_multi stop 命令进行关闭实例,为什么不说,因为命令无效。Step 9 的操作会让它变成有效)step 8 . 第一次登入实例,修改root账号密码多实例登入需指定 socket 参数

本测试3306实例登入的方式为:mysql-S /tmp/mysql_3306.sock -uroot --port 3306 -pMySQL 多实例的安装

step 9 . 赋予通过mysqld_multi stop关闭实例的权限。

关闭实例需要配置root用户及密码, 修改 /etc/my.cnf文件。

在 [client] 位置添加 user=rootpassword=密码MySQL 多实例的安装

因为文件中需要保留账号密码,有安全风险。实际环境中要不要如此设置,还需根据具体情况和安全要求而定。

经过以上步骤的操作,此服务器成功安装了2个MySQL实例,一个Port为3306,另一个Port为3307以上就是MySQL 多实例的安装的详细内容,更多请关注小潘博客其它相关文章!

转载请注明出处。

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。转载请注明seohttp://www.hkxiaopan.com

网友点评
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
验证码: 点击我更换图片
精彩导读