[go: up one dir, main page]

CN106021030A - Database system and database fault processing method and device - Google Patents

Database system and database fault processing method and device Download PDF

Info

Publication number
CN106021030A
CN106021030A CN201610370627.5A CN201610370627A CN106021030A CN 106021030 A CN106021030 A CN 106021030A CN 201610370627 A CN201610370627 A CN 201610370627A CN 106021030 A CN106021030 A CN 106021030A
Authority
CN
China
Prior art keywords
database
mdl
data base
slave
master database
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
CN201610370627.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.)
IEIT Systems Co Ltd
Original Assignee
Inspur Electronic Information Industry 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 Inspur Electronic Information Industry Co Ltd filed Critical Inspur Electronic Information Industry Co Ltd
Priority to CN201610370627.5A priority Critical patent/CN106021030A/en
Publication of CN106021030A publication Critical patent/CN106021030A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Quality & Reliability (AREA)
  • Computing Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a database system and a database fault processing method and device. The method comprises the steps that 1, at least one slave database is set for a master database in advance; 2, original data in the master database is copied into each slave database in advance; 3, each operation of the master database is obtained in real time; 4, the operation which is the same as the operation of the master database is carried out on each slave database; 5, whether the master database breaks down or not is detected in real time, and if yes, any slave database is used for being substituted for the master database. By means of the database system and the database fault processing method and device, database reliability can be improved.

Description

一种数据库的系统、一种处理数据库故障的方法及装置A database system, a method and device for dealing with database faults

技术领域technical field

本发明涉及计算机技术领域,特别涉及一种数据库的系统、一种处理数据库故障的方法及装置。The invention relates to the field of computer technology, in particular to a database system, a method and a device for processing database faults.

背景技术Background technique

复杂系统对数据库容灾的要求越来越高,大多数的系统只有一个数据库,一旦在运行中出现数据库误操作或者崩溃的问题,会影响整个系统的运行,甚至可能造成宕机,即所谓的单点故障。Complex systems have higher and higher requirements for database disaster recovery. Most systems have only one database. Once the database is misoperated or crashed during operation, it will affect the operation of the entire system and may even cause downtime. single point of failure.

现有技术中当系统中的数据库出现故障时,与数据库相关的服务就会停止运行,对数据库进行维护,数据库恢复正常后,相关的服务才能正常运行。In the prior art, when the database in the system fails, the services related to the database will stop running, the database is maintained, and the related services can only run normally after the database returns to normal.

通过上述描述可见,现有的数据库的可靠性较低。It can be seen from the above description that the reliability of the existing database is low.

发明内容Contents of the invention

本发明实施例提供了一种数据库的系统、一种处理数据库故障的方法及装置,能够提高数据库的可靠性。Embodiments of the present invention provide a database system, a method and a device for dealing with database faults, which can improve the reliability of the database.

第一方面,本发明实施例提供了一种处理数据库故障的方法,包括:In the first aspect, the embodiment of the present invention provides a method for processing database faults, including:

S1:预先为主数据库设置至少一个从数据库;S1: Pre-set at least one slave database for the master database;

S2:预先将所述主数据库中原始数据复制到每个所述从数据库中;S2: Copy the original data in the master database to each of the slave databases in advance;

S3:实时获取所述主数据库的每个操作;S3: Obtain each operation of the master database in real time;

S4:在每个所述从数据库上执行与所述主数据库的操作相同的操作;S4: Execute the same operation as that of the master database on each of the slave databases;

S5:实时检测所述主数据库是否发生故障,如果是,则利用任一所述从数据库代替所述主数据库。S5: Detect in real time whether the master database fails, and if so, use any of the slave databases to replace the master database.

进一步地,在所述S2之前,还包括:Further, before said S2, it also includes:

在所述主数据库中创建复制账户,授予所述复制账户REPLICATIONSLAVE权限;Create a replication account in the master database and grant REPLICATIONSLAVE permission to the replication account;

利用所述复制账户连接所述主数据库;using the replication account to connect to the master database;

所述S2,包括:The S2, including:

利用所述复制账户的REPLICATION SLAVE权限,将所述主数据库中原始数据复制到每个所述从数据库中。Using the REPLICATION SLAVE authority of the replication account, the original data in the master database is replicated to each of the slave databases.

进一步地,在所述S3之前,还包括:开启所述主数据库的二进制日志;Further, before the S3, it also includes: opening the binary log of the master database;

还包括:实时在所述二进制日志中记录所述主数据库的每个操作;It also includes: recording each operation of the main database in the binary log in real time;

所述S3,包括:The S3, including:

实时从所述二进制日志中获取所述主数据库的每个操作。Obtain each operation of the primary database from the binary log in real time.

进一步地,所述利用任一所述从数据库代替所述主数据库,包括:Further, the use of any of the slave databases to replace the master database includes:

将外部对所述主数据库的操作转换为对用于代替所述主数据库的从数据库的操作。An external operation on the master database is converted into an operation on a slave database replacing the master database.

第二方面,本发明实施例提供了一种处理数据库故障的装置,包括:In a second aspect, an embodiment of the present invention provides a device for processing database faults, including:

设置单元,用于为主数据库设置至少一个从数据库;A setting unit is used to set at least one slave database for the master database;

复制单元,用于将所述主数据库中原始数据复制到每个所述从数据库中;a replication unit, configured to replicate the original data in the master database to each of the slave databases;

获取单元,用于实时获取所述主数据库的每个操作;an acquisition unit, configured to acquire each operation of the master database in real time;

执行单元,用于在每个所述从数据库上执行与所述主数据库相同的操作;an execution unit, configured to perform the same operation on each of the slave databases as that of the master database;

检测单元,用于实时检测所述主数据库是否发生故障,当检测到所述主数据库发生故障,利用任一所述从数据库代替所述主数据库。The detection unit is configured to detect in real time whether the primary database fails, and when detecting that the primary database fails, use any of the secondary databases to replace the primary database.

进一步地,还包括:创建单元,用于在所述主数据库中创建复制账户,授予所述复制账户REPLICATION SLAVE权限;Further, it also includes: a creation unit, configured to create a replication account in the master database, and grant the replication account REPLICATION SLAVE permission;

连接单元,用于利用所述复制账户连接所述主数据库;a connection unit, configured to use the replication account to connect to the master database;

所述复制单元,用于利用所述复制账户的REPLICATION SLAVE权限,将所述主数据库中原始数据复制到每个所述从数据库中。The replication unit is configured to use the REPLICATION SLAVE authority of the replication account to replicate the original data in the master database to each of the slave databases.

进一步地,还包括:开启单元,用于开启所述主数据库的二进制日志;Further, it also includes: an opening unit, configured to open the binary log of the master database;

还包括:记录单元,用于实时在所述二进制日志中记录所述主数据库的每个操作;It also includes: a recording unit, configured to record each operation of the master database in the binary log in real time;

所述获取单元,用于实时从所述二进制日志中获取所述主数据库的每个操作。The acquiring unit is configured to acquire each operation of the master database from the binary log in real time.

进一步地,所述检测单元在执行所述利用任一所述从数据库代替所述主数据库时,用于将外部对所述主数据库的操作转换为对用于代替所述主数据库的从数据库的操作。Further, when the detection unit executes the method of using any of the slave databases to replace the master database, it is used to convert external operations on the master database into operations on the slave database used to replace the master database. operate.

第三方面,本发明实施例提供了一种数据库的系统,包括:In a third aspect, an embodiment of the present invention provides a database system, including:

主数据库、至少一个从数据库、如第二方面中任一所述的处理数据库故障的装置。The master database, at least one slave database, and the device for handling database faults described in any one of the second aspect.

进一步地,所述主数据库与所述至少一个从数据库部署在不同的服务器上。Further, the master database and the at least one slave database are deployed on different servers.

在本发明实施例中,为主数据库设置至少一个从数据库,将主数据库中的原始数据复制到每个从数据库中,使得每个从数据库中保存有主数据库的原始数据,在每个从数据库上执行与主数据库的操作相同的操作,使得每个从数据库与主数据库同步,实现从数据库对主数据库的备份,当检测主数据库发送故障时,利用任一从数据库代替主数据库,外部需要操作主数据库的数据时,通过操作从数据库的数据也可以实现,因此,主数据库发生故障也不会影响为外部对主数据库中数据的操作,提高了数据库的可靠性。In an embodiment of the present invention, at least one slave database is set for the master database, and the original data in the master database is copied to each slave database, so that each slave database preserves the original data of the master database, and each slave database Execute the same operation as that of the master database, so that each slave database is synchronized with the master database, and the backup of the slave database to the master database is realized. When the failure of the master database is detected, any slave database is used to replace the master database. External operations are required Data in the master database can also be realized by manipulating the data in the slave database. Therefore, the failure of the master database will not affect external operations on the data in the master database, which improves the reliability of the database.

附图说明Description of drawings

为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are For some embodiments of the present invention, those skilled in the art can also obtain other drawings based on these drawings without creative work.

图1是本发明一实施例提供的一种处理数据库故障的方法的流程图;Fig. 1 is a flow chart of a method for dealing with database faults provided by an embodiment of the present invention;

图2是本发明一实施例提供的另一种处理数据库故障的方法的流程图;Fig. 2 is a flow chart of another method for dealing with database faults provided by an embodiment of the present invention;

图3是本发明一实施例提供的一种处理数据库故障的装置的示意图;Fig. 3 is a schematic diagram of a device for processing database faults provided by an embodiment of the present invention;

图4是本发明一实施例提供的另一种处理数据库故障的装置的示意图;FIG. 4 is a schematic diagram of another device for handling database faults provided by an embodiment of the present invention;

图5是本发明一实施例提供的一种数据库的系统的示意图。Fig. 5 is a schematic diagram of a database system provided by an embodiment of the present invention.

具体实施方式detailed description

为使本发明实施例的目的、技术方案和优点更加清楚,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例,基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动的前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments It is a part of the embodiments of the present invention, but not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative work belong to the protection of the present invention. scope.

如图1所示,本发明实施例提供了一种处理数据库故障的方法,该方法可以包括以下步骤:As shown in Figure 1, the embodiment of the present invention provides a method for processing database faults, the method may include the following steps:

S1:预先为主数据库设置至少一个从数据库;S1: Pre-set at least one slave database for the master database;

S2:预先将所述主数据库中原始数据复制到每个所述从数据库中;S2: Copy the original data in the master database to each of the slave databases in advance;

S3:实时获取所述主数据库的每个操作;S3: Obtain each operation of the master database in real time;

S4:在每个所述从数据库上执行与所述主数据库的操作相同的操作;S4: Execute the same operation as that of the master database on each of the slave databases;

S5:实时检测所述主数据库是否发生故障,如果是,则利用任一所述从数据库代替所述主数据库。S5: Detect in real time whether the master database fails, and if so, use any of the slave databases to replace the master database.

在本发明实施例中,为主数据库设置至少一个从数据库,将主数据库中的原始数据复制到每个从数据库中,使得每个从数据库中保存有主数据库的原始数据,在每个从数据库上执行与主数据库的操作相同的操作,使得每个从数据库与主数据库同步,实现从数据库对主数据库的备份,当检测主数据库发送故障时,利用任一从数据库代替主数据库,外部需要操作主数据库的数据时,通过操作从数据库的数据也可以实现,因此,主数据库发生故障也不会影响为外部对主数据库中数据的操作,提高了数据库的可靠性。In an embodiment of the present invention, at least one slave database is set for the master database, and the original data in the master database is copied to each slave database, so that each slave database preserves the original data of the master database, and each slave database Execute the same operation as that of the master database, so that each slave database is synchronized with the master database, and the backup of the slave database to the master database is realized. When the failure of the master database is detected, any slave database is used to replace the master database. External operations are required Data in the master database can also be realized by manipulating the data in the slave database. Therefore, the failure of the master database will not affect external operations on the data in the master database, which improves the reliability of the database.

在本发明一实施例中,在所述S2之前,还包括:In an embodiment of the present invention, before S2, it also includes:

在所述主数据库中创建复制账户,授予所述复制账户REPLICATIONSLAVE权限;Create a replication account in the master database and grant REPLICATIONSLAVE permission to the replication account;

利用所述复制账户连接所述主数据库;using the replication account to connect to the master database;

所述S2,包括:The S2, including:

利用所述复制账户的REPLICATION SLAVE权限,将所述主数据库中原始数据复制到每个所述从数据库中。Using the REPLICATION SLAVE authority of the replication account, the original data in the master database is replicated to each of the slave databases.

在本实施例中,由于对主数据库的操作需要有相应的权限,为了复制主数据库中的原始数据,通过创建复制账户来提供相应的REPLICATIONSLAVE权限。当通过复制账户连接主数据库时,即可以复制主数据库中的原始数据。具体的,任一从数据库可以利用该复制账号和该复制账户的密码链接到主数据库。In this embodiment, because operations on the master database require corresponding permissions, in order to replicate the original data in the master database, a replication account is created to provide corresponding REPLICATIONSLAVE permissions. When connecting to the master database through a replication account, the original data in the master database can be replicated. Specifically, any slave database can use the replication account and the password of the replication account to link to the master database.

另外,为了避免使得主数据库中的原始数据能够全部复制到每个从数据库中,在步骤S2之前,还包括:禁止对主数据库和每个从数据库进行写操作。这样可以保证主数据库和每个从数据库不会写入新的数据,保证了主数据库中的原始数据能够全部复制到每个从数据库中,使得主数据库和每个从数据库中的数据相同。In addition, in order to avoid copying all the original data in the master database to each slave database, before step S2, it also includes: prohibiting writing operations on the master database and each slave database. This can ensure that the master database and each slave database will not write new data, and ensure that the original data in the master database can be copied to each slave database, so that the data in the master database and each slave database are the same.

在本发明一实施例中,在所述S3之前,还包括:In an embodiment of the present invention, before the S3, it also includes:

开启所述主数据库的二进制日志;Open the binary log of the primary database;

还包括:实时在所述二进制日志中记录所述主数据库的每个操作;It also includes: recording each operation of the main database in the binary log in real time;

所述S3,包括:The S3, including:

实时从所述二进制日志中获取所述主数据库的每个操作。Obtain each operation of the primary database from the binary log in real time.

在本实施例中,开启所述主数据库的二进制日志可以通过对主数据库进行配置来实现,为了使配置生效,一般需要重启主数据库。在主数据库的二进制日志中记录主数据库的每个操作,对操作的记录可以通过事件的形式来记录。具体的,在二进制日志中记录主数据库的所有的DDL(Data DefinitionLanguage,数据定义语言)和DML(Data Manipulation Language,数据操纵语言)。In this embodiment, enabling the binary log of the master database can be implemented by configuring the master database. In order to make the configuration take effect, the master database generally needs to be restarted. Each operation of the main database is recorded in the binary log of the main database, and the record of the operation can be recorded in the form of an event. Specifically, all DDL (Data Definition Language, Data Definition Language) and DML (Data Manipulation Language, Data Manipulation Language) of the master database are recorded in the binary log.

另外,为了使得主数据库与任一从数据库连接,还可以对主数据库进行配置,具体的,配置从数据库的标识,例如:从数据库的地址。针对从数据库也进行相似的配置,具体的,配置主数据库的标识,例如:主数据库的地址。In addition, in order to connect the master database to any slave database, the master database can also be configured, specifically, the identifier of the slave database, for example, the address of the slave database. A similar configuration is also performed on the slave database, specifically, the identity of the master database is configured, for example: the address of the master database.

在实现实时从所述二进制日志中获取所述主数据库的每个操作时,可以通过设置获取线程自动获取,具体的,通过获取线程轮询二进制日志,获取二进制日志中的每个操作。When obtaining each operation of the main database from the binary log in real time, it can be automatically obtained by setting the obtaining thread. Specifically, each operation in the binary log is obtained by polling the binary log through the obtaining thread.

在执行S4时,可以设置执行线程,通过执行线程执行获取到的每个操作。这样保证了主数据库和从数据库中数据的一致。When executing S4, an execution thread may be set, and each acquired operation may be executed through the execution thread. This ensures the consistency of the data in the master database and the slave database.

在本发明一实施例中,所述利用任一所述从数据库代替所述主数据库,包括:In an embodiment of the present invention, the use of any of the slave databases to replace the master database includes:

将外部对所述主数据库的操作转换为对用于代替所述主数据库的从数据库的操作。An external operation on the master database is converted into an operation on a slave database replacing the master database.

在本实施例中,将主数据库切换到从数据库,由从数据库实现主数据库的所有功能。具体的,可以将外部访问的数据库的地址由主数据库的地址修改为用于代替所述主数据库的从数据库的地址。举例来说,外部的软件A需要对主数据库的数据进行操作,软件A需要根据已经配置的主数据库的地址来访问主数据库,由于主数据库发生故障,无法实现访问主数据库,将主数据库与从数据库进行切换,将软件A的配置中数据库的地址修改为从数据库的地址,对于软件A来说,其操作并没有发生变化,仍然根据配置的数据库的地址进行访问。In this embodiment, the master database is switched to the slave database, and all the functions of the master database are implemented by the slave database. Specifically, the address of the externally accessed database may be changed from the address of the master database to the address of the slave database used to replace the master database. For example, external software A needs to operate the data of the master database. Software A needs to access the master database according to the address of the configured master database. Because the master database fails, it cannot access the master database. The database is switched, and the address of the database in the configuration of software A is changed to the address of the slave database. For software A, its operation has not changed, and access is still performed according to the address of the configured database.

以MYSQL为例,如图2所示,本发明实施例提供了一种处理数据库故障的方法,在本发明实施例中,主数据库和从数据库都为MYSQL,该方法可以包括以下步骤:Take MYSQL as an example, as shown in Figure 2, the embodiment of the present invention provides a kind of method for processing database failure, in the embodiment of the present invention, master database and slave database are all MYSQL, and this method can comprise the following steps:

步骤201:预先为主数据库设置从数据库。Step 201: Pre-setting the slave database for the master database.

主数据库和从数据库部署在不同的服务器,这样主数据库由于所在服务器故障而无法正常工作时,从数据库也可以实现对主数据库的备份。避免当主数据库与从数据库都在同一个服务器上时,由于所在的服务器故障而导致主数据库与从数据库都无法正常工作。这样,即使主数据库所在的服务器发生宕机等故障时,可以成功的切换的从数据库,使从数据库代替主数据库。The master database and the slave database are deployed on different servers, so that when the master database cannot work normally due to the failure of the server where it is located, the slave database can also realize the backup of the master database. Avoid when the master database and the slave database are on the same server, the master database and the slave database cannot work normally due to the failure of the server. In this way, even if the server where the master database is located has a failure such as downtime, the slave database can be successfully switched so that the slave database can replace the master database.

另外,为了保证主数据库与从数据库之间的数据复制成功,并为了保证从数据库能够完全替代主服务器,需要确保主数据库与从数据库的版本兼容,具体的,保证从数据库的版本与主数据库版本相同或者从数据库的版本比主数据库版本更高。In addition, in order to ensure the success of data replication between the master database and the slave database, and to ensure that the slave database can completely replace the master server, it is necessary to ensure that the versions of the master database and the slave database are compatible, specifically, to ensure that the version of the slave database is compatible with the master database version Same or the version of the slave database is higher than the version of the master database.

步骤202:在主数据库中创建复制账户,授予复制账户REPLICATIONSLAVE权限。Step 202: Create a replication account in the primary database, and grant REPLICATIONSLAVE permission to the replication account.

具体的,复制账户具有REPLICATION SLAVE权限后,即可复制主数据库中的原始数据。Specifically, after the replication account has the REPLICATION SLAVE authority, the original data in the primary database can be replicated.

步骤203:利用复制账户连接主数据库。Step 203: use the replication account to connect to the master database.

具体的,可以利用复制账户将从数据库与主数据库连接。Specifically, a replication account can be used to connect the slave database to the master database.

步骤204:利用复制账户的REPLICATION SLAVE权限,将主数据库中原始数据复制到从数据库中。Step 204: Using the REPLICATION SLAVE authority of the replication account, the original data in the master database is copied to the slave database.

该过程可以由从数据库来完成。This process can be done from the database.

步骤205:开启主数据库的二进制日志。Step 205: Open the binary log of the primary database.

二进制日志中通过二进制来记录相应的信息。The corresponding information is recorded in the binary log through binary.

步骤206:实时在二进制日志中记录主数据库的每个操作。Step 206: Record each operation of the master database in the binary log in real time.

步骤207:实时从二进制日志中获取主数据库的每个操作。Step 207: Obtain each operation of the primary database from the binary log in real time.

该步骤可以由从数据库来实现。具体地,实时轮询二进制日志,获取二进制日志中的记录。This step can be implemented from the database. Specifically, the binary log is polled in real time to obtain records in the binary log.

步骤208:在从数据库上执行与主数据库的操作相同的操作。Step 208: Execute the same operation as that of the master database on the slave database.

通过该步骤可以使得主数据库与从数据库的数据保持同步,使得从数据库称为主数据库的备份。Through this step, the data of the master database and the slave database can be kept in sync, so that the slave database is called the backup of the master database.

步骤209:实时检测主数据库是否发生故障,如果是,则利用从数据库代替主数据库。Step 209: Detect in real time whether the master database fails, and if so, replace the master database with the slave database.

举例来说,应用A需要读取主数据库中的数据A,主数据库发生故障后,应用A直接从从数据库中读取数据A。对于应用A来说,可以将应用A的数据库的地址由主数据库的地址修改为从数据库的地址来实现从数据库代替主数据库。For example, application A needs to read data A in the primary database. After the primary database fails, application A directly reads data A from the secondary database. For application A, the address of the database of application A can be changed from the address of the master database to the address of the slave database to realize that the slave database replaces the master database.

具体的,外部需要操作主数据库的应用都切换为对从数据库进行操作。该步骤可以通过中间件来实现,该中间件将对主数据库的操作转换为对从数据库的操作。Specifically, external applications that need to operate the master database are switched to operate on the slave database. This step can be realized by middleware, which converts the operation on the master database into the operation on the slave database.

在本发明实施例中,可以利用MYSQL的asynchronous replication功能,将主数据库的数据复制到从数据库中。本发明实施例中对数据库的操作可以包括:读取、写入、删除、修改、查询等。In the embodiment of the present invention, the asynchronous replication function of MYSQL can be used to replicate the data of the master database to the slave database. Operations on the database in the embodiment of the present invention may include: reading, writing, deleting, modifying, querying, and the like.

本发明实施例可以有效的解决单点故障的问题。当主数据库出现问题时,可以迅速切换到从数据库,保证系统正常运行,简单可靠。The embodiment of the present invention can effectively solve the problem of a single point of failure. When there is a problem with the master database, it can be quickly switched to the slave database to ensure the normal operation of the system, which is simple and reliable.

如图3、图4所示,本发明实施例提供了一种处理数据库故障的装置。装置实施例可以通过软件实现,也可以通过硬件或者软硬件结合的方式实现。从硬件层面而言,如图3所示,为本发明实施例提供的一种处理数据库故障的装置所在设备的一种硬件结构图,除了图3所示的处理器、内存、网络接口、以及非易失性存储器之外,实施例中装置所在的设备通常还可以包括其他硬件,如负责处理报文的转发芯片等等。以软件实现为例,如图4所示,作为一个逻辑意义上的装置,是通过其所在设备的CPU将非易失性存储器中对应的计算机程序指令读取到内存中运行形成的。本实施例提供的一种处理数据库故障的装置,包括:As shown in FIG. 3 and FIG. 4 , the embodiment of the present invention provides a device for handling database faults. The device embodiments can be implemented by software, or by hardware or a combination of software and hardware. From the perspective of hardware, as shown in Figure 3, it is a hardware structural diagram of the device where the device for processing database faults provided by the embodiment of the present invention is located, except for the processor, memory, network interface, and In addition to the non-volatile memory, the device where the device in the embodiment is located may generally include other hardware, such as a forwarding chip responsible for processing packets, and the like. Taking software implementation as an example, as shown in Figure 4, as a device in a logical sense, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory for operation by the CPU of the device where it is located. A device for processing database faults provided in this embodiment includes:

设置单元401,用于为主数据库设置至少一个从数据库;A setting unit 401, configured to set at least one slave database for the master database;

复制单元402,用于将所述主数据库中原始数据复制到每个所述从数据库中;a replication unit 402, configured to replicate the original data in the master database to each of the slave databases;

获取单元403,用于实时获取所述主数据库的每个操作;An acquisition unit 403, configured to acquire each operation of the master database in real time;

执行单元404,用于在每个所述从数据库上执行与所述主数据库相同的操作;an execution unit 404, configured to perform the same operation on each of the slave databases as that of the master database;

检测单元405,用于实时检测所述主数据库是否发生故障,当检测到所述主数据库发生故障,利用任一所述从数据库代替所述主数据库。The detection unit 405 is configured to detect in real time whether the master database fails, and when it is detected that the master database fails, use any of the slave databases to replace the master database.

在本发明一实施例中,还包括:创建单元,用于在所述主数据库中创建复制账户,授予所述复制账户REPLICATION SLAVE权限;In an embodiment of the present invention, it further includes: a creation unit, configured to create a replication account in the master database, and grant the replication account REPLICATION SLAVE permission;

连接单元,用于利用所述复制账户连接所述主数据库;a connection unit, configured to use the replication account to connect to the primary database;

所述复制单元,用于利用所述复制账户的REPLICATION SLAVE权限,将所述主数据库中原始数据复制到每个所述从数据库中。The replication unit is configured to use the REPLICATION SLAVE authority of the replication account to replicate the original data in the master database to each of the slave databases.

在本发明一实施例中,还包括:开启单元,用于开启所述主数据库的二进制日志;In an embodiment of the present invention, it also includes: an opening unit, configured to open the binary log of the master database;

还包括:记录单元,用于实时在所述二进制日志中记录所述主数据库的每个操作;It also includes: a recording unit, configured to record each operation of the master database in the binary log in real time;

所述获取单元,用于实时从所述二进制日志中获取所述主数据库的每个操作。The acquiring unit is configured to acquire each operation of the master database from the binary log in real time.

在本发明一实施例中,所述检测单元在执行所述利用任一所述从数据库代替所述主数据库时,用于将外部对所述主数据库的操作转换为对用于代替所述主数据库的从数据库的操作。In an embodiment of the present invention, the detection unit is configured to convert an external operation on the master database into an operation for replacing the master database by using any of the slave databases to replace the master database. Database operations from the database.

本发明实施例提供了一种数据库的系统,包括:The embodiment of the present invention provides a database system, including:

主数据库、至少一个从数据库、本发明实施例中任一的处理数据库故障的装置。The master database, at least one slave database, and any device for handling database failures in the embodiments of the present invention.

如图5所示,本发明实施例提供的一种数据库的系统,包括:As shown in Figure 5, a database system provided by an embodiment of the present invention includes:

主数据库501、从数据库502、本发明实施例中任一的处理数据库故障的装置503。The master database 501, the slave database 502, and the device 503 for processing database faults in any one of the embodiments of the present invention.

在本发明一实施例中,所述主数据库与所述至少一个从数据库部署在不同的服务器上。In an embodiment of the present invention, the master database and the at least one slave database are deployed on different servers.

上述装置内的各单元之间的信息交互、执行过程等内容,由于与本发明方法实施例基于同一构思,具体内容可参见本发明方法实施例中的叙述,此处不再赘述。The information exchange and execution process among the units in the above-mentioned device are based on the same concept as the method embodiment of the present invention, and the specific content can refer to the description in the method embodiment of the present invention, and will not be repeated here.

本发明各个实施例至少具有如下有益效果:Various embodiments of the present invention have at least the following beneficial effects:

1、在本发明实施例中,为主数据库设置至少一个从数据库,将主数据库中的原始数据复制到每个从数据库中,使得每个从数据库中保存有主数据库的原始数据,在每个从数据库上执行与主数据库的操作相同的操作,使得每个从数据库与主数据库同步,实现从数据库对主数据库的备份,当检测主数据库发送故障时,利用任一从数据库代替主数据库,外部需要操作主数据库的数据时,通过操作从数据库的数据也可以实现,因此,主数据库发生故障也不会影响为外部对主数据库中数据的操作,提高了数据库的可靠性。1. In the embodiment of the present invention, at least one slave database is set for the master database, and the original data in the master database is copied to each slave database, so that each slave database preserves the original data of the master database. Perform the same operations on the slave database as the master database, so that each slave database is synchronized with the master database, and the backup of the slave database to the master database is realized. When detecting the failure of the master database, any slave database is used to replace the master database. When it is necessary to operate the data of the master database, it can also be realized by manipulating the data of the slave database. Therefore, the failure of the master database will not affect the external operation of the data in the master database, which improves the reliability of the database.

2、本发明实施例可以有效的解决单点故障的问题,当主数据库出现问题时,可以迅速切换到从数据库,保证系统正运行,简单可靠。2. The embodiment of the present invention can effectively solve the problem of a single point of failure. When a problem occurs in the master database, it can quickly switch to the slave database to ensure that the system is running, which is simple and reliable.

需要说明的是,在本文中,诸如第一和第二之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个〃·····”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同因素。It should be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is a relationship between these entities or operations. There is no such actual relationship or sequence. Furthermore, the term "comprises", "comprises" or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, article or apparatus comprising a set of elements includes not only those elements, but also includes elements not expressly listed. other elements of or also include elements inherent in such a process, method, article, or device. Without further limitations, an element defined by the phrase "comprising a" does not exclude the presence of additional identical elements in the process, method, article or apparatus comprising said element.

本领域普通技术人员可以理解:实现上述方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成,前述的程序可以存储在计算机可读取的存储介质中,该程序在执行时,执行包括上述方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质中。Those of ordinary skill in the art can understand that all or part of the steps to realize the above method embodiments can be completed by program instructions related hardware, and the aforementioned programs can be stored in a computer-readable storage medium. When the program is executed, the It includes the steps of the above method embodiments; and the aforementioned storage medium includes: ROM, RAM, magnetic disk or optical disk and other various media that can store program codes.

最后需要说明的是:以上所述仅为本发明的较佳实施例,仅用于说明本发明的技术方案,并非用于限定本发明的保护范围。凡在本发明的精神和原则之内所做的任何修改、等同替换、改进等,均包含在本发明的保护范围内。Finally, it should be noted that the above descriptions are only preferred embodiments of the present invention, and are only used to illustrate the technical solution of the present invention, and are not used to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present invention are included in the protection scope of the present invention.

Claims (10)

1. the method processing database failure, it is characterised in that including:
S1: for MDL, at least one is set from data base in advance;
S2: in advance initial data in described MDL is copied to each described from data base;
S3: obtain each operation of described MDL in real time;
S4: in each described operation that execution is identical with the operation of described MDL from data base;
S5: in real time detect whether described MDL breaks down, if it is, utilize arbitrary described from Data base replaces described MDL.
Method the most according to claim 1, it is characterised in that
Before described S2, also include:
Described MDL creates and replicates account, authorize described duplication account REPLICATION SLAVE authority;
Described duplication account is utilized to connect described MDL;
Described S2, including:
Utilize the REPLICATION SLAVE authority of described duplication account, by described MDL Central Plains Beginning data copy to each described from data base.
Method the most according to claim 1, it is characterised in that
Before described S3, also include: open the binary log of described MDL;
Also include: in described binary log, record each operation of described MDL in real time;
Described S3, including:
Each operation of described MDL is obtained in real time from described binary log.
4. according to described method arbitrary in claim 1-3, it is characterised in that
Described utilization arbitrary described replaces described MDL from data base, including:
The operation of described MDL is converted to by outside to be used for replacing described MDL from data The operation in storehouse.
5. the device processing database failure, it is characterised in that including:
Unit is set, for arranging at least one from data base for MDL;
Copied cells, each described from data base for initial data in described MDL is copied to;
Acquiring unit, for each operation of the described MDL of acquisition in real time;
Performance element, in each described operation that execution is identical with described MDL from data base;
For in real time, detector unit, detects whether described MDL breaks down, when described master being detected Data base breaks down, and utilizes and arbitrary described replaces described MDL from data base.
Device the most according to claim 5, it is characterised in that
Also include: creating unit, replicate account for creating in described MDL, authorize described multiple Account REPLICATION SLAVE authority processed;
Connect unit, be used for utilizing described duplication account to connect described MDL;
Described copied cells, for utilizing the REPLICATION SLAVE authority of described duplication account, Initial data in described MDL is copied to each described from data base.
Device the most according to claim 5, it is characterised in that
Also include: open unit, for opening the binary log of described MDL;
Also include: record unit, for recording described MDL in described binary log in real time Each operation;
Described acquiring unit, for obtaining each of described MDL in real time from described binary log Operation.
8. according to described device arbitrary in claim 5-7, it is characterised in that
Described detector unit perform described utilize arbitrary described replace described MDL from data base time, For the operation of described MDL is converted to by outside to be used for replacing described MDL from data The operation in storehouse.
9. the system of a data base, it is characterised in that including:
MDL, at least one is from data base, process data as described in arbitrary claim 5-8 The device of storehouse fault.
System the most according to claim 9, it is characterised in that including:
Described MDL with described at least one from data base dispose on a different server.
CN201610370627.5A 2016-05-30 2016-05-30 Database system and database fault processing method and device Pending CN106021030A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610370627.5A CN106021030A (en) 2016-05-30 2016-05-30 Database system and database fault processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610370627.5A CN106021030A (en) 2016-05-30 2016-05-30 Database system and database fault processing method and device

Publications (1)

Publication Number Publication Date
CN106021030A true CN106021030A (en) 2016-10-12

Family

ID=57092621

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610370627.5A Pending CN106021030A (en) 2016-05-30 2016-05-30 Database system and database fault processing method and device

Country Status (1)

Country Link
CN (1) CN106021030A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108243209A (en) * 2016-12-23 2018-07-03 深圳市优朋普乐传媒发展有限公司 A kind of method of data synchronization and device
CN108932338A (en) * 2018-07-11 2018-12-04 北京百度网讯科技有限公司 Data-updating method, device, equipment and medium
WO2019047072A1 (en) * 2017-09-06 2019-03-14 富璟科技(深圳)有限公司 Database detection method and terminal
CN110019500A (en) * 2017-08-21 2019-07-16 东软集团股份有限公司 A kind of copy group method for monitoring state, device, equipment and storage medium
CN112306794A (en) * 2020-09-28 2021-02-02 国网吉林省电力有限公司信息通信公司 Automatic processing method and device for typical fault scene of database

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101414946A (en) * 2008-11-21 2009-04-22 上海爱数软件有限公司 Method and medium server for remote data backup
US20120109906A1 (en) * 2006-12-07 2012-05-03 Robert Edward Wagner Method for identifying logical data discrepancies between database replicas in a database cluster using enhanced transaction logging
US20130117237A1 (en) * 2011-11-07 2013-05-09 Sap Ag Distributed Database Log Recovery
US20140164831A1 (en) * 2010-12-23 2014-06-12 Mongodb, Inc. Method and apparatus for maintaining replica sets
CN105095486A (en) * 2015-08-17 2015-11-25 浪潮(北京)电子信息产业有限公司 Cluster database disaster recovery method and device
CN105468475A (en) * 2015-11-16 2016-04-06 北京奇虎科技有限公司 Backup method and backup device of database

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120109906A1 (en) * 2006-12-07 2012-05-03 Robert Edward Wagner Method for identifying logical data discrepancies between database replicas in a database cluster using enhanced transaction logging
CN101414946A (en) * 2008-11-21 2009-04-22 上海爱数软件有限公司 Method and medium server for remote data backup
US20140164831A1 (en) * 2010-12-23 2014-06-12 Mongodb, Inc. Method and apparatus for maintaining replica sets
US20130117237A1 (en) * 2011-11-07 2013-05-09 Sap Ag Distributed Database Log Recovery
CN105095486A (en) * 2015-08-17 2015-11-25 浪潮(北京)电子信息产业有限公司 Cluster database disaster recovery method and device
CN105468475A (en) * 2015-11-16 2016-04-06 北京奇虎科技有限公司 Backup method and backup device of database

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
简简单单: "mysql数据库主从复制部署笔记", 《HTTP://WWW.111CN.NET/DATABASE/MYSQL/59749.HTM》 *

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108243209A (en) * 2016-12-23 2018-07-03 深圳市优朋普乐传媒发展有限公司 A kind of method of data synchronization and device
CN110019500A (en) * 2017-08-21 2019-07-16 东软集团股份有限公司 A kind of copy group method for monitoring state, device, equipment and storage medium
WO2019047072A1 (en) * 2017-09-06 2019-03-14 富璟科技(深圳)有限公司 Database detection method and terminal
CN108932338A (en) * 2018-07-11 2018-12-04 北京百度网讯科技有限公司 Data-updating method, device, equipment and medium
CN108932338B (en) * 2018-07-11 2021-08-10 北京百度网讯科技有限公司 Data updating method, device, equipment and medium
CN112306794A (en) * 2020-09-28 2021-02-02 国网吉林省电力有限公司信息通信公司 Automatic processing method and device for typical fault scene of database

Similar Documents

Publication Publication Date Title
WO2022063284A1 (en) Data synchronization method and apparatus, device, and computer-readable medium
US20190243806A1 (en) System and method for using local storage to emulate centralized storage
CN102810111B (en) A kind of oracle database service high available implementation method and system of keeping
CN106021030A (en) Database system and database fault processing method and device
CN106775602B (en) A code publishing method and device
CN106933843B (en) Database heartbeat detection method and device
JP6097880B2 (en) Byzantine fault tolerance data replication method and system
CN111858468B (en) Distributed file system metadata verification method, system, terminal and storage medium
CN107608826A (en) A kind of fault recovery method, device and the medium of the node of storage cluster
US11079960B2 (en) Object storage system with priority meta object replication
WO2017097233A1 (en) Fault tolerance method for data storage load and iptv system
CN105260265A (en) Fusion snapshot realization method and fusion snapshot realization system
CN106789180A (en) The service control method and device of a kind of meta data server
CN108595287B (en) Data truncation method and device based on erasure codes
US8762662B1 (en) Method and apparatus for application migration validation
CN106325768A (en) Dual storage system and method
CN106997305B (en) A transaction processing method and device
CN105608150A (en) Business data processing method and system
CN105938446B (en) A fault-tolerant approach to data replication based on RDMA and hardware transactional memory support
CN110858168A (en) Cluster node fault processing method and device and cluster node
CN108959604B (en) Method, apparatus and computer readable storage medium for maintaining database cluster
US11093465B2 (en) Object storage system with versioned meta objects
US11074002B2 (en) Object storage system with meta object replication
CN107888430B (en) Virtual machine management operation synchronization method and device
CN105760456A (en) Method and device for maintaining data consistency

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20161012

WD01 Invention patent application deemed withdrawn after publication