• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • 介绍InnoDB集群

    MySQL InnoDB集群为MySQL提供了完整的高可用性解决方案。 MySQL Shell包含AdminAPI,可让您轻松配置和管理至少三个MySQL服务器实例的组,以充当InnoDB集群。每个MySQL服务器实例都运行MySQL Group Replication,它提供了具有内置故障转移功能的InnoDB群集内复制数据的机制。AdminAPI消除了直接在InnoDB群集中使用组复制的需要,但是有关更多信息,请参见组复制,其中详细说明了该操作。 MySQL路由器可以根据您部署的群集自动进行自我配置,从而将客户端应用程序透明地连接到服务器实例。如果服务器实例发生意外故障,则群集将自动重新配置。在默认的单主服务器模式下,InnoDB集群具有单个读写服务器实例-主服务器。多个辅助服务器实例是主服务器的副本。如果主服务器发生故障,则辅助服务器将自动升级为主服务器角色。MySQL Router会检测到此情况,并将客户端应用程序转发到新的主服务器。高级用户还可以将集群配置为具有多个主数据库。

    重要

    InnoDB群集不提供对MySQL NDB群集的支持。NDB Cluster取决于NDB存储引擎以及特定于NDB Cluster的许多程序,而MySQL Server 8.0并未提供这些程序。NDB仅可作为MySQL NDB Cluster发行版的一部分使用。另外,MySQL Server 8.0随附的MySQL服务器二进制文件(mysqld)不能与NDB Cluster一起使用。有关MySQL NDB群集的更多信息,请参见MySQL NDB Cluster 8.0。 22.1.6节,“MySQL服务器使用的是InnoDB与NDB集群相比”,提供了有关之间的差异InnoDBNDB存储引擎。

    下图概述了这些技术如何协同工作:

    InnoDB集群概述


    使用AdminAPI

    MySQL Shell包含AdminAPI,可通过dba全局变量及其关联方法进行访问。该dba变量的方法使您能够部署,配置和管理InnoDB的集群。例如,使用该dba.createCluster()方法创建一个InnoDB集群。

    重要

    MySQL Shell使您可以通过套接字连接连接到服务器,但是AdminAPI需要与服务器实例的TCP连接。AdminAPI不支持基于套接字的连接。

    MySQL Shell为AdminAPI提供在线帮助。要列出所有可用dba命令,请使用dba.help()方法。有关特定方法的在线帮助,请使用常规格式object.help('methodname')。例如:

    mysql-js> dba.help('getCluster')
    
    Retrieves a cluster from the Metadata Store.
    
    SYNTAX
    
      dba.getCluster([name][, options])
    
    WHERE
    
      name: Parameter to specify the name of the cluster to be returned.
      options: Dictionary with additional options.
    
    RETURNS
    
      The cluster object identified by the given name or the default cluster.
    
    DESCRIPTION
    
    If name is not specified or is null, the default cluster will be returned.
    
    If name is specified, and no cluster with the indicated name is found, an error
    will be raised.
    
    The options dictionary accepts the connectToPrimary option,which defaults to
    true and indicates the shell to automatically connect to the primary member of
    the cluster.
    
    EXCEPTIONS
    
      MetadataError in the following scenarios:
    
       - If the Metadata is inaccessible.
       - If the Metadata update operation failed.
    
      ArgumentError in the following scenarios:
    
       - If the Cluster name is empty.
       - If the Cluster name is invalid.
       - If the Cluster does not exist.
    
      RuntimeError in the following scenarios:
    
       - If the current connection cannot be used for Group Replication.
    

    MySQL Shell可以选择记录AdminAPI操作使用的SQL语句(沙盒操作除外),还可以在执行它们时在终端中显示它们。要配置MySQL Shell来执行此操作,请参见记录AdminAPI操作。

    指定实例

    管理InnoDB集群的核心概念之一是了解与组成集群的MySQL实例的连接。管理InnoDB集群时,与实例的连接以及实例本身之间的连接的要求是:

    • 仅支持TCP / IP连接,不支持使用Unix套接字或命名管道。InnoDB集群旨在用于局域网中,不建议运行通过广域网连接的实例集群。
    • 仅支持MySQL经典协议连接,不支持X协议。

      注意

      您的应用程序可以使用X协议,此要求适用于AdminAPI。

    MySQL Shell使您能够使用各种API,并支持指定连接,如“使用URI类字符串或键值对连接到服务器”中所述。的其它连接参数不被InnoDB的集群支持。您可以使用URI类型的字符串或键值对指定连接。本文档演示了使用URI类型的连接字符串的AdminAPI。例如,要以用户身份连接myuserwww.example.com端口上的MySQL服务器实例,请3306使用连接字符串:

    myuser@www.example.com:3306
    

    要将此连接字符串与AdminAPI操作(如)一起使用dba.configureInstance(),您需要确保将连接字符串解释为字符串,例如,用单引号(')或双引号(“)引起来的连接字符串。) AdminAPI的JavaScript实现问题:

    MySQL JS > dba.configureInstance('myuser@www.example.com:3306')
    

    假设您正在默认交互模式下运行MySQL Shell,则系统会提示您输入密码。AdminAPI支持MySQL Shell的 Pluggable Password Store,一旦存储了用于连接到实例的密码,将不再提示您输入密码。


    下篇:部署方案