下面小編就為大家帶來一篇MySQL-group-replication 設定步驟(推薦)。小編覺得蠻不錯的,現在就分享給大家,也給大家做個參考。一起跟著小編過來看看吧
MySQL-Group-Replication 是mysql-5.7.17版本開發出來的新功能;它在master-slave 之間實作了強一致性,
但是目前來說主要是效能不太好。
【1】確定目前的mysql資料庫版本為5.7.17及以上##
/usr/local/mysql/bin/mysqld --version /usr/local/mysql/bin/mysqld Ver 5.7.17 for linux-glibc2.5 on x86_64 (MySQL Community Server (GPL))
【2】實驗環境為一台主機上安裝3台mysql,它們三個組成一個group-replication 群組
/tmp/4406.cnf 內容如下:[mysqld] ####: for global user =jianglexing # mysql basedir =/usr/local/mysql # /usr/local/mysql/ datadir =/tmp/4406/ # /usr/local/mysql/data server_id =4406 # 0 port =4406 # 3306 socket =/tmp/4406/mysql.sock # /tmp/mysql.sock auto_increment_increment =1 # 1 auto_increment_offset =1 # 1 lower_case_table_names =1 # 0 secure_file_priv = # null ####: for binlog binlog_format =row # row log_bin =mysql-bin # off binlog_rows_query_log_events =on # off log_slave_updates =on # off expire_logs_days =4 # 0 binlog_cache_size =32768 # 32768(32k) binlog_checksum =none # CRC32 sync_binlog =1 # 1 ####: for error-log log_error =mysql-err.log # /usr/local/mysql/data/localhost.localdomain.err ####: for slow query log ####: for gtid gtid_mode =on # off enforce_gtid_consistency =on # off ####: for replication master_info_repository =table # file relay_log_info_repository =table # file ####: for group replication transaction_write_set_extraction =XXHASH64 # off loose-group_replication_group_name ="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" # loose-group_replication_start_on_boot =off # off loose-group_replication_local_address ="127.0.0.1:24901" # loose-group_replication_group_seeds ="127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903" loose-group_replication_bootstrap_group =off # off ####: for innodb default_storage_engine =innodb # innodb default_tmp_storage_engine =innodb # innodb innodb_data_file_path =ibdata1:12M:autoextend # ibdata1:12M:autoextend innodb_temp_data_file_path =ibtmp1:12M:autoextend # ibtmp1:12M:autoextend innodb_log_group_home_dir =./ # ./ innodb_log_files_in_group =2 # 2 innodb_log_file_size =48M # 50331648(48M) innodb_file_format =Barracuda # Barracuda innodb_file_per_table =on # on innodb_page_size =16k # 16384(16k) innodb_thread_concurrency =0 # 0 innodb_read_io_threads =4 # 4 innodb_write_io_threads =4 # 4 innodb_purge_threads =4 # 4 innodb_print_all_deadlocks =on # off innodb_deadlock_detect =on # on innodb_lock_wait_timeout =50 # 50 innodb_spin_wait_delay =6 # 6 innodb_autoinc_lock_mode =2 # 1 innodb_stats_persistent =on # on innodb_stats_persistent_sample_pages =20 # 20 innodb_adaptive_hash_index =on # on innodb_change_buffering =all # all innodb_change_buffer_max_size =25 # 25 innodb_flush_neighbors =1 # 1 innodb_flush_method =O_DIRECT # innodb_doublewrite =on # on innodb_log_buffer_size =16M # 16777216(16M) innodb_flush_log_at_timeout =1 # 1 innodb_flush_log_at_trx_commit =1 # 1 autocommit =1 # 1 [client] auto-rehash/tmp /5506.cnf 內容如下:
[mysqld] ####: for global user =jianglexing # mysql basedir =/usr/local/mysql # /usr/local/mysql/ datadir =/tmp/5506 # /usr/local/mysql/data server_id =5506 # 0 port =5506 # 3306 socket =/tmp/5506/mysql.sock # /tmp/mysql.sock auto_increment_increment =1 # 1 auto_increment_offset =1 # 1 lower_case_table_names =1 # 0 secure_file_priv = # null ####: for binlog binlog_format =row # row log_bin =mysql-bin # off binlog_rows_query_log_events =on # off log_slave_updates =on # off expire_logs_days =4 # 0 binlog_cache_size =32768 # 32768(32k) binlog_checksum =none # CRC32 sync_binlog =1 # 1 ####: for error-log log_error =mysql-err.log # /usr/local/mysql/data/localhost.localdomain.err ####: for slow query log ####: for gtid gtid_mode =on # off enforce_gtid_consistency =on # off ####: for replication master_info_repository =table # file relay_log_info_repository =table # file ####: for group replication transaction_write_set_extraction =XXHASH64 # off loose-group_replication_group_name ="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" # loose-group_replication_start_on_boot =off # off loose-group_replication_local_address ="127.0.0.1:24902" # loose-group_replication_group_seeds ="127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903" loose-group_replication_bootstrap_group =off # off ####: for innodb default_storage_engine =innodb # innodb default_tmp_storage_engine =innodb # innodb innodb_data_file_path =ibdata1:12M:autoextend # ibdata1:12M:autoextend innodb_temp_data_file_path =ibtmp1:12M:autoextend # ibtmp1:12M:autoextend innodb_log_group_home_dir =./ # ./ innodb_log_files_in_group =2 # 2 innodb_log_file_size =48M # 50331648(48M) innodb_file_format =Barracuda # Barracuda innodb_file_per_table =on # on innodb_page_size =16k # 16384(16k) innodb_thread_concurrency =0 # 0 innodb_read_io_threads =4 # 4 innodb_write_io_threads =4 # 4 innodb_purge_threads =4 # 4 innodb_print_all_deadlocks =on # off innodb_deadlock_detect =on # on innodb_lock_wait_timeout =50 # 50 innodb_spin_wait_delay =6 # 6 innodb_autoinc_lock_mode =2 # 1 innodb_stats_persistent =on # on innodb_stats_persistent_sample_pages =20 # 20 innodb_adaptive_hash_index =on # on innodb_change_buffering =all # all innodb_change_buffer_max_size =25 # 25 innodb_flush_neighbors =1 # 1 innodb_flush_method =O_DIRECT # innodb_doublewrite =on # on innodb_log_buffer_size =16M # 16777216(16M) innodb_flush_log_at_timeout =1 # 1 innodb_flush_log_at_trx_commit =1 # 1 autocommit =1 # 1/tmp/6606.cnf 內容如下:
[mysqld] ####: for global user =jianglexing # mysql basedir =/usr/local/mysql # /usr/local/mysql/ datadir =/tmp/6606/ # /usr/local/mysql/data server_id =6606 # 0 port =6606 # 3306 socket =/tmp/6606/mysql.sock # /tmp/mysql.sock auto_increment_increment =1 # 1 auto_increment_offset =1 # 1 lower_case_table_names =1 # 0 secure_file_priv = # null ####: for binlog binlog_format =row # row log_bin =mysql-bin # off binlog_rows_query_log_events =on # off log_slave_updates =on # off expire_logs_days =4 # 0 binlog_cache_size =32768 # 32768(32k) binlog_checksum =none # CRC32 sync_binlog =1 # 1 ####: for error-log log_error =mysql-err.log # /usr/local/mysql/data/localhost.localdomain.err ####: for slow query log ####: for gtid gtid_mode =on # off enforce_gtid_consistency =on # off ####: for replication master_info_repository =table # file relay_log_info_repository =table # file ####: for group replication transaction_write_set_extraction =XXHASH64 # off loose-group_replication_group_name ="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" # loose-group_replication_start_on_boot =off # off loose-group_replication_local_address ="127.0.0.1:24903" # loose-group_replication_group_seeds ="127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903" loose-group_replication_bootstrap_group =off # off ####: for innodb default_storage_engine =innodb # innodb default_tmp_storage_engine =innodb # innodb innodb_data_file_path =ibdata1:12M:autoextend # ibdata1:12M:autoextend innodb_temp_data_file_path =ibtmp1:12M:autoextend # ibtmp1:12M:autoextend innodb_log_group_home_dir =./ # ./ innodb_log_files_in_group =2 # 2 innodb_log_file_size =48M # 50331648(48M) innodb_file_format =Barracuda # Barracuda innodb_file_per_table =on # on innodb_page_size =16k # 16384(16k) innodb_thread_concurrency =0 # 0 innodb_read_io_threads =4 # 4 innodb_write_io_threads =4 # 4 innodb_purge_threads =4 # 4 innodb_print_all_deadlocks =on # off innodb_deadlock_detect =on # on innodb_lock_wait_timeout =50 # 50 innodb_spin_wait_delay =6 # 6 innodb_autoinc_lock_mode =2 # 1 innodb_stats_persistent =on # on innodb_stats_persistent_sample_pages =20 # 20 innodb_adaptive_hash_index =on # on innodb_change_buffering =all # all innodb_change_buffer_max_size =25 # 25 innodb_flush_neighbors =1 # 1 innodb_flush_method =O_DIRECT # innodb_doublewrite =on # on innodb_log_buffer_size =16M # 16777216(16M) innodb_flush_log_at_timeout =1 # 1 innodb_flush_log_at_trx_commit =1 # 1 autocommit =1 # 1
##【3】初始化三個資料庫實例#cd /usr/local/mysql/
./bin/mysqld --defautls-file=/tmp/4406.cnf --datadir=/tmp/4406 --initialize-insecrue
./bin/mysqld --defautls-file=/tmp/5506.cnf --datadir=/tmp/5506 --initialize-insecrue
./bin/mysqld --defautls-file=/tmp/6606.cnf --datadir=/tmp/6606 --initialize-insecrue
【4】設定group-replication 的初始實例/usr/local/mysql/bin/mysqld --defaults-file=/tmp/4406.cnf &
mysql -h127.0.0.1 -uroot -P4406
-- 增加用户
set sql_log_bin=0;
create user rpl_user@'%' identified by '123456';
grant replication slave,replication client on *.* to rpl_user@'%';
create user rpl_user@'127.0.0.1' identified by '123456';
grant replication slave,replication client on *.* to rpl_user@'127.0.0.1';
create user rpl_user@'localhost' identified by '123456';
grant replication slave,replication client on *.* to rpl_user@'localhost';
set sql_log_bin=1;
-- 增加复制凭证
change master to
master_user='rpl_user',
master_password='123456'
for channel 'group_replication_recovery';
-- 安装组复制物件
install plugin group_replication soname 'group_replication.so';
-- 启动组复制
set global group_replication_bootstrap_group=on;
start group_replication;
set global group_replication_bootstrap_group=off;
【5】5506 實例的設定過程如下:/usr/local/mysql/bin/mysqld --defaults-file=/tmp/5506.cnf &
mysql -h127.0.0.1 -uroot -P5506
-- 增加用户
set sql_log_bin=0;
create user rpl_user@'%' identified by '123456';
grant replication slave,replication client on *.* to rpl_user@'%';
create user rpl_user@'127.0.0.1' identified by '123456';
grant replication slave,replication client on *.* to rpl_user@'127.0.0.1';
create user rpl_user@'localhost' identified by '123456';
grant replication slave,replication client on *.* to rpl_user@'localhost';
set sql_log_bin=1;
-- 增加复制凭证
change master to
master_user='rpl_user',
master_password='123456'
for channel 'group_replication_recovery';
-- 安装组复制物件
install plugin group_replication soname 'group_replication.so';
-- 启动组复制
start group_replication; # 注意这里不是初始化了,只要加入就行
【6】6606 實例的操作與5506的操作一樣,這樣group replication 的設定就完成了。 #
以上是MySQL-group-replication設定步驟的範例程式碼分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

在MySQL中創建和管理用戶賬戶的步驟如下:1.創建用戶:使用CREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';2.分配權限:使用GRANTSELECT,INSERT,UPDATEONmydatabase.TO'newuser'@'localhost';3.修正權限錯誤:使用REVOKEALLPRIVILEGESONmydatabase.FROM'newuser'@'localhost';然後重新分配權限;4.優化權限:使用SHOWGRA

MySQL適合快速開發和中小型應用,Oracle適合大型企業和高可用性需求。 1)MySQL開源、易用,適用於Web應用和中小型企業。 2)Oracle功能強大,適合大型企業和政府機構。 3)MySQL支持多種存儲引擎,Oracle提供豐富的企業級功能。

MySQL相比其他關係型數據庫的劣勢包括:1.性能問題:在處理大規模數據時可能遇到瓶頸,PostgreSQL在復雜查詢和大數據處理上表現更優。 2.擴展性:水平擴展能力不如GoogleSpanner和AmazonAurora。 3.功能限制:在高級功能上不如PostgreSQL和Oracle,某些功能需要更多自定義代碼和維護。

MySQL支持四種JOIN類型:INNERJOIN、LEFTJOIN、RIGHTJOIN和FULLOUTERJOIN。 1.INNERJOIN用於匹配兩個表中的行並返回符合條件的結果。 2.LEFTJOIN返回左表的所有行,即使右表沒有匹配。 3.RIGHTJOIN與LEFTJOIN相反,返回右表的所有行。 4.FULLOUTERJOIN返回兩表中所有符合或不符合條件的行。

