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)

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!

Atom editor mac version download
The most popular open source editor

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
