MHA提供了3种方式用于实现故障转移,分别自动故障转移,需要启用MHA监控;在无监控的情况下的手动故障转移以及基于在线手动切换。
MHA提供了3种方式用于实现故障转移,分别自动故障转移,,需要启用MHA监控;在无监控的情况下的手动故障转移以及基于在线手动切换。三种方式可以应对MySQL主从故障的任意场景。本文主要描述在无监控的情形是手动实现故障转移。供大家参考。
有关MHA的其他两种切换方式,可以参考:
1、手动故障转移的特点
a、在监控节点未启用masterha_manager
b、master库已经宕机或者转移到高性能服务器
c、手动故障转移支持交互或非交互两种模式
d、切换样例:$ masterha_master_switch --master_state=dead --conf=/etc/app1.cnf --dead_master_host=host1
2、masterha_master_switch切换的几个参数
--master_state=dead
强制参数为"dead" 或者 "alive". dead为手动故障转移,alive为在线切换。
--dead_master_host=(hostname)
强制参数为主机名,另2个--dead_master_ip --dead_master_port(缺省3306)可选。
--new_master_host=(hostname)
可选参数,用于指定新master,如果未指定则按candidate_master参数设定值。
--interactive=(0|1)
可选参数,指定是否交互。缺省为1,表明交互。
3、演示手动故障转移
###环境
[root@vdbsrv1 ~]# more /etc/hosts
127.0.0.1 localhost.localdomain localhost
192.168.1.6 vdbsrv1 #master
192.168.1.7 vdbsrv2 #slave1
192.168.1.8 vdbsrv3 #slave2
192.168.1.12 vdbsrv4 #manager
###master开启VIP
[root@vdbsrv4 ~]# ssh vdbsrv1 "/sbin/ifconfig eth0:0 192.168.1.13 netmask 255.255.255.0 up"
###检测MHA监控是否运行,如果已启动,可以使用masterha_check_stop先停止
[root@vdbsrv4 ~]# masterha_check_status --conf=/etc/masterha/app1.cnf
app1 is stopped(2:NOT_RUNNING).
###模拟从库滞后
[root@vdbsrv4 ~]# ssh vdbsrv2 "mysql -e 'stop slave io_thread'"
[root@vdbsrv4 ~]# ssh vdbsrv2 "mysql -e 'show slave status\G' | egrep 'Slave_IO|Slave_SQL'"
Slave_IO_State:
Slave_IO_Running: No
Slave_SQL_Running: Yes
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
###主库上插入新记录
mysql> insert into tb(val,dt) values('john',current_date());
Query OK, 1 row affected (0.01 sec)
###模拟master异常宕机
[root@vdbsrv4 ~]# ssh vdbsrv1 "killall -r mysqld"
###开始手工故障转移
[root@vdbsrv4 ~]# masterha_master_switch --master_state=dead --conf=/etc/masterha/app1.cnf --dead_master_host=vdbsrv1 \
> --dead_master_port=3306 --new_master_host=vdbsrv3 --new_master_port=3306 --ignore_last_failover
--dead_master_ip=
Wed Apr 22 11:48:39 2015 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Wed Apr 22 11:48:39 2015 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Wed Apr 22 11:48:39 2015 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Wed Apr 22 11:48:39 2015 - [info] MHA::MasterFailover version 0.56.
Wed Apr 22 11:48:39 2015 - [info] Starting master failover.
Wed Apr 22 11:48:39 2015 - [info]
Wed Apr 22 11:48:39 2015 - [info] * Phase 1: Configuration Check Phase..
Wed Apr 22 11:48:39 2015 - [info]
Wed Apr 22 11:48:39 2015 - [info] GTID failover mode = 0
Wed Apr 22 11:48:39 2015 - [info] Dead Servers:
Wed Apr 22 11:48:39 2015 - [info] vdbsrv1(192.168.1.6:3306)
Wed Apr 22 11:48:39 2015 - [info] Checking master reachability via MySQL(double check)...
Wed Apr 22 11:48:39 2015 - [info] ok.
Wed Apr 22 11:48:39 2015 - [info] Alive Servers:
Wed Apr 22 11:48:39 2015 - [info] vdbsrv2(192.168.1.7:3306)
Wed Apr 22 11:48:39 2015 - [info] vdbsrv3(192.168.1.8:3306)
Wed Apr 22 11:48:39 2015 - [info] Alive Slaves:
Wed Apr 22 11:48:39 2015 - [info] vdbsrv2(192.168.1.7:3306) Version=5.6.22-log (oldest major version between slaves) log-bin:enabled
Wed Apr 22 11:48:39 2015 - [info] Replicating from 192.168.1.6(192.168.1.6:3306)
Wed Apr 22 11:48:39 2015 - [info] vdbsrv3(192.168.1.8:3306) Version=5.6.22-log (oldest major version between slaves) log-bin:enabled
Wed Apr 22 11:48:39 2015 - [info] Replicating from 192.168.1.6(192.168.1.6:3306)
Master vdbsrv1(192.168.1.6:3306) is dead. Proceed? (yes/NO): yes
Wed Apr 22 11:48:54 2015 - [info] Starting Non-GTID based failover.
Wed Apr 22 11:48:54 2015 - [info]
Wed Apr 22 11:48:54 2015 - [info] ** Phase 1: Configuration Check Phase completed.
Wed Apr 22 11:48:54 2015 - [info]
Wed Apr 22 11:48:54 2015 - [info] * Phase 2: Dead Master Shutdown Phase..
Wed Apr 22 11:48:54 2015 - [info]
Wed Apr 22 11:48:54 2015 - [info] HealthCheck: SSH to vdbsrv1 is reachable.
Wed Apr 22 11:48:55 2015 - [info] Forcing shutdown so that applications never connect to the current master..
Wed Apr 22 11:48:55 2015 - [info] Executing master IP deactivation script:
Wed Apr 22 11:48:55 2015 - [info] /tmp/master_ip_failover --orig_master_host=vdbsrv1 --orig_master_ip=192.168.1.6
--orig_master_port=3306 --command=stopssh --ssh_user=root
IN SCRIPT TEST====/sbin/ifconfig eth0:0 down==/sbin/ifconfig eth0:0 192.168.1.13/24===

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