MySQL在高負載下的性能與其他RDBMS相比各有優劣。 1)MySQL通過InnoDB引擎和優化策略如索引、查詢緩存和分區表在高負載下表現良好。 2)PostgreSQL通過MVCC機制提供高效並發讀寫,Oracle和MicrosoftSQLServer則通過各自的優化策略提升性能。通過合理的配置和優化,MySQL可以在高負載環境中表現出色。

InnoDBBufferPool通過緩存數據和索引頁來減少磁盤I/O,提升數據庫性能。其工作原理包括:1.數據讀取:從BufferPool中讀取數據;2.數據寫入:修改數據後寫入BufferPool並定期刷新到磁盤;3.緩存管理:使用LRU算法管理緩存頁;4.預讀機制:提前加載相鄰數據頁。通過調整BufferPool大小和使用多個實例,可以優化數據庫性能。

MySQL与其他编程语言相比,主要用于存储和管理数据,而其他语言如Python、Java、C 则用于逻辑处理和应用开发。MySQL以其高性能、可扩展性和跨平台支持著称,适合数据管理需求,而其他语言在各自领域如数据分析、企业应用和系统编程中各有优势。

MySQL值得學習,因為它是強大的開源數據庫管理系統,適用於數據存儲、管理和分析。 1)MySQL是關係型數據庫,使用SQL操作數據,適合結構化數據管理。 2)SQL語言是與MySQL交互的關鍵,支持CRUD操作。 3)MySQL的工作原理包括客戶端/服務器架構、存儲引擎和查詢優化器。 4)基本用法包括創建數據庫和表,高級用法涉及使用JOIN連接表。 5)常見錯誤包括語法錯誤和權限問題,調試技巧包括檢查語法和使用EXPLAIN命令。 6)性能優化涉及使用索引、優化SQL語句和定期維護數據庫。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

Dreamweaver CS6
視覺化網頁開發工具