MySQL database switching methods and related devices

By probing and constructing the minimal common collation set C_common through the proxy layer, the incompatibility of collation_id caused by version differences in the master-slave architecture of MySQL database is resolved, achieving lossless master-slave switchover and rollback, and ensuring the compatibility of binlog and the stability of the replication link.

CN123115168APending Publication Date: 2026-11-17CTRIP TRAVEL NETWORK TECH SHANGHAI0
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611552184.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-08
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

In a MySQL database master-slave architecture, when the source instance and the target instance have different master version numbers, the incompatibility of collation_id can cause the target instance to fail to parse binlog and the replication link to be interrupted. Existing technologies lack an overall guarantee for the consistency of collation_id in binlog during the switchover and rollback bidirectional links.

Method used

The proxy layer detects the major version numbers of the source and target instances and their supported collation_id sets, constructs a minimum common collation set C_common, and normalizes the character sets of the backend connection and client session after the handshake. It then verifies whether the collation_id in the active session and binlog is within C_common. If so, it performs a switch or rollback; otherwise, it postpones or rewrites the session.

Benefits of technology

It enables lossless bidirectional switching and rollback between instances with different major version numbers, eliminating the risk of replication interruption caused by incompatible collation_id, without requiring modification of the MySQL server source code or application-side driver.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123115168A_ABST
    Figure CN123115168A_ABST
Patent Text Reader

Abstract

This application provides a MySQL database switching method and related apparatus. The method includes: when establishing a backend connection with a backend MySQL instance, the proxy layer probes the MySQL version string of the backend MySQL instance, obtains the set of `collation_id` supported by the major version number, and constructs a capability table; based on the intersection of the `collation_id` sets in the capability tables of all MySQL instances within the same switching domain, it determines the minimum common `collation` set `C_common`; it issues a character set normalization instruction to the backend connection, where the `collation_id` is taken from `C_common`; it injects the character set normalization instruction into the client session; in response to a master-slave switching instruction or a rollback instruction, if the `collation_id` of the currently active session and the `collation_id` in the binlog of the link to be switched both fall within `C_common`, then a traffic switch is performed. This application ensures that the `collation_id` recorded in the binlog of the cross-version switching and rollback bidirectional link always falls within the set commonly supported by both versions, eliminating the risk of replication interruption caused by `collation_id` incompatibility, and achieving database switching without modifying the MySQL server-side source code or application-side driver.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of database technology, and more specifically, to a method and apparatus for switching MySQL databases. Background Technology

[0002] Upgrading a MySQL database from a lower version to a higher version is a common requirement in MySQL database operation and maintenance. For example, upgrading from MySQL 5.7 to MySQL 8.0 typically uses a master-slave architecture, routing application traffic to the backend MySQL instance through a database proxy layer, and performing master-slave failover or rollback operations during the upgrade process. However, MySQL 5.7 and MySQL 8.0 differ in the range of supported character sets and collation identifiers, i.e., collation_id. MySQL 5.7 supports a collation_id range of 1 to 247, while MySQL 8.0 extends this to 248 to 311 and introduces collations such as utf8mb4_0900_ai_ci with a collation_id of 255. When a MySQL 8.0 instance generates binary logs (binlog) as the master instance, the QUERY_EVENT event header of the binlog may record the character set number with a collation_id of 255. If a MySQL 5.7 instance is used as a slave instance to rebuild the replication link for rollback, the MySQL 5.7 instance will report an error when parsing the binlog because it cannot recognize the collation_id as 255, causing the replication link to be interrupted.

[0003] In existing technologies, the global default character set configuration of the proxy layer cannot constrain the situation where a single session is overwritten with the MySQL 8.0 version-specific collation_id after the handshake. The SET NAMES statement specified by the application side also cannot constrain the character set negotiation between the proxy layer and the backend server, and there is a lack of overall guarantee for the consistency of collation_id in the binlog during the switching and rollback bidirectional links.

[0004] It should be noted that the information disclosed in the background section above is only used to enhance the understanding of the background of this application, and therefore may include information that does not constitute prior art known to those skilled in the art. Summary of the Invention

[0005] This application provides a MySQL database switching method and related apparatus to solve the problem that when the source instance and the target instance have different major version numbers in a MySQL database master-slave architecture, the target instance fails to parse binlog and the replication link is interrupted due to incompatible collation_id. This enables bidirectional lossless execution of master-slave switching and rollback.

[0006] According to one aspect of this application, a MySQL database switching method is provided, applied to a proxy layer located between the application side and the MySQL cluster, comprising: when establishing a backend connection with a backend MySQL instance, the proxy layer probes the MySQL version string of the backend MySQL instance, obtains the major version number and the set of collation_ids supported by the major version number based on the MySQL version string, and constructs a capability table; determines the minimum common collation set C_common based on the intersection of the collation_id sets in the capability tables of all MySQL instances within the same switching domain; after the proxy layer completes a handshake with the backend MySQL instance, it then... Before the endpoint connection is placed into the connection pool, a character set normalization instruction is sent to the backend connection. The collation_id in the character set normalization instruction is taken from C_common. After the client session is established and before the first business statement is executed, the proxy layer injects the character set normalization instruction into the client session. In response to the primary / backup switchover instruction or rollback instruction, the proxy layer verifies whether the collation_id of the currently active session and the collation_id in the binlog of the link to be switched both fall within C_common. If so, traffic switching is performed to complete the primary / backup switchover or rollback. If not, the switchover is postponed or non-compliant sessions are rewritten until the verification passes and then traffic switching is performed.

[0007] In some embodiments, probing the MySQL version string of the backend MySQL instance includes: obtaining the MySQL version string from the handshake protocol message of the backend MySQL instance, and / or sending a version query request to the backend MySQL instance and receiving the returned MySQL version string; obtaining the major version number based on the MySQL version string includes: taking the number before the first decimal point in the MySQL version string as the major version number; obtaining the collation_id set supported by the major version number includes: querying the collation information table of the backend MySQL instance, the collation information table being INFORMATION_SCHEMA.COLLATIONS, extracting the value of the ID column from the returned result to form the collation_id set; the capability table includes at least the instance address of the backend MySQL instance, the major version number, and the collation_id set supported by the major version number; the capability table is refreshed when the backend MySQL instance version changes, the cluster topology changes, or when manually triggered by the administrator; if C_common is empty, the proxy layer refuses to establish an external service connection and issues an alarm.

[0008] In some embodiments, the same switching domain is a group of MySQL instances that share the same master-slave switching relationship.

[0009] In some embodiments, the MySQL cluster includes instances of MySQL 5.7 and MySQL 8.0, and the intersection of the collation_id set supported by MySQL 5.7 and the collation_id set supported by MySQL 8.0 is {1,2,...,247}; the character set normalization instruction is: SET NAMESutf8mb4 COLLATE utf8mb4_general_ci, where the collation_id corresponding to utf8mb4_general_ci is 45, and collation_id=45 belongs to C_common.

[0010] In some embodiments, when establishing the backend connection, the proxy layer sets the target `collation_id` in the default character set negotiation statements `SETcharacter_set_client`, `SET collation_connection`, and `SET collation_server` to the value in `C_common`; it sends a character set normalization instruction to the backend connection, which is issued by the proxy layer through its internal session interface after the backend connection completes its handshake, so that the session character set variable of the backend connection is set to `collation_id` in `C_common`; and it injects a character set normalization instruction into the client session, so that the character set variable of the client session is set to `collation_id` in `C_common`.

[0011] In some embodiments, the proxy layer is configured with query rules, which are used to intercept character set-related statements from the client session during the client session's execution, and to rewrite the intercepted statements according to their type before allowing them to pass; the character set-related statements include SET NAMES, SET character_set_ SET collation_ Specifically, the statement that sets the result set character set is rewritten as a statement that sets the result set character set to empty; the statement that sets the join collation to a collation name starting with utf8mb4_0900 is rewritten as a statement that sets the join collation to utf8mb4_general_ci.

[0012] In some embodiments, the binlog of the link to be switched is the binary log generated by the primary instance and transmitted to the standby instance during data replication between the primary and standby instances in the MySQL cluster; the verification of whether the collation_id of the currently active session and the collation_id in the binlog of the link to be switched both fall within C_common includes: verifying that C_common is not empty; confirming that the collation_id of all currently active sessions falls within C_common; reading several QUERY_EVENTs at the end of the binlog of the link to be switched, extracting the character set number in the event header of each QUERY_EVENT, and confirming that the character set number is in C_common; if not, the switch is suspended or non-compliant sessions are rewritten until the verification passes; after the verification passes, traffic switching is performed, including: updating the weight field of the corresponding host group in the mysql_servers table through the proxy layer management interface, and executing LOAD MYSQL SERVERS TO RUNTIME enables the weight change to take effect, thereby migrating traffic to the target instance; the rewriting of non-compliant sessions includes: rewriting the collation_id of the non-compliant session to the collation_id in C_common according to the preset statement rewriting rules.

[0013] In some embodiments, the method further includes a binlog replication health check for the rollback link: when the old node is re-established as a new master node slave node after a switchover, the collation_id in the pulled binlog is sampled; if a collation_id exceeding C_common is found, an alarm is triggered and the rollback is blocked; after confirming that all collation_ids in the binlog are within the range of C_common, the rollback operation is allowed; wherein, the parsing of the pulled binlog includes: for QUERY_EVENT, extracting the character set number in its event header; for TABLE_MAP_EVENT, extracting the sorting rule number of each character column in its column metadata; if any number is not in C_common, an alarm is triggered.

[0014] In some embodiments, for scenarios where binlog_format is STATEMENT or MIXED, the method directly controls the collation_connection value of QUERY_EVENT in the binlog through session layer character set normalization; for scenarios where binlog_format is ROW, the method reduces the probability of newly created tables using collations specific to the target major version number through session layer character set normalization.

[0015] According to another aspect of this application, a MySQL database switching system is provided, deployed between the application side and the MySQL cluster, for implementing the MySQL database switching method according to any of the above embodiments. The system includes: a version awareness module, configured to, when establishing a backend connection with a backend MySQL instance, detect the MySQL version string of the backend MySQL instance, obtain the major version number and the set of collation_ids supported by the major version number based on the MySQL version string, construct a capability table; and determine the minimum common collation set C_common based on the intersection of the collation_id sets in the capability tables of all MySQL instances within the same switching domain; and a normalized handshake module, configured to, when establishing a backend connection with the backend MySQL instance, detect the MySQL version string of the application side and the MySQL cluster, obtain the major version number and the set of collation_ids supported by the major version number, construct a capability table; and determine the minimum common collation set C_common based on the intersection of the collation_id sets in the capability tables of all MySQL instances within the same switching domain; and a normalized handshake module, configured to, when establishing a backend connection with the application side and the MySQL cluster, detect the MySQL version string of the application side and the MySQL cluster ... construct a normalized handshake based on the MySQL version string and the MySQL cluster, construct a capability table; and determine the minimum common collation set C_common based on the intersection of the collation_id sets After the QL instance completes the handshake and before placing the backend connection into the connection pool, it sends a character set normalization instruction to the backend connection. The collation_id in the character set normalization instruction is taken from C_common. The session initialization module is configured to inject the character set normalization instruction into the client session after the client session is established and before the first business statement is executed. The switching control module is configured to, in response to the primary / standby switching instruction or rollback instruction, verify whether the collation_id of the currently active session and the collation_id in the binlog of the link to be switched both fall within C_common. If so, traffic switching is performed to complete the primary / standby switching or rollback. If not, the switching is postponed or non-compliant sessions are rewritten until the verification passes and then traffic switching is performed.

[0016] According to another aspect of this application, an electronic device is provided, comprising: a processor; a memory storing executable instructions; wherein, when the executable instructions are executed by the processor, they implement the MySQL database switching method according to any of the above embodiments.

[0017] According to another aspect of this application, a computer-readable storage medium is provided for storing a program that, when executed by a processor, implements the MySQL database switching method according to any of the above embodiments.

[0018] According to another aspect of this application, a computer program product is provided, including a computer program that, when executed by a processor, implements the MySQL database switching method according to any of the above embodiments.

[0019] The advantages of this application compared to the prior art may include: This application uses version awareness at the proxy layer to detect the major version number of the source instance and the target instance and their supported collation_id sets. It then determines the minimum common collation set based on the intersection of the collation_id sets of all instances within the same switching domain, ensuring that common collation_ids still exist between instances with different major version numbers. Through post-handshake normalization and session initialization normalization, the character set variables of the backend connection and client session are anchored within the minimum common collation set, preventing target version-specific collation_ids from entering the binlog from the source. Finally, through pre-switch verification, it confirms that the collation_ids in the active session and binlog fall within the minimum common collation set before performing primary / standby switching or rollback.

[0020] This application, through the coordinated steps described above, ensures that the collation_id recorded in the binlog in both the forward switching and reverse rollback directions falls within a set supported by both the source and target instances. This eliminates the risk of replication interruption caused by incompatible collation_ids and enables bidirectional switching without modifying the MySQL server-side source code or application-side driver.

[0021] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description

[0022] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.

[0023] Figure 1 This is a schematic diagram illustrating the steps of the MySQL database switching method provided in the embodiments of this application; Figure 2 A flowchart of a MySQL database switching method provided as a specific example of this application; Figure 3 This is a schematic diagram of the modules of the MySQL database switching system provided in the embodiments of this application; Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0024] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to those described herein. Rather, these embodiments are provided to make this application more comprehensive and complete, and to fully convey the concept of the exemplary embodiments to those skilled in the art.

[0025] The accompanying drawings are merely illustrative of this application and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted. Some block diagrams shown in the drawings are functional entities and do not necessarily correspond to physically or logically independent entities. These functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.

[0026] Furthermore, the process shown in the accompanying drawings is merely illustrative and does not necessarily include all steps. For example, some steps can be broken down, some steps can be combined or partially combined, and the actual execution order may change depending on the actual situation.

[0027] It should be noted that, unless otherwise specified, the embodiments of this application and the features in different embodiments can be combined with each other. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.

[0028] Reference Figure 1 As shown in the embodiments of this application, the MySQL database switching method is applied to the proxy layer located between the application side and the MySQL cluster, and includes the following steps.

[0029] S110, when the proxy layer establishes a backend connection with the backend MySQL instance, it probes the MySQL version string of the backend MySQL instance, obtains the major version number and the set of collation_ids supported by the major version number based on the MySQL version string, and constructs the capability table.

[0030] MySQL is a relational database management system. In this application, MySQL refers both to the database management system itself and to the version, such as MySQL 5.7 and MySQL 8.0. The major version number is the number before the first decimal point in the MySQL version string; for example, the major version number of MySQL 5.7 is 5, and the major version number of MySQL 8.0 is 8. The major version number is used to distinguish major releases of MySQL. Collation is a collation rule used to determine the comparison and sorting of characters in a character set; each collation has a unique numeric identifier called collation_id. collation_id is the collation rule identifier, a unique numeric number for the collation. For example, the collation_id of utf8mb4_general_ci is 45, and the collation_id of utf8mb4_0900_ai_ci is 255. The collation_id set refers to the set of all collation_ids supported by a given MySQL version. For example, MySQL version 5.7 supports the collation_id set {1,2,...,247}, while MySQL version 8.0 supports the collation_id set {1,2,...,311}.

[0031] The capability table is a data structure built and maintained by the proxy layer for each backend MySQL instance. It records the instance address, major version number, and the set of collation_ids supported by that major version number. The capability table may also include a default collation_id and an identifier indicating whether it is a switch target. The default collation_id records the collation_ids issued by the proxy layer to the backend MySQL instance by default; the identifier indicates whether the backend MySQL instance is a switch target in the current switch relationship. By recording the version and collation_id support of the backend MySQL instance, the capability table provides the data foundation for subsequent calculation of the minimum common collation set.

[0032] S120. Determine the minimum common collation set C_common based on the intersection of the collation_id sets in the capability tables of all MySQL instances within the same switching domain.

[0033] Any `collation_id` in `C_common` can be recognized and resolved on all MySQL instances within the same failover domain. The same failover domain refers to a group of MySQL instances sharing the same master-slave failover relationship; master-slave failover or rollback operations may occur between instances within the same failover domain. Through `C_common`, the proxy layer can ensure that the `collation_id` in subsequently issued character set normalization commands can be resolved on all relevant MySQL instances.

[0034] S130: After the proxy layer completes the handshake with the backend MySQL instance and before putting the backend connection into the connection pool, it sends a character set normalization instruction to the backend connection. The collation_id in the character set normalization instruction is taken from C_common.

[0035] The handshake is the protocol interaction process between a MySQL client and server when establishing a connection. During the handshake, the server sends a handshake packet to the client, and the client sends a handshake response packet to the server, negotiating connection parameters. The connection pool is a mechanism used by the proxy layer to reuse backend connections. After the handshake and initialization are complete, the connection established between the proxy layer and the backend MySQL instance is placed in the connection pool for reuse by subsequent business requests. Issuing a normalization command within the time window after the handshake is completed and before the connection is placed in the connection pool ensures that the session character set variable of the backend connection has been set to `collation_id` in `C_common` before it is reused by subsequent business requests. Therefore, the `collation_id` recorded in the binlog subsequently generated by the backend connection will not exceed the range of `C_common`.

[0036] S140, after the client session is established and before the first business statement is executed, the proxy layer injects a character set normalization instruction into the client session.

[0037] Client session: The logical channel through which the application interacts with the backend MySQL instance via the proxy layer. After the client session is established, the application sends business statements to the backend MySQL instance through this session. Injecting a normalization instruction before the execution of the first business statement anchors the client session's character set variable at the session entry point, preventing subsequent character set-related statements from the client from overwriting the `collation_id` with a value specific to MySQL 8.0. Thus, the character set negotiation result between the client session and the backend connection is constrained to the range of `C_common`.

[0038] S150, in response to the primary / standby switchover command or rollback command, the proxy layer verifies whether the collation_id of the currently active session and the collation_id in the binlog of the link to be switched both fall within C_common; if so, traffic switching is performed to complete the primary / standby switchover or rollback; if not, the switchover is postponed or non-compliant sessions are rewritten until the verification passes and then traffic switching is performed.

[0039] Binlog is a binary log generated by the primary instance and transmitted to the secondary instance during data replication between primary and secondary instances in a MySQL cluster. Binlog contains various event types, such as QUERY_EVENT and TABLE_MAP_EVENT. QUERY_EVENT is an event type in binlog used to record an SQL statement in statement format. The QUERY_EVENT event header contains a character set number, which indicates the character set and collation of the session when executing the statement. TABLE_MAP_EVENT is an event type in binlog used to describe the table structure corresponding to subsequent row events. The column metadata of TABLE_MAP_EVENT contains the collation number of each character column. Through verification, the agent layer can confirm that all active sessions and the collation_id in the binlog are within the C_common range before actually performing a switchover or rollback, thereby avoiding binlog parsing failures and replication interruptions caused by collation_id incompatibility.

[0040] In summary, this application utilizes version awareness at the proxy layer to detect the primary version numbers of the source and target instances and their supported collation_id sets. It then determines the minimum common collation set based on the intersection of the collation_id sets of all instances within the same switching domain, ensuring that common collation_ids exist even between instances with different primary version numbers. Through post-handshake normalization and session initialization normalization, the character set variables of the backend connection and client session are anchored within this minimum common collation set, preventing target version-specific collation_ids from entering the binlog from the source. Pre-switch verification confirms that the collation_ids in the active session and binlog fall within this minimum common collation set before performing primary / standby switching or rollback. Through these coordinated steps, this application ensures that the collation_ids recorded in the binlog in both forward switching and reverse rollback directions fall within the set commonly supported by both the source and target instances, thereby eliminating the risk of replication interruption caused by collation_id incompatibility and achieving bidirectional switching without modifying the MySQL server-side source code or application-side driver.

[0041] In some embodiments, probing the MySQL version string of the backend MySQL instance includes: obtaining the MySQL version string from the handshake protocol message of the backend MySQL instance, and / or sending a version query request to the backend MySQL instance and receiving the returned MySQL version string; In some embodiments, obtaining the collection of `collation_id` supported by the major version number includes: querying the collation information table of the backend MySQL instance, where the collation information table is `INFORMATION_SCHEMA.COLLATIONS`, and extracting the values ​​of the `ID` column from the returned results to form the `collation_id` collection. `INFORMATION_SCHEMA.COLLATIONS` is the collation information table in the MySQL information schema, containing columns such as `COLLATION_NAME`, `CHARACTER_SET_NAME`, `ID`, `IS_DEFAULT`, `IS_COMPILED`, and `SORTLEN`. The value of the `ID` column is the `collation_id`.

[0042] In some embodiments, the capability table includes at least the instance address of the backend MySQL instance, its major version number, and the set of collation_ids supported by the major version number. The capability table is refreshed when the backend MySQL instance version changes, the cluster topology changes, or when manually triggered by the administrator, ensuring that the capability table remains consistent with the actual situation. If C_common is empty, the proxy layer refuses to establish external service connections and issues an alert to prevent continued service provision without a commonly supported collation_id, which could lead to subsequent replication interruptions.

[0043] In some embodiments, the same switching domain is a group of MySQL instances that share the same master-slave switching relationship, so that the computed object of the minimum common collation set is consistent with the scope of instances that actually perform switching or rollback operations, avoiding the unnecessary shrinking of C_common due to including irrelevant instances in the intersection calculation.

[0044] In some embodiments, the MySQL cluster includes instances of MySQL version 5.7 and MySQL version 8.0, and the intersection of the collation_id set supported by MySQL version 5.7 and the collation_id set supported by MySQL version 8.0 is {1,2,...,247}.

[0045] In some embodiments, the character set normalization directive is: `SET NAMES utf8mb4 COLLATE utf8mb4_general_ci`, where `utf8mb4_general_ci` corresponds to a `collation_id` of 45, and `collation_id=45` belongs to `C_common`. `SET NAMES` is a MySQL statement used to set the character sets for clients, connections, and result sets. `SET NAMES utf8mb4 COLLATE utf8mb4_general_ci` means setting the client character set to `utf8mb4` and the connection collation to `utf8mb4_general_ci`.

[0046] In some embodiments, when establishing a backend connection, the proxy layer sets the target collation_id in the default SET character_set_client, SET collation_connection, and SET collation_server character set negotiation statements to the value in C_common. This ensures that the proxy layer uses the collation_id in C_common when generating the default character set negotiation statement, thus preventing the MySQL 8.0-specific collation_id from entering the backend connection.

[0047] In some embodiments, a character set normalization instruction is sent to the backend connection. This instruction is issued by the proxy layer through its internal session interface after the backend connection completes its handshake, setting the backend connection's session character set variable to `collation_id` in `C_common`. A character set normalization instruction is also injected into the client session, setting its character set variable to `collation_id` in `C_common`. Thus, the character set variables on both the backend connection and client session sides are anchored within the `C_common` scope, forming a bidirectional constraint. The internal session interface is the proxy layer's internal interface for managing backend connections. The proxy layer directly constructs a default character set negotiation statement using `collation_id` in `C_common` and sends the character set normalization instruction to the backend connection through the internal session interface. This instruction bypasses the proxy layer's client query processing pipeline.

[0048] In some embodiments, the proxy layer is configured with query rules. These rules are used to intercept character set-related statements from the client session during its execution, and then rewrite the intercepted statements according to their type before allowing them to pass. Even if the client actively sends character set-related statements during the session, the proxy layer can rewrite them into statements conforming to the C_common requirement, thereby maintaining character set normalization throughout the entire lifecycle of the client session and preventing client statements from overwriting the initial normalization result. The query rules are the rules in the proxy layer used to match and rewrite statements from the client. The query rules match the statement text using regular expressions and replace the matched statements with the specified rewritten results.

[0049] In some embodiments, character set related statements include SET NAMES, SET character_set_ SETcollation_ Specifically, the statement that sets the result set character set is rewritten as a statement that sets the result set character set to empty; the statement that sets the join collation to a collation name starting with utf8mb4_0900 is rewritten as a statement that sets the join collation to utf8mb4_general_ci.

[0050] SET character_set_ This refers to the SET statement family that begins with `character_set_`, including `SET character_set_client`, `SET character_set_connection`, `SET character_set_results`, `SET character_set_server`, etc. `SET collation_` This refers to the SET statement family that begins with collation_, including SET collation_connection, SET collation_server, SET collation_database, etc.

[0051] In some embodiments, the binlog of the link to be switched is a binary log generated by the primary instance and transmitted to the standby instance during data replication between the primary and standby instances in the MySQL cluster. Verifying whether the collation_id of the currently active session and the collation_id in the binlog of the link to be switched both fall within C_common includes: verifying that C_common is not empty; confirming that the collation_id of all currently active sessions falls within C_common; reading several QUERY_EVENTs at the end of the binlog of the link to be switched, extracting the character set number from the event header of each QUERY_EVENT, and confirming that the character set number is in C_common; if not, the switch is temporarily suspended or non-compliant sessions are rewritten according to the query rules until the verification passes; after the verification passes, the weight field of the corresponding host group in the mysql_servers table is updated through the proxy layer management interface, and LOADMYSQL SERVERS TO RUNTIME is executed to make the weight change effective, thereby migrating traffic to the target instance.

[0052] In this context, `hostgroup` is a logical group within the proxy layer used to manage backend MySQL instances. The proxy layer controls the distribution of traffic among different instances by adjusting the weights of instances within a `hostgroup`. The `mysql_servers` table in the proxy layer stores the configuration of the backend MySQL instances, containing fields such as instance address, hostgroup, and weight.

[0053] In some embodiments, switching the routing weight of a host group includes: updating the weight field of the corresponding host group in the mysql_servers table through the proxy layer management interface, and executing LOAD MYSQL SERVERS TO RUNTIME to make the weight change take effect.

[0054] In some embodiments, rewriting non-compliant sessions includes: rewriting the collation_id of the non-compliant session to the collation_id in C_common according to a preset statement rewriting rule.

[0055] In some embodiments, the MySQL database failover method further includes a binlog replication health check of the rollback link: when the old node is re-established as the new master / slave node after the failover, the collation_id in the retrieved binlog is sampled; if a collation_id exceeding C_common is found, an alarm is triggered and the rollback is blocked; after confirming that all collation_ids in the binlog are within the range of C_common, the rollback operation is allowed; wherein, parsing the retrieved binlog includes: for QUERY_EVENT, extracting the character set number in its event header; for TABLE_MAP_EVENT, extracting the collation rule number of each character column in its column metadata; if any number is not in C_common, an alarm is triggered. The addition of a sampling check of the binlog retrieved for re-establishing the replication link before the rollback operation forms a closed loop with the pre-failover verification, further reducing the risk of replication interruption during the rollback process.

[0056] In some embodiments, the MySQL database switching method directly controls the collation_connection value of QUERY_EVENT in the binlog when binlog_format is STATEMENT or MIXED through session-level character set normalization; when binlog_format is ROW, it reduces the probability of newly created tables using the target major version number-specific collation through session-level character set normalization.

[0057] binlog_format specifies the binlog recording format, which includes three types: STATEMENT, MIXED, and ROW. In STATEMENT format, the binlog records SQL statements; in ROW format, the binlog records row changes; and in MIXED format, MySQL automatically selects either STATEMENT or ROW format based on the statement type.

[0058] The following example, using a master-slave switchover and rollback from MySQL 5.7 to MySQL 8.0, illustrates the MySQL database switching method described in this application.

[0059] This example provides a MySQL database failover system comprising an application-side DAL, a proxy layer, and a MySQL cluster. The application-side DAL connects to the database through the proxy layer. The proxy layer handles traffic routing, version awareness, character set normalization, statement rewriting, and failover control. The MySQL cluster includes instances of MySQL 5.7 and MySQL 8.0. The proxy layer includes a version awareness module, a normalization handshake module, a session initialization module, a statement rule rewriting module, a failover control module, and a binlog sampling and inspection module.

[0060] The application-side DAL uses mysql-connector-java 5.1.48 as the data access layer, connecting to the database through a proxy layer. The proxy layer uses ProxySQL, which is responsible for traffic routing, version awareness, and character set normalization. The initial master database is MySQL version 5.7, which handles write traffic. The initial standby database is MySQL version 8.0, which is the switch target and becomes the master database after the switch.

[0061] Reference Figure 2 As shown, the MySQL database switching method in this example includes steps such as version detection and capability table construction, C_common determination, character set normalization after handshake, client session initialization normalization, pre-switching verification, traffic switching, and post-switching inspection.

[0062] Step S210: Version awareness and capability table construction.

[0063] The version awareness module performs version detection and retrieves the collation_id set for both MySQL 5.7 and MySQL 8.0 instances, and calculates C_common.

[0064] When establishing a connection with the backend MySQL instance, the proxy layer probes the MySQL version string of the backend MySQL instance using one or a combination of the following methods: Method 1: Read the `server_version` field in the MySQL protocol handshake packet. In the HandshakeV10 packet sent by the MySQL server after the TCP connection is established, the `server_version` field is a string type, terminated by a null character, and its content is in the form of 8.0.35 or 5.7.44-log. Method 2: Send a query statement `SHOW VARIABLES LIKE 'version'` or `SELECT @@version` to the backend MySQL instance and obtain the version string from the returned results. Method 3: Send a query statement `SELECT @@version_comment` to the backend MySQL instance to obtain version comment information, which is used to help confirm the release version.

[0065] The proxy layer takes the obtained version string, using the first decimal point as a separator, and extracts the digits before the separator as the major version number. For example, the major version number of the version string 8.0.35 is 8, and the major version number of the version string 5.7.44-log is 5.

[0066] The proxy layer sends a query statement `SELECT ID FROM INFORMATION_SCHEMA.COLLATIONS ORDER BY ID` to the backend MySQL instance, or executes `SHOW COLLATION` and reads the `Id` column from the returned result, extracting the value of the `ID` column to form a set of `collation_id`s supported by the major version number. The proxy layer constructs a capability table using the backend MySQL instance address, major version number, the set of `collation_id`s supported by the major version number, the default `collation_id`, and an identifier indicating whether it is a target for switching. The capability table is refreshed when the backend MySQL instance version changes, the cluster topology changes, or when manually triggered by the administrator.

[0067] The proxy layer determines the minimum common collation set C_common based on the intersection of the collation_id sets in the capability tables of all MySQL instances within the same failover domain. The same failover domain refers to a group of MySQL instances sharing the same master-slave failover relationship. For MySQL 5.7 and MySQL 8.0 instances, C_common ranges from 1 to 247. The selected normalization target is collation_id equal to 45, i.e., utf8mb4_general_ci. If C_common is empty, the proxy layer refuses to establish external service connections and issues an alert.

[0068] Step S220: Character set normalization after handshake.

[0069] After the proxy layer completes the handshake with the backend MySQL instance, before placing the backend connection into the connection pool, it sends a character set normalization command to the backend connection through the proxy layer's internal session interface. The character set normalization command is `SET NAMESutf8mb4 COLLATE utf8mb4_general_ci`, where `utf8mb4_general_ci` corresponds to a `collation_id` of 45, and `collation_id` equal to 45 belongs to `C_common`. When establishing a backend connection, the proxy layer sets the target `collation_id` in the default `SET character_set_client`, `SET collation_connection`, and `SET collation_server` character set negotiation statements to the value in `C_common`. The backend connection's session character set variable is then set to the `collation_id` in `C_common`. Through this process, the `collation_id` recorded in the binlog subsequently generated by the backend connection will not exceed the range of `C_common`.

[0070] Step S230: Client session initialization normalization.

[0071] After the client session is established and before the first business statement is executed, the proxy layer injects a character set normalization instruction into the client session, setting the client session's character set variable to `collation_id` in `C_common`. The proxy layer is configured with query rules to intercept character set-related statements from the client session during its execution, and then rewrites the intercepted statements according to their type before allowing them to proceed. Character set-related statements include `SETNAMES`, `SET character_set_`, etc. SET collation_ For statements that set the result set character set, matching non-NULL values ​​will be rewritten as statements that set the result set character set to NULL, i.e., `SET character_set_results` equals NULL. For statements that set the join collation rule to a collation name starting with `utf8mb4_0900`, they will be rewritten as statements that set the join collation rule to `utf8mb4_general_ci`. Query rules are configured as follows: insert rule records into the `mysql_query_rules` table of the proxy layer, set `active` to 1, `match_pattern` to a regular expression, `replace_pattern` to the rewritten statement, and `apply` to 1. Then execute `LOAD MYSQL QUERY RULES TORUNTIME` and `SAVE MYSQL QUERY RULES TO DISK` to make the rules effective and persistent.

[0072] By initializing normalization during the client session and continuously intercepting and rewriting query rules, the character set variables of the client session are constrained to the range of C_common throughout the entire lifecycle, preventing subsequent character set-related statements from the client from overwriting the initial normalization result.

[0073] Step S240: Verification before switching.

[0074] The switchover control module performs verification before primary / standby switchover or rollback. In response to the primary / standby switchover command, the proxy layer verifies whether the `collation_id` of the currently active session and the `collation_id` in the binlog of the link to be switched both fall within `C_common`. Verification includes: verifying that `C_common` is not empty; confirming that the `collation_id` of all currently active sessions falls within `C_common`; reading several `QUERY_EVENT` events at the end of the binlog of the link to be switched, extracting the character set number from the event header of each `QUERY_EVENT`, and confirming that the character set number is in `C_common`. If the verification fails, the switchover is temporarily suspended or non-compliant sessions are rewritten according to the query rules until the verification passes. Rewriting non-compliant sessions includes rewriting the `collation_id` of the non-compliant session to the `collation_id` in `C_common` according to preset statement rewriting rules.

[0075] After successful verification, the weight field of the corresponding host group in the mysql_servers table is updated through the proxy layer management interface, and the LOAD MYSQL SERVERS TO RUNTIME command is executed to make the weight change take effect, so as to migrate traffic to the target instance.

[0076] Step S250: Verify after switching.

[0077] After the switchover is complete, the original MySQL 5.7 master database is rebuilt as a slave database using MySQL 8.0 as the source. The binlog sampling and inspection module in the proxy layer samples the `collation_id` from the retrieved binlog when the old node is rebuilt as the new master / slave replication link. The parsing of the retrieved binlog includes: for `QUERY_EVENT`, extracting the character set number from its event header; for `TABLE_MAP_EVENT`, extracting the collation number of each character column in its column metadata; if any number is not in `C_common`, an alarm is triggered. If a `collation_id` exceeding `C_common` is found, an alarm is triggered and rollback is blocked. After confirming that all `collation_id`s in the binlog are within the range of `C_common`, the rollback operation is allowed.

[0078] Step S260: Rollback verification.

[0079] If a rollback is required, the switchover control module reverses the above steps to revert write traffic to the MySQL 5.7 version node. Since all binlogs have been normalized, MySQL 8.0, as the new slave, can also correctly parse the binlog, achieving a seamless bidirectional switchover.

[0080] This example of MySQL database switching directly controls the `collation_connection` value of `QUERY_EVENT` in the binlog for scenarios where `binlog_format` is `STATEMENT` or `MIXED`, through session-level character set normalization. For scenarios where `binlog_format` is `ROW`, session-level character set normalization reduces the probability of newly created tables using collations specific to the target major version number, and separately manages collations explicitly specified in the table definition.

[0081] Furthermore, the core concept of this application is not limited to ProxySQL. Any database proxy component capable of internally implementing statement interception and backend connection management, such as DBLE and self-developed proxies, can adopt this method. The choice of the minimum common collation set C_common is not limited to utf8mb4_general_ci; a more suitable collation can be selected from C_common as the normalization target based on the business character set requirements. The MySQL database switching method of this application can be extended to upgrades from MySQL 8.0 to future higher versions, as well as other similar cross-version switching scenarios where character sets or collation rules are incompatible.

[0082] This application also provides a MySQL database switching system, deployed between the application side and the MySQL cluster, for implementing the MySQL database switching method described in any of the above embodiments. (Refer to...) Figure 3 As shown, the MySQL database switching system 300 includes the following modules.

[0083] Version awareness module 310 is configured to detect the MySQL version string of the backend MySQL instance when establishing a backend connection with the backend MySQL instance, obtain the major version number and the set of collation_ids supported by the major version number based on the MySQL version string, construct a capability table, and determine the minimum common collation set C_common based on the intersection of the collation_id sets in the capability tables of all MySQL instances in the same switching domain.

[0084] The normalization handshake module 320 is configured to send a character set normalization instruction to the backend connection after completing the handshake with the backend MySQL instance and before putting the backend connection into the connection pool. The collation_id in the character set normalization instruction is taken from C_common.

[0085] The session initialization module 330 is configured to inject a character set normalization instruction into the client session after the client session is established and before the first business statement is executed.

[0086] The switching control module 340 is configured to, in response to a primary / standby switching command or a rollback command, verify whether the collation_id of the currently active session and the collation_id in the binlog of the link to be switched both fall within C_common; if so, then perform traffic switching to complete the primary / standby switching or rollback; if not, then postpone the switching or rewrite the non-compliant session until the verification passes and then perform traffic switching.

[0087] The MySQL database switching system described in this application can ensure that the collation_id recorded in the binlog in both forward switching and reverse rollback directions falls within the set supported by both the source instance and the target instance, eliminating the risk of replication interruption caused by collation_id incompatibility, and achieving bidirectional switching without modifying the MySQL server source code or application-side driver.

[0088] This application also provides an electronic device, including a processor and a memory, wherein the memory stores executable instructions, and when the executable instructions are executed by the processor, the MySQL database switching method described in any of the above embodiments is implemented.

[0089] Reference Figure 4As shown, the electronic device 400 is presented in the form of a general-purpose computing device. The components of the electronic device 400 include, but are not limited to: at least one processing unit 410, at least one storage unit 420, and a bus 430 connecting different platform components (including storage unit 420 and processing unit 410).

[0090] Storage unit 420 stores program code, which can be executed by processing unit 410 to perform the steps of the MySQL database switching method described in any of the above embodiments. Storage unit 420 may include readable media in the form of volatile storage units, such as random access memory and / or cache memory units, and may further include read-only memory units. Storage unit 420 may also include programs / utilities having one or more program modules, including but not limited to: operating systems, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment.

[0091] Bus 430 can represent one or more of several types of bus structures, including a memory cell bus or memory cell controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any of the various bus structures.

[0092] Electronic device 400 can also communicate with one or more external devices, such as keyboards, pointing devices, Bluetooth devices, etc. These external devices enable users to interact and communicate with electronic device 400. Electronic device 400 can also communicate with one or more other computing devices, including routers and modems. This communication can be achieved through input / output interfaces. Furthermore, electronic device 400 can communicate with one or more networks (e.g., local area networks, wide area networks, and / or public networks, such as the Internet) via a network adapter. The network adapter can communicate with other modules of electronic device 400 via bus 430. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 400, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage platforms.

[0093] This application also provides a computer-readable storage medium for storing a program that, when executed, implements the MySQL database switching method described in any of the above embodiments.

[0094] The storage medium may be a portable compact disk read-only memory and include program code, and may run on a terminal device, such as a personal computer. However, the storage medium of this application is not limited to this; it may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.

[0095] The storage medium may be any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example,, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media include, but are not limited to: electrical connections with one or more wires, portable disks, hard disks, random access memory, read-only memory, erasable programmable read-only memory, optical fibers, portable compact disk read-only memory, optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0096] A readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying readable program code. This propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The readable signal medium may also be any readable medium other than a readable storage medium, capable of transmitting, propagating, or transmitting a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the readable signal medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.

[0097] Program code for performing the operations of this application can be written in any combination of one or more programming languages, including object-oriented programming languages. The program code can execute entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device, for example, via the Internet using an Internet service provider.

[0098] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the MySQL database switching method as described in any of the above embodiments.

[0099] Finally, it should be noted that the above description, in conjunction with specific preferred embodiments, provides a further detailed explanation of this application and should not be construed as limiting the specific implementation of this application to these descriptions. For those skilled in the art, various simple deductions or substitutions can be made without departing from the concept of this application, and all such modifications or substitutions should be considered within the scope of protection of this application.

Claims

1. A MySQL database switching method, applied to a proxy layer located between the application side and the MySQL cluster, characterized in that, include: When establishing a backend connection with the backend MySQL instance, the proxy layer probes the MySQL version string of the backend MySQL instance, obtains the major version number and the set of collation_ids supported by the major version number based on the MySQL version string, and constructs a capability table. The minimum common collation set C_common is determined by the intersection of the collation_id sets in the capability tables of all MySQL instances within the same switching domain. After the proxy layer completes the handshake with the backend MySQL instance, before putting the backend connection into the connection pool, it sends a character set normalization instruction to the backend connection. The collation_id in the character set normalization instruction is taken from C_common. The proxy layer injects the character set normalization instruction into the client session after the client session is established and before the first business statement is executed; In response to a primary / standby switchover command or a rollback command, the proxy layer verifies whether the collation_id of the currently active session and the collation_id in the binlog of the link to be switched both fall within C_common. If so, traffic switching is performed to complete the primary / standby switchover or rollback. If not, the switchover is postponed or non-compliant sessions are rewritten until the verification passes and then traffic switching is performed.

2. The MySQL database switching method according to claim 1, characterized in that, Detecting the MySQL version string of the backend MySQL instance includes: obtaining the MySQL version string from the handshake protocol message of the backend MySQL instance, and / or sending a version query request to the backend MySQL instance and receiving the returned MySQL version string; Obtaining the major version number from the MySQL version string includes: taking the number before the first decimal point in the MySQL version string as the major version number; Obtaining the collection of collation_ids supported by the major version number includes: querying the collation information table of the backend MySQL instance, wherein the collation information table is INFORMATION_SCHEMA.COLLATIONS, extracting the value of the ID column from the returned result, and forming the collection of collation_ids; The capability table includes at least the instance address of the backend MySQL instance, the major version number, and the set of collation_ids supported by the major version number; the capability table is refreshed when the backend MySQL instance version changes, the cluster topology changes, or when manually triggered by the administrator; if C_common is empty, the proxy layer refuses to establish an external service connection and issues an alarm.

3. The MySQL database switching method according to claim 1, characterized in that, The same switching domain refers to a group of MySQL instances that share the same master-slave switching relationship.

4. The MySQL database switching method according to claim 1, characterized in that, The MySQL cluster includes instances of MySQL 5.7 and MySQL 8.

0. The intersection of the collation_id set supported by MySQL 5.7 and the collation_id set supported by MySQL 8.0 is {1,2,...,247}. The character set normalization instruction is: SET NAMES utf8mb4 COLLATE utf8mb4_general_ci, where the collation_id corresponding to utf8mb4_general_ci is 45, and collation_id=45 belongs to C_common.

5. The MySQL database switching method according to claim 1, characterized in that, When establishing the backend connection, the proxy layer sets the target collation_id in the default SET character_set_client, SET collation_connection, and SET collation_server character set negotiation statements to the value in C_common. A character set normalization instruction is sent to the backend connection. This instruction is sent by the proxy layer through its internal session interface after the backend connection completes the handshake, so that the session character set variable of the backend connection is set to collation_id in C_common. Inject a character set normalization instruction into the client session so that the character set variable of the client session is set to collation_id in C_common.

6. The MySQL database switching method according to claim 1, characterized in that, The proxy layer is configured with query rules, which are used to intercept character set-related statements from the client session during the client session's operation, and rewrite the intercepted statements according to their statement types before allowing them to pass. The character set-related statements include SET NAMES, SET character_set_ SET collation_ Specifically, the statement that sets the result set character set is rewritten as a statement that sets the result set character set to empty; the statement that sets the join collation to a collation name starting with utf8mb4_0900 is rewritten as a statement that sets the join collation to utf8mb4_general_ci.

7. The MySQL database switching method according to claim 1, characterized in that, The binlog of the link to be switched is the binary log generated by the primary instance and transmitted to the standby instance when data is replicated between the primary and standby instances in the MySQL cluster. The verification of whether the collation_id of the current active session and the collation_id in the binlog of the link to be switched both fall within C_common includes: verifying that C_common is not empty; confirming that the collation_id of all current active sessions falls within C_common; reading several QUERY_EVENTs at the end of the binlog of the link to be switched, extracting the character set number in the event header of each QUERY_EVENT, and confirming that the character set number is in C_common; if not, the switching is suspended or non-compliant sessions are rewritten until the verification passes; after the verification passes, traffic switching is performed, including: updating the weight field of the corresponding host group in the mysql_servers table through the proxy layer management interface, and executing LOAD MYSQL SERVERS TORUNTIME to make the weight change take effect, so as to migrate traffic to the target instance; The rewriting of non-compliant sessions includes: rewriting the collation_id of the non-compliant session to the collation_id in C_common according to the preset statement rewriting rules.

8. The MySQL database switching method according to claim 1, characterized in that, The method also includes a binlog replication health check for the rollback link: When re-establishing the replication link as a new master node slave node after a switchover, the collation_id in the retrieved binlog is sampled; if a collation_id exceeding C_common is found, an alarm is triggered and rollback is blocked; after confirming that all collation_ids in the binlog are within the range of C_common, the rollback operation is allowed. The parsing of the retrieved binlog includes: for QUERY_EVENT, extracting the character set number from its event header; for TABLE_MAP_EVENT, extracting the sorting rule number of each character column in its column metadata; and issuing an alarm if any number is not in C_common.

9. The MySQL database switching method according to any one of claims 1 to 8, characterized in that, For scenarios where binlog_format is STATEMENT or MIXED, the method directly controls the collation_connection value of QUERY_EVENT in binlog through session layer character set normalization; for scenarios where binlog_format is ROW, the method reduces the probability of newly created tables using the target major version number-specific collation through session layer character set normalization.

10. A MySQL database switching system, deployed between the application side and the MySQL cluster, characterized in that, The system for implementing the MySQL database switching method according to any one of claims 1 to 9 includes: The version awareness module is configured to detect the MySQL version string of the backend MySQL instance when establishing a backend connection with the backend MySQL instance, obtain the major version number and the set of collation_ids supported by the major version number based on the MySQL version string, construct a capability table, and determine the minimum common collation set C_common based on the intersection of the collation_id sets in the capability tables of all MySQL instances in the same switching domain. The normalization handshake module is configured to send a character set normalization instruction to the backend connection after completing the handshake with the backend MySQL instance and before putting the backend connection into the connection pool. The collation_id in the character set normalization instruction is taken from C_common. The session initialization module is configured to inject the character set normalization instruction into the client session after the client session is established and before the first business statement is executed. The switching control module is configured to respond to a primary / standby switchover command or a rollback command by verifying whether the collation_id of the currently active session and the collation_id in the binlog of the link to be switched both fall within C_common. If so, traffic switching is performed to complete the primary / standby switchover or rollback. If not, the switchover is suspended or non-compliant sessions are rewritten until the verification passes and then traffic switching is performed.

11. An electronic device, characterized in that, include: processor; A memory, wherein executable instructions are stored; When the executable instructions are executed by the processor, they implement the MySQL database switching method according to any one of claims 1 to 9.

12. A computer-readable storage medium for storing a program, characterized in that, When the program is executed by the processor, it implements the MySQL database switching method according to any one of claims 1 to 9.

13. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the MySQL database switching method according to any one of claims 1 to 9.