toadduserInmysqleffect和securly,跟隨台詞:1)USEtheCreateUserStattoDaneWuser,指定thehostandastrongpassword.2)GrantNecterAryAryaryPrivilegesSustherthing privilegesgeStatement,usifementStatement,adheringtotheprinciplelastprefilegege.3)

toaddanewuserwithcomplexpermissionsinmysql,loldtheSesteps:1)創建eTheEserWithCreateuser'newuser'newuser'@''localhost'Indedify'pa ssword';。 2)GrantreadAccesstoalltablesin'mydatabase'withGrantSelectOnMyDatabase.to'newuser'@'localhost';。 3)GrantWriteAccessto'

MySQL中的字符串數據類型包括CHAR、VARCHAR、BINARY、VARBINARY、BLOB、TEXT,排序規則(Collations)決定了字符串的比較和排序方式。 1.CHAR適合固定長度字符串,VARCHAR適合可變長度字符串。 2.BINARY和VARBINARY用於二進制數據,BLOB和TEXT用於大對像數據。 3.排序規則如utf8mb4_unicode_ci忽略大小寫,適合用戶名;utf8mb4_bin區分大小寫,適合需要精確比較的字段。

最佳的MySQLVARCHAR列長度選擇應基於數據分析、考慮未來增長、評估性能影響及字符集需求。 1)分析數據以確定典型長度;2)預留未來擴展空間;3)注意大長度對性能的影響;4)考慮字符集對存儲的影響。通過這些步驟,可以優化數據庫的效率和擴展性。

mysqlblobshavelimits:tinyblob(255bytes),blob(65,535 bytes),中間佈洛布(16,777,215個比例),andlongblob(4,294,967,967,295 bytes).tousebl觀察:1)考慮pperformance impactsandSandStorLageBlobSextern; 2)管理backbackupsandreplication carecration; 3)usepathsinst

自動化在MySQL中創建用戶的最佳工具和技術包括:1.MySQLWorkbench,適用於小型到中型環境,易於使用但資源消耗大;2.Ansible,適用於多服務器環境,簡單但學習曲線陡峭;3.自定義Python腳本,靈活但需確保腳本安全性;4.Puppet和Chef,適用於大規模環境,複雜但可擴展。選擇時需考慮規模、學習曲線和集成需求。

是的,YouCansearchInIdeAblobInMysqlusingsPecificteChniques.1)轉換theblobtoautf-8StringWithConvertFunctionWithConvertFunctionandSearchUsiseLike.2)forCompresseBlysBlobs,useuncompresseblobs,useuncompressbeforeconversion.3)expperformance impperformance imptactSandDataEcoding.4)


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

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

熱門文章

熱工具

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SublimeText3 Linux新版
SublimeText3 Linux最新版

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

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

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。