CN115629921A - Method, system, medium and device for failover of MySQL database - Google Patents

Method, system, medium and device for failover of MySQL database Download PDF

Info

Publication number
CN115629921A
CN115629921A CN202211267953.5A CN202211267953A CN115629921A CN 115629921 A CN115629921 A CN 115629921A CN 202211267953 A CN202211267953 A CN 202211267953A CN 115629921 A CN115629921 A CN 115629921A
Authority
CN
China
Prior art keywords
database
master database
slave
current master
configuration
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211267953.5A
Other languages
Chinese (zh)
Inventor
孙容容
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Yonghui Technology Co ltd
Original Assignee
Beijing Yonghui Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Yonghui Technology Co ltd filed Critical Beijing Yonghui Technology Co ltd
Priority to CN202211267953.5A priority Critical patent/CN115629921A/en
Publication of CN115629921A publication Critical patent/CN115629921A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/16Error detection or correction of the data by redundancy in hardware
    • G06F11/20Error detection or correction of the data by redundancy in hardware using active fault-masking, e.g. by switching out faulty elements or by switching in spare elements
    • G06F11/202Error detection or correction of the data by redundancy in hardware using active fault-masking, e.g. by switching out faulty elements or by switching in spare elements where processing functionality is redundant
    • G06F11/2023Failover techniques
    • G06F11/203Failover techniques using migration
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • G06F11/3409Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment
    • G06F11/3419Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment by assessing time
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/21Design, administration or maintenance of databases
    • G06F16/214Database migration support
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/08Configuration management of networks or network elements
    • H04L41/0803Configuration setting
    • H04L41/0813Configuration setting characterised by the conditions triggering a change of settings

Abstract

The application provides a method, a system, a medium and a device for fault transfer of a MySQL database, wherein the method comprises the following steps: detecting whether the reaction time length of the current main database exceeds a limit time length threshold value; responding to the fact that the reaction duration of the current master database exceeds the limit duration threshold, modifying the configuration of the current master database, and detecting whether the reaction duration of the current master database exceeds the limit duration threshold again; and switching the current master database into the slave database in response to the response time of the current master database after the configuration modification exceeding the limit time threshold. When the current master database fails and does not stop service, the configuration of the current master database is modified and adjusted to try to recover the access of the master database, and master-slave switching of the master database can be performed under the condition that the master database cannot be recovered, so that the fault transfer of the MySQL database is realized, and after the master database is switched and before the domain name is not effective, the service of the slave database can be normally accessed through the domain name.

Description

MySQL database fault transfer method, system, medium and equipment
Technical Field
The application belongs to the technical field of database clusters and relates to a method, a system, a medium and equipment for failover of a MySQL database.
Background
High availability clusters are presented to make the overall services of the cluster as available as possible, thereby reducing the loss caused by computer hardware and software error-vulnerability. If a node fails, its standby node will take over its responsibilities within a few seconds. For example, in a real-world environment, in order to ensure the availability of data, a MySQL database service is generally deployed redundantly, and data is synchronized from a master database to a slave database through a master-slave replication technology, wherein the master database is responsible for providing services to the outside. Therefore, once the master database in the MySQL database system fails, the master-slave copy of the MySQL database system cannot implement failover, and thus needs to be implemented by other software. Currently, a slave database in a cluster is set as a master database by using database high-availability software.
The existing MySQL database generally HAs high available MHA (Master HA, served by MHA Manager and MHA Node), which provides an automated Master Failover (automated Master Failover) function for MySQL Master-slave replication architecture. When the MHA monitors the failure of the master database (master) node, the slave database (slave) node having the latest data therein is promoted to be a new master database (master) node, and during the period, the MHA can avoid the problem of consistency by acquiring additional information from other slave nodes. The MHA also provides an online switching function of a master database (master) node, i.e., switching master/slave database (slave) nodes as needed.
However, currently, two problems exist in master-slave switching of MHA: 1) The current master database (master) has no service stop, for example, the current service is rammed (Hang), and the scheme of MHA cannot be detected; 2) If the database is accessed in a domain name mode, the time domain name generation time for switching the master database and the slave database is too long, and about 5-10 minutes is needed.
Therefore, a technical need exists in the art for a failover scheme for MySQL databases, which solves the above-mentioned problems of master-slave switching of existing databases.
Disclosure of Invention
The application aims to provide a method, a system, a medium and equipment for failover of a MySQL database, which are used for realizing master-slave switching of the MySQL database and realizing failover of the MySQL database.
In a first aspect, the present application provides a failover method for a MySQL database, where the method includes: detecting whether the reaction time length of the current main database exceeds a limit time length threshold value; responding to the condition that the reaction duration of the current master database exceeds a limit duration threshold, modifying the configuration of the current master database, and detecting whether the reaction duration of the current master database exceeds the limit duration threshold again; and switching the current master database to a slave database in response to the response time of the current master database after the configuration modification exceeding a limit time threshold.
According to the method and the device, when the current master database fails and is not out of service, the configuration of the current master database is modified and adjusted, the access of the master database is tried to be recovered, and master-slave switching of the master database can be performed under the condition that the recovery is not achieved and the master database is not out of service, so that the failover of the MySQL database is achieved.
In an embodiment of the present application, one implementation manner of detecting whether the reaction duration of the current master database exceeds the time limit threshold includes: generating a detection instruction; sending the detection instruction to the current master database so that the current master database operates based on the detection instruction and returns the operating reaction duration; detecting whether the reaction time length exceeds the limit time length threshold.
In the implementation mode, whether the current master database breaks down or not is determined by sending the instruction to detect the reaction time length of the current master database, and the detection is simple and convenient and has high efficiency.
In an embodiment of the present application, one way of modifying the configuration of the current master database is to modify a link configuration of the current master database; the modifying the link configuration of the current master database includes decreasing a number of links of the current master database.
In the implementation mode, the database is recovered by modifying the link configuration, and the recovery mode is quick and efficient.
In an embodiment of the present application, after the switching the current master database to the slave database, the method further includes: when a domain name access instruction is received, acquiring the IP address of the slave database; performing host configuration based on the IP address of the slave database; accessing the slave database based on the host configuration.
In an embodiment of the present application, the method further includes: detecting whether the domain name is effective; and deleting the host configuration in response to the domain name being effective.
In the method and the device, after the master database and the slave database are switched and before the domain name is not effective, the IP address of the slave database is subjected to host configuration, so that the service of the slave database can be normally accessed through the domain name.
In a second aspect, the present application provides a failover system for a MySQL database, the system comprising: the time length detection module is used for detecting whether the reaction time length of the current main database exceeds a limit time length threshold value or not; the configuration modification module is used for modifying the configuration of the current master database in response to the response time of the current master database exceeding a limit time threshold, and enabling the time detection module to detect whether the response time of the current master database exceeds the limit time threshold again; and the database switching module is used for switching the current master database into the slave database in response to the response time of the current master database after the configuration modification exceeding a time limit threshold.
According to the method and the system, when the current master database fails and does not stop service, the configuration of the current master database is modified and adjusted, the access of the master database is tried to be recovered, and master-slave switching of the master database can be performed under the condition that the recovery is not performed and the service of the master database is not stopped, so that the failover of the MySQL database is realized.
In an embodiment of the present application, the method further includes: an access control module; the access control module includes: the IP address acquisition unit is used for acquiring the IP address of the slave database when receiving a domain name access instruction; a host configuration unit, configured to perform host configuration based on the IP address of the slave database; a database access unit for accessing the slave database based on the host configuration; and the host configuration deleting unit is used for detecting whether the domain name is effective or not and deleting the host configuration in response to the effective domain name.
In the method and the device, after the master database and the slave database are switched and before the domain name is not effective, the IP address of the slave database is subjected to host configuration, so that the service of the slave database can be normally accessed through the domain name, and the disconnection time of an application program accessing the database is shortened as much as possible.
In a third aspect, the present application provides an electronic device, comprising: a memory storing a computer program; and the processor is in communication connection with the memory and realizes the method when the computer program is called.
In a fourth aspect, the present application provides a computer readable storage medium having stored thereon a computer program which, when executed by an electronic device, implements the method described above.
As described above, the method, system, medium, and device for failover of MySQL database according to the present application have the following beneficial effects:
1. in the invention, when the current master database fails and is not out of service, the configuration of the current master database is modified and adjusted to try to recover the access of the master database, and the master-slave switching of the master database can be carried out under the condition that the master database is not recovered and the master database is not out of service, so that the fault transfer of the MySQL database is realized.
2. In the invention, after the master database and the slave database are switched and before the domain name is not effective, the IP address of the slave database is subjected to host configuration, so that the service of the slave database can be normally accessed through the domain name.
Drawings
Fig. 1 is a schematic view showing an application scenario of the failover method of the MySQL database according to the embodiment of the present application.
Fig. 2 is a schematic flowchart showing a failover method of the MySQL database according to the embodiment of the present application.
Fig. 3 is a schematic flow chart illustrating the detection of the reaction duration in the method for failover of MySQL database according to the embodiment of the present application;
fig. 4 is a schematic flowchart illustrating a process of accessing a slave database in the MySQL database failover method according to the embodiment of the present application;
fig. 5 is a schematic flowchart illustrating a process of accessing a slave database when a domain name is not validated in the MySQL database failover method according to the embodiment of the present application;
fig. 6 is a schematic diagram showing a specific implementation process of the failover method of the MySQL database according to the embodiment of the present application;
fig. 7 is a schematic structural diagram illustrating a schematic structural diagram of a failover system of MySQL database according to the embodiment of the present application;
fig. 8 is a schematic structural diagram illustrating a preferred principle of the failover system of MySQL database according to the embodiment of the present application;
fig. 9 is a schematic structural diagram illustrating a principle of an access control module in the MySQL database failover system according to the embodiment of the present application;
fig. 10 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Description of the element reference numerals
100 Fault transfer system of MySQL database
110. Duration detection module
120. Configuration modification module
130. Database switching module
140. Access control module
141 IP address acquisition unit
142 host configuration unit
143. Database access unit
144 host configuration deleting unit
101. Electronic device
1001. Processor with a memory having a plurality of memory cells
1002. Memory device
S100 to S400
S110 to S130
S50 to S560
Detailed Description
The following embodiments of the present application are described by specific examples, and other advantages and effects of the present application will be readily apparent to those skilled in the art from the disclosure of the present application. The application is capable of other and different embodiments and its several details are capable of modifications and various changes in detail without departing from the spirit of the application. It is to be noted that the features in the following embodiments and examples may be combined with each other without conflict.
It should be noted that the drawings provided in the following embodiments are only for illustrating the basic idea of the present application, and the drawings only show the components related to the present application and are not drawn according to the number, shape and size of the components in actual implementation, the type, quantity and proportion of each component in actual implementation may be changed freely, and the layout of the components may be more complicated.
The following embodiments of the present application provide a method, a system, a medium, and a device for failover of a MySQL database, which are used to implement master-slave switching of the MySQL database and implement failover of the MySQL database. Fig. 1 is a schematic view showing an application scenario of the failover method of the MySQL database according to the embodiment of the present application. The method for failover of MySQL database according to this embodiment will be described below with reference to the application scenario of fig. 1.
As shown in fig. 1, the failure transfer method of MySQL database of the present embodiment is applied to MySQL database, one MySQL database service is generally a redundant deployment, and includes at least one master database and a plurality of slave databases (slave database 1, slave database 2, \8230;, slave database N). In this embodiment, the MySQL database HAs high available MHA (Master HA, which is served by MHA Manager and MHA Node), and provides an automatic Master Failover (automatic Master failure) function for the MySQL Master-slave replication architecture. In order to realize data transmission, the server and the database are connected in a one-to-one correspondence manner, and the connection technology can be Bluetooth or a local area network and the like. Of course, the connection technology in the embodiment of the present invention may be any connection technology that can connect the servers and the database, and is not limited herein.
In the method for failover of the MySQL database according to this embodiment, a Software Development Kit (SDK) may be configured in high-availability software of the server, and on the basis of the function of MHA master-slave switching provided by the MySQL database, the Software Development Kit (SDK) is configured in available software embedded in the application program terminal, so as to implement the specific steps of the method for failover of the MySQL database according to this embodiment. The functional principles of implementation of the Software Development Kit (SDK) include: the method is used for detecting whether the service of the main database exceeds the limit time length or not, trying to recover the access of the main database by adjusting the database link configuration of a Software Development Kit (SDK), and if the access cannot be recovered, performing master-slave switching by sending an instruction or a master-slave switching technology. And after the master-slave switching is finished and before the domain name is effective, a host configuration is locally established for the new IP, so that the disconnection time of the application program for accessing the database is reduced as much as possible.
The following describes technical solutions in the embodiments of the present application in detail with reference to the drawings in the embodiments of the present application.
Fig. 2 is a schematic flow chart illustrating a failover method of a MySQL database according to an embodiment of the present application. As shown in fig. 2, the method includes the following steps S100 to S400.
Step S100, detecting whether the reaction time length of the current main database exceeds a time length limiting threshold value;
step S200, in response to the response time of the current master database exceeding a time limit threshold, modifying the configuration of the current master database;
step S300, re-detecting whether the reaction time length of the current main database exceeds a limit time length threshold value;
and S400, in response to the response time of the current master database after configuration modification exceeding a time limit threshold, switching the current master database into a slave database.
The following describes the steps S100 to S400 in the failover method of MySQL database according to this embodiment in detail.
And step S100, detecting whether the reaction time length of the current main database exceeds a limit time length threshold value.
In this embodiment, whether the master database has a fault is determined according to the reaction duration of the current master database, so as to determine whether the master database needs to be repaired and whether the slave database is switched to work.
Fig. 3 is a schematic flow chart illustrating detection of reaction duration in the MySQL database failover method according to the embodiment of the present application; specifically, as shown in fig. 3, in the present embodiment, one implementation manner of detecting whether the reaction duration of the current master database exceeds the limit duration threshold includes the following steps S110 to S130.
In step S110, a detection command is generated.
The detection instruction is, but not limited to, a query instruction, a retrieval instruction, a data modification instruction, and the like. For example, a query instruction, such as a query statement, is generated.
And step S120, sending the detection instruction to the current master database so that the current master database operates based on the detection instruction, and returning the operating reaction time length.
For example, the query instruction is sent to the current master database, the current master database executes the corresponding query operation based on the query instruction, and after the execution is finished, the query result is returned.
Step S130, detecting whether the reaction time length exceeds the limit time length threshold.
For example, the time difference from the sending of the query instruction to the receiving of the query result returned by the master database is obtained as the reaction time length of the master database, and whether the reaction time length exceeds the limit time length threshold is detected. Wherein, the limit duration threshold value can be freely set according to the performance of the database.
In the implementation mode of the embodiment, whether the current master database fails or not is determined by sending an instruction to detect the reaction time of the current master database, and the detection is simple and convenient and has high efficiency.
Step S200, responding to the response time of the current master database exceeding the limit time threshold, and modifying the configuration of the current master database.
In an embodiment of the present application, one way of modifying the configuration of the current master database is to modify a link configuration of the current master database; wherein the modifying the link configuration of the current master database comprises decreasing the number of links of the current master database.
Wherein the link configuration is the link configuration of a Software Development Kit (SDK) link main database, namely, the access of the main database is tried to be recovered by adjusting the database link configuration of the Software Development Kit (SDK). The preferred embodiment is to restore the master database by reducing the number of links of the current master database. In the implementation mode, the database is recovered by modifying the link configuration, and the recovery mode is quick and efficient.
Therefore, in the application, when the current master database fails and is not out of service, the configuration of the current master database is modified and adjusted, the access of the master database is tried to be recovered, and the recovery mode is fast and efficient.
After the configuration of the current master database is modified and adjusted, it is detected whether the master database is recovered to normal operation, i.e. the fault is removed, and step S300 is continuously executed. Detecting whether the reaction time length exceeds the limit time length threshold value
Step S300, whether the reaction time length of the current main database exceeds the limit time length threshold value is detected again.
The execution process and principle of step S300 are the same as step S100, i.e. it is equivalent to re-executing step S110 to step S130. I.e. re-detecting if the reaction duration of the current master database after the modification adjustment exceeds the limit duration threshold.
If the reaction time length of the current main database after the redetection, modification and adjustment exceeds the limit time length threshold value, confirming that the fault of the current main database after the redetection, modification and adjustment is not repaired, and the fault still exists, so that the slave database needs to replace the main database to work; if the reaction time length of the current main database after the redetection, modification and adjustment does not exceed the time limit threshold, the fault of the current main database after the redetection, modification and adjustment is confirmed to be repaired, namely the aim of recovering the main database access through the adjustment and the configuration when the main database does not stop the service is fulfilled, the database is recovered through the modification and the link configuration, and the method has the advantages of quick and efficient recovery mode.
When the reaction time length of the current master database after the re-detection modification adjustment exceeds the time limit threshold, it is determined that the fault of the current master database after the re-detection modification adjustment is not repaired and still has a fault, and at this time, the step S400 is continuously performed.
And S400, responding to the condition that the reaction time length of the current master database exceeds a limit time length threshold value after configuration modification, and switching the current master database into a slave database.
In this embodiment, the current master database is switched to the slave database based on a received external instruction or a master-slave switching service of the MySQL database.
For example, an external instruction is generated through a man-machine interface to control the current master database to be switched into the slave database.
Preferably, in this embodiment, the master-slave switching service based on the MySQL database switches the current master database to the slave database. The Master-slave switching service MHA (Master HA, which is served by MHA Manager and MHA Node) provides an automatic Master Failover (automatic Master Failover) function for MySQL Master-slave replication architecture. When the MHA monitors the failure of the master database (master) node, the slave database (slave) node having the latest data therein is promoted to be a new master database (master) node, and during the period, the MHA can avoid the problem of consistency by acquiring additional information from other slave nodes. The MHA also provides an online switching function of a master database (master) node, i.e., switching master/slave database (slave) nodes as needed.
Therefore, in this embodiment, it is first detected whether the service of the master database exceeds the limit duration, the own database link configuration of the Software Development Kit (SDK) is adjusted to try to recover the access of the master database, and if the access fails to be recovered, a master-slave switching is performed by sending an instruction or a master-slave switching technique (such as MHA service).
Therefore, in the method for transferring the MySQL database failure, when the current main database fails and is not out of service, the configuration of the current main database is modified and adjusted to try to recover the access of the main database, and the master-slave switching of the main database can be performed under the condition that the recovery is not performed and the service of the main database is not stopped, so that the MySQL database failure transfer is realized.
In this embodiment, after the current master database is switched to the slave database, it is also necessary to control access to the slave database. Fig. 4 is a schematic flowchart illustrating a process of accessing a slave database in the MySQL database failover method according to the embodiment of the present application. As shown in fig. 4, the method for failover of MySQL database according to the present application further includes the following steps S510 to S53.
Step S510, when a domain name access instruction is received, the IP address of the slave database is obtained;
step S520, host configuration is carried out based on the IP address of the slave database;
step S530, accessing the slave database based on the host configuration.
That is, in this embodiment, after the master-slave switching is completed, before the domain name is validated, a host configuration is locally created for a new IP in the slave database. One example implementation of the host configuration is as follows:
1) Opening a System disk of a computer, generally defaulting to a C disk, entering the C disk, clicking 'Windows', entering a 'System 32' option, clicking 'drivers' and clicking to open a 'hosts' file;
2) The files are opened in a notepad mode, because the host files have very strict requirements on formats, different software is opened, the formats are different, and the configuration is unsuccessful;
3) Inputting a host address (namely a new IP address of the database) to be added, adding the host address into a host file, and adding a "#" before a comment statement if a comment needs to be added into the added address;
4) Saving files, accessing the slave database through a domain name, and inputting an address;
5) And if the host configuration is completed, the slave database cannot be accessed, the host file is opened again, whether the format of the file is correct or not is judged, and if the format of the file is incorrect, the file is stored after being modified and then accessed again.
Fig. 5 is a schematic flowchart illustrating a process of accessing the slave database when the domain name is not valid in the MySQL database failover method according to the embodiment of the present application. As shown in fig. 5, the present embodiment further includes the following steps S540 to S560.
Step S540, detecting whether the domain name is effective; if the validation is valid, the step S550 is continuously executed, and if the validation is not valid, the step S560 is continuously executed, the preset time is waited, and the step S540 is continuously executed.
And step S550, responding to the validity of the domain name, and deleting host configuration.
In this embodiment, after the master-slave switching is completed, a new IP of the slave database is acquired, host configuration is locally performed on the slave database, and after the domain name becomes valid, the host configuration is deleted.
In the method, after the master database and the slave database are switched and before the domain name is not effective, the IP address of the slave database is subjected to host configuration, so that the service of the slave database can be normally accessed through the domain name, and the disconnection time of an application program for accessing the database is shortened as much as possible.
In order to further understand the principle and the implementation manner of the failover method of MySQL database according to this embodiment, an implementation procedure of the failover method of MySQL database according to this embodiment is described below with reference to fig. 6.
As shown in fig. 6, a Software Development Kit (SDK) may be configured in the highly available software of the server, a detection instruction, such as a query instruction, is generated, the query instruction is sent to a current master database (database), the current master database executes a corresponding query operation based on the query instruction, and after the query operation is completed, a query result, that is, a command result, is returned.
And then detecting whether the instruction result is overtime or not, namely detecting whether the reaction time length of the current main database exceeds a time length limiting threshold or not. If yes, modifying the configuration of the current master database, namely attempting to modify configurations such as data links and the like, and re-detecting whether the reaction time length of the current master database exceeds the time length limiting threshold value. If the time is not out, the fault of the current main database after re-detection, modification and adjustment is confirmed to be repaired, namely the purpose of recovering the main database access by adjusting the configuration when the main database is not out of service is realized, the database is recovered by modifying the link configuration, and the method has the advantages of being fast and efficient in recovery mode. If the configuration is modified and the configuration is overtime, the fault of the current main database after re-detection modification and adjustment is not repaired, the fault still exists, the slave database needs to replace the main database to work, and the operation of switching the master database and the slave database is continuously executed.
And in the master-slave database switching, switching the current master database into the slave database based on the received external instruction or master-slave switching service of the MySQL database. Therefore, in the MySQL database failover method, when the current main database fails and is not out of service, the configuration of the current main database is modified and adjusted to try to recover the access of the main database, and the master-slave switching of the main database can be performed under the condition that the current main database fails to be recovered and the main database is not out of service, so that the MySQL database failover is realized.
If the master database and the slave database are successfully switched, the slave database also needs to be controlled to be accessed. And when a domain name access instruction is received, acquiring the IP address of the slave database, performing host configuration based on the IP address of the slave database, and accessing the slave database based on the host configuration. That is, in this embodiment, after the master-slave switching is completed, before the domain name is validated, a host configuration is locally created for the new IP in the slave database.
And then waiting for the domain name to be effective, continuously detecting whether the domain name is effective, and deleting the host configuration when the domain name is effective.
In other words, in this embodiment, after the master-slave switching is completed, a new IP in the slave database is acquired, the host configuration is locally performed for the slave database, and after the domain name becomes valid, the host configuration is deleted.
In the method and the device, after the master database and the slave database are switched and before the domain name is not effective, the IP address of the slave database is subjected to host configuration, so that the service of the slave database can be normally accessed through the domain name, and the disconnection time of an application program accessing the database is shortened as much as possible.
The protection scope of the method for failover of the MySQL database according to the embodiment of the present application is not limited to the execution sequence of the steps listed in this embodiment, and all the solutions implemented by adding, subtracting, and replacing steps in the prior art according to the principles of the present application are included in the protection scope of the present application.
The embodiment of the present application further provides a failover system of a MySQL database, where the failover system of the MySQL database may implement the failover method of the MySQL database described in the present application, but the implementation system of the failover method of the MySQL database described in the present application includes, but is not limited to, the structure of the failover system of the MySQL database recited in the present embodiment, and all structural modifications and replacements in the prior art made according to the principles of the present application are included in the scope of protection of the present application.
Fig. 7 is a schematic structural diagram illustrating a principle of the failover system of the MySQL database according to the embodiment of the present application. As shown in fig. 7, the present embodiment provides a failover system 100 of a MySQL database, where the failover system 100 of the MySQL database includes: a duration detection module 110, a configuration modification module 120 and a database switching module 130.
In this embodiment, the duration detection module 110 is configured to detect whether a reaction duration of the current master database exceeds a time limit threshold; the configuration modification module 120 is configured to modify the configuration of the current master database in response to the response duration of the current master database exceeding a time limit threshold, and enable the duration detection module 110 to detect whether the response duration of the current master database exceeds the time limit threshold again; the database switching module 130 is configured to switch the current master database to the slave database in response to the response time of the current master database after the configuration modification exceeding a time limit threshold.
In the failover system 100 of the MySQL database in the embodiment of the present application, when the current master database fails and is not out of service, the configuration of the current master database is modified and adjusted to try to recover the access of the master database, and when the current master database fails to be recovered and the master database is not out of service, the master-slave switching of the master database may be performed, so as to implement the failover of the MySQL database.
Fig. 8 is a schematic structural diagram of a preferred principle of the failover system 100 of MySQL database according to the embodiment of the present application. In this embodiment, as shown in fig. 8, the failover system 100 of MySQL database further includes: access control module 140. Fig. 9 is a schematic structural diagram illustrating an access control module 140 in the MySQL database failover system 100 according to the embodiment of the present application. As shown in fig. 9, the access control module 140 includes: an IP address acquisition unit 141, a host configuration unit 142, a database access unit 143, and a host configuration deletion unit 144.
In this embodiment, the IP address obtaining unit 141 is configured to obtain the IP address of the slave database when receiving a domain name access instruction; the host configuration unit 142 is configured to perform host configuration based on the IP address of the slave database; the database access unit 143 is configured to access the slave database based on the host configuration; the host configuration deleting unit 144 is configured to detect whether the domain name is in effect, and delete the host configuration in response to the domain name being in effect.
In the method and the device, after the master database and the slave database are switched and before the domain name is not effective, the IP address of the slave database is subjected to host configuration, so that the service of the slave database can be normally accessed through the domain name, and the disconnection time of an application program accessing the database is shortened as much as possible.
In this application, the failover system 100 of the MySQL database may implement the failover method of the MySQL database described in this embodiment, so that specific implementation functions of each module of the failover system 100 of the MySQL database refer to the detailed description of the failover method of the MySQL database, and are not repeated here. However, the implementation system of the failover method of MySQL database described in the present invention includes, but is not limited to, the failover system 100 of MySQL database recited in this embodiment, and it can be clearly understood by those skilled in the art that, for convenience and simplicity of description, the foregoing division of each functional unit and module is merely used as an example, and in practical application, the above function distribution may be completed by different functional units and modules according to needs, that is, the internal structure of the system/apparatus is divided into different functional units or modules to complete all or part of the above described functions.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus, or method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, a module/unit may be divided into only one logical functional division, and an actual implementation may have another division, for example, a plurality of modules or units may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed coupling or direct coupling or communication connection between each other may be an indirect coupling or communication connection through some interfaces, devices or modules or units, and may be in an electrical, mechanical or other form.
The modules/units described as separate parts may or may not be physically separate, and parts displayed as modules/units may or may not be physical modules, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules/units can be selected according to actual needs to achieve the purposes of the embodiments of the present application. For example, functional modules/units in the embodiments of the present application may be integrated into one processing module, or each module/unit may exist alone physically, or two or more modules/units are integrated into one module/unit.
It will be further appreciated by those of ordinary skill in the art that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
As shown in fig. 10, embodiments of the present application provide an electronic device 101, which may be, for example, a computer that includes components such as one or more processors 1001, one or more memories 1002, peripheral interfaces, RF circuitry, audio circuitry, speakers, microphones, input/output (I/O) subsystems, display screens, other output or control devices, and external ports; the computer includes, but is not limited to, personal computers such as desktop computers, notebook computers, tablet computers, smart phones, smart televisions, personal Digital Assistants (PDAs), and the like. In other embodiments, the electronic device may also be a server, and the server may be arranged on one or more entity servers according to various factors such as functions, loads, and the like, or may be formed by a distributed or centralized server cluster, which is not limited in this embodiment.
The electronic device 101 includes: a processor 1001 and a memory 1002; the memory 1002 is used for storing computer programs; the processor 1001 is configured to execute the computer program stored in the memory 1002 to enable the electronic device 101 to execute the steps of the failover method of the MySQL database according to embodiment 1. The specific implementation process of the steps of the failover method of the MySQL database has been described in detail in the embodiments, and is not described herein again.
The processor 1001 is a Central Processing Unit (cpu). The memory 1002 is connected to the processor 1001 through a system bus and is used for communicating with the processor 1001, the memory 1002 is used for storing computer programs, and the processor 1001 is used for operating the computer programs, so that the processor 1001 executes the battery rapid diagnosis method based on the edge calculation. The Memory 1002 may include a Random Access Memory (RAM), and may further include a non-volatile Memory (non-volatile Memory), such as at least one disk Memory.
The embodiment of the application also provides a computer readable storage medium. It will be understood by those of ordinary skill in the art that all or part of the steps in the method for implementing the above embodiments may be implemented by a program instructing a processor, and the program may be stored in a computer-readable storage medium, which is a non-transitory (non-transitory) medium, such as a random access memory, a read only memory, a flash memory, a hard disk, a solid state drive, a magnetic tape (magnetic tape), a floppy disk (floppy disk), an optical disk (optical disk), and any combination thereof. The storage medium may be any available medium that can be accessed by a computer or a data storage device including one or more available media integrated servers, data centers, and the like. The usable medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a Digital Video Disk (DVD)), or a semiconductor medium (e.g., a Solid State Disk (SSD)), among others.
Embodiments of the present application may also provide a computer program product comprising one or more computer instructions. When loaded and executed on a computing device, cause the processes or functions described in accordance with embodiments of the application to occur, in whole or in part. The computer instructions can be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions can be transmitted from one website, computer, or data center to another website, computer, or data center via wired (e.g., coaxial cable, fiber optic, digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means.
When the computer program product is executed by a computer, the computer executes the method of the previous method embodiment. The computer program product may be a software installation package, which may be downloaded and executed on a computer in case it is desired to use the method as described above.
The description of the flow or structure corresponding to each of the above drawings has emphasis, and a part not described in detail in a certain flow or structure may refer to the related description of other flows or structures.
The above embodiments are merely illustrative of the principles and utilities of the present application and are not intended to limit the application. Any person skilled in the art can modify or change the above-described embodiments without departing from the spirit and scope of the present application. Accordingly, it is intended that all equivalent modifications or changes which can be made by those skilled in the art without departing from the spirit and technical concepts disclosed in the present application shall be covered by the claims of the present application.

Claims (10)

1. A failover method of a MySQL database is characterized by comprising the following steps:
detecting whether the reaction time length of the current main database exceeds a limit time length threshold value;
responding to the fact that the reaction duration of the current master database exceeds a limit duration threshold, modifying the configuration of the current master database, and detecting whether the reaction duration of the current master database exceeds the limit duration threshold again;
and switching the current master database into a slave database in response to the response time of the current master database after the configuration modification exceeding a limit time threshold.
2. The method of claim 1, wherein: one implementation manner of detecting whether the reaction duration of the current master database exceeds the limit duration threshold includes:
generating a detection instruction;
sending the detection instruction to the current master database so that the current master database operates based on the detection instruction and returns the operating reaction duration;
detecting whether the reaction time length exceeds the limit time length threshold value.
3. The method of claim 1, wherein: one way of modifying the configuration of the current master database is to modify a link configuration of the current master database; the modifying the link configuration of the current master database includes decreasing the number of links of the current master database.
4. The method of claim 1, wherein: after switching the current master database to the slave database, further comprising:
when a domain name access instruction is received, acquiring the IP address of the slave database;
performing host configuration based on the IP address of the slave database;
accessing the slave database based on the host configuration.
5. The method of claim 4, wherein: further comprising:
detecting whether the domain name is effective;
and deleting the host configuration in response to the domain name being effective.
6. The method of claim 2, wherein: and switching the current master database into the slave database based on the received external instruction or master-slave switching service of the MySQL database.
7. A system for failover of MySQL databases, the system comprising:
the time length detection module is used for detecting whether the reaction time length of the current main database exceeds a limit time length threshold value or not;
the configuration modification module is used for modifying the configuration of the current master database in response to the response time of the current master database exceeding a limit time threshold, and enabling the time detection module to detect whether the response time of the current master database exceeds the limit time threshold again;
and the database switching module is used for switching the current master database into the slave database in response to the response time of the current master database after the configuration modification exceeding a limit time threshold.
8. The system of claim 7, wherein: further comprising: an access control module; the access control module includes:
the IP address acquisition unit is used for acquiring the IP address of the slave database when receiving a domain name access instruction;
a host configuration unit, configured to perform host configuration based on the IP address of the slave database;
a database access unit for accessing the slave database based on the host configuration;
and the host configuration deleting unit is used for detecting whether the domain name is effective or not and deleting the host configuration in response to the effective domain name.
9. An electronic device, characterized in that the electronic device comprises:
a memory storing a computer program;
a processor, communicatively connected to the memory, implementing the method of any of claims 1 to 6 when the computer program is invoked.
10. A computer-readable storage medium, on which a computer program is stored, characterized in that the program, when executed by an electronic device, implements the method of claims 1 to 6.
CN202211267953.5A 2022-10-17 2022-10-17 Method, system, medium and device for failover of MySQL database Pending CN115629921A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211267953.5A CN115629921A (en) 2022-10-17 2022-10-17 Method, system, medium and device for failover of MySQL database

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211267953.5A CN115629921A (en) 2022-10-17 2022-10-17 Method, system, medium and device for failover of MySQL database

Publications (1)

Publication Number Publication Date
CN115629921A true CN115629921A (en) 2023-01-20

Family

ID=84904979

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211267953.5A Pending CN115629921A (en) 2022-10-17 2022-10-17 Method, system, medium and device for failover of MySQL database

Country Status (1)

Country Link
CN (1) CN115629921A (en)

Similar Documents

Publication Publication Date Title
CN108616382B (en) Method and device for upgrading network card firmware, network card and equipment
CN108984349B (en) Method and device for electing master node, medium and computing equipment
US10936295B2 (en) Software update system
US20050193248A1 (en) Computer system for recovering data based on priority of the data
KR20110044858A (en) Maintain data indetermination in data servers across data centers
US8904055B2 (en) Switching control device and switching control method
CN109446169B (en) Double-control disk array shared file system
US11573737B2 (en) Method and apparatus for performing disk management of all flash array server
CN104036043A (en) High availability method of MYSQL and managing node
EP3648405B1 (en) System and method to create a highly available quorum for clustered solutions
CN103973470A (en) Cluster management method and equipment for shared-nothing cluster
KR20210040866A (en) File resource processing method and apparatus, device and medium
CN102457400B (en) Method for preventing split brain phenomenon from occurring on distributed replicated block device (DRBD) resource
WO2020233001A1 (en) Distributed storage system comprising dual-control architecture, data reading method and device, and storage medium
CN112732492A (en) Extraction backup method and system based on cloud database
CN117076196A (en) Database disaster recovery management and control method and device
CN115629921A (en) Method, system, medium and device for failover of MySQL database
CN115543393A (en) Upgrading method, electronic device and storage medium
CN115098324A (en) Hard disk maintenance method, device, equipment and storage medium
CN115292408A (en) Master-slave synchronization method, device, equipment and medium for MySQL database
US9971532B2 (en) GUID partition table based hidden data store system
CN109510867B (en) Data request processing method and device, storage medium and electronic equipment
CN114254035A (en) Database system, data processing method and equipment
CN113467717B (en) Dual-machine volume mirror image management method, device and equipment and readable storage medium
CN112363815B (en) Redis cluster processing method and device, electronic equipment and computer readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination