您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關MySQL多實例的安裝方法是什么,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
Step 1 . 準備工作
關閉防火墻; 安裝 MySQL依賴于libaio 庫;下載,解壓,重命名 MySQL的執行文件;新建用戶組和用戶 等準備工作在此不再贅述。
可執行文件目錄為 /data/mysql57
添加用戶和組的指令
groupadd mysql useradd mysql -g mysql
Step 2 . 添加環境變量
在/etc/profile文件中,追加 PATH=${PATH}:/data/mysql57/bin/
保存后,如需要立即生效,可執行 source /etc/profile 。
在data根目錄下執行
mkdir -p mysql3306/data mysql3306/mysql_log mysql3306/tmp mysql3307/data mysql3307/mysql_log mysql3307/tmp mysqld_multi/log
創建記錄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/bin
chmod -R 755 /data/mysql57/support-files
step 4 . 編輯my.cnf
[client] host=localhost socket = /tmp/mysql.sock default-character-set=utf8mb4 #loose-local-infile=0 [mysqld] user=mysql log_bin_trust_function_creators=1 secure_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=utf8mb4 collation_server=utf8mb4_unicode_ci lower_case_table_names = 0 skip_name_resolve = 1 #max_connect_errors = 1000 max_connections = 2000 thread_cache_size=256 #thread_stack= 262144 #back_log=80 max_allowed_packet = 134217728 event_scheduler = 1 local-infile=0 #lower_case_table_names = 1 explicit_defaults_for_timestamp = 1 expire_logs_days = 7 log_bin_trust_function_creators =1 ####.frm/.ibd files qty related open_files_limit=65535 innodb_open_files=65535 table_open_cache=65535 table_definition_cache=65535 #### seesion buffer related read_buffer_size = 262144 read_rnd_buffer_size = 524288 sort_buffer_size = 8388608 join_buffer_size = 8388608 ####memory table size tmp_table_size =67108864 max_heap_table_size=67108864 ####timeout interactive_timeout = 1800 wait_timeout = 1800 # connect_timeout=10 ########slow query ######## slow_query_log = 1 log_slow_slave_statements = 1 #log_queries_not_using_indexes = 1 log_throttle_queries_not_using_indexes = 10 long_query_time = 1 #min_examined_row_limit = 10000 ########innodb settings######## innodb_buffer_pool_size = 10737418240 innodb_buffer_pool_instances = 16 innodb_buffer_pool_dump_pct = 40 innodb_lru_scan_depth = 2048 innodb_page_cleaners = 16 #innodb_purge_threads = 4 innodb_sort_buffer_size = 67108864 #innodb_file_per_table = 1 #innodb_flush_log_at_trx_commit = 1 innodb_undo_log_truncate = 1 innodb_undo_tablespaces = 3 innodb_max_undo_log_size = 2147483648 innodb_purge_rseg_truncate_frequency = 128 innodb_log_file_size = 1073741824 innodb_log_files_in_group = 3 innodb_log_buffer_size = 16777216 innodb_flush_method = O_DIRECT innodb_flush_neighbors = 0 innodb_print_all_deadlocks = 1 innodb_strict_mode = 1 #innodb_lock_wait_timeout = 50 innodb_io_capacity = 32768 innodb_io_capacity_max = 65536 innodb_thread_concurrency = 32 innodb_write_io_threads = 8 innodb_read_io_threads = 8 ########replication settings######## master_info_repository = TABLE relay_log_info_repository = TABLE gtid_mode = on enforce_gtid_consistency = 1 binlog_gtid_simple_recovery=1 relay_log_recovery = 1 slave-parallel-type = LOGICAL_CLOCK slave-parallel-workers = 16 slave_transaction_retries=128 slave_preserve_commit_order=1 log_slave_updates=1 binlog_format = ROW log_timestamps=system binlog_rows_query_log_events = 1 binlog_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_safe mysqladmin = /data/mysql57/bin/mysqladmin log = /data/mysqld_multi/log/mysqld_multi.log [mysqld3306] basedir = /data/mysql57 mysqladmin=mysqladmin datadir=/data/mysql3306/data port=3306 server_id=102473306 socket= /tmp/mysql_3306.sock tmpdir = /data/mysql3306/tmp pid-file = /data/mysql3306/mysql_log/mysql3306.pid slow_query_log_file = /data/mysql3306/mysql_log/mysql3306_slow_new.log log-error = /data/mysql3306/mysql_log/mysql3306.err general_log_file= /data/mysql3306/mysql_log/mysql3306.genlog log-bin = /data/mysql3306/mysql_log/mysql3306_bin relay_log = /data/mysql3306/mysql_log/relay3306.log innodb_buffer_pool_size = 90G innodb_buffer_pool_instances = 8 [mysqld3307] basedir = /data/mysql57 mysqladmin=mysqladmin datadir=/data/mysql3307/data port=3307 server_id=102473307 socket= /tmp/mysql_3307.sock tmpdir = /data/mysql3307/tmp pid-file = /data/mysql3307/mysql_log/mysql3307.pid slow_query_log_file = /data/mysql3307/mysql_log/mysql3307_slow_new.log log-error = /data/mysql3307/mysql_log/mysql3307.err general_log_file= /data/mysql3307/mysql_log/mysql3307.genlog log-bin = /data/mysql3307/mysql_log/mysql3307_bin relay_log = /data/mysql3307/mysql_log/relay3307.log innodb_buffer_pool_size = 90G innodb_buffer_pool_instances = 8 [mysqldump] quick
step 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/data
step 6 . 復制生成mysqld_multi并添加到開機啟動
cp /data/mysql57/support-files/mysqld_multi.server /etc/init.d/mysqld_multi
chkconfig --add mysqld_multi
step 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 的操作會讓它變成有效)
多實例登入需指定 socket 參數
本測試3306實例登入的方式為:
mysql -S /tmp/mysql_3306.sock -uroot --port 3306 -p
step 9 . 賦予通過mysqld_multi stop關閉實例的權限。
關閉實例需要配置root用戶及密碼, 修改 /etc/my.cnf文件。
在 [client] 位置添加
user=root password=密碼
因為文件中需要保留賬號密碼,有安全風險。實際環境中要不要如此設置,還需根據具體情況和安全要求而定。
經過以上步驟的操作,此服務器成功安裝了2個MySQL實例,一個Port為3306,另一個Port為3307
關于MySQL多實例的安裝方法是什么就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。