Skip to main content
Version: release-0.8

Create and connect to a MySQL cluster

This tutorial shows how to create and connect to a MySQL cluster.

Create a MySQL cluster

Before you start

  • Install kbcli if you want to create and connect a MySQL cluster by kbcli.

  • Install KubeBlocks by kbcli or install KubeBlocks by Helm.

  • Make sure the ApeCloud MySQL add-on is enabled.

    kbcli addon list
    >
    NAME TYPE STATUS EXTRAS AUTO-INSTALL INSTALLABLE-SELECTOR
    ...
    apecloud-mysql Helm Enabled true
    ...
  • View all the database types and versions available for creating a cluster.

    kbcli clusterdefinition list

    kbcli clusterversion list
  • To keep things isolated, create a separate namespace called demo throughout this tutorial.

    kubectl create namespace demo

Create a cluster

KubeBlocks supports creating two types of MySQL clusters: Standalone and RaftGroup Cluster. Standalone only supports one replica and can be used in scenarios with lower requirements for availability. For scenarios with high availability requirements, it is recommended to create a RaftGroup Cluster, which creates a cluster with three replicas. And to ensure high availability, all replicas are distributed on different nodes by default.

Create a Standalone.

kbcli cluster create mysql <clustername>

Create a RaftGroup Cluster.

kbcli cluster create mysql --mode raftGroup <clustername>

If you only have one node for deploying a RaftGroup Cluster, set the availability-policy as none when creating a RaftGroup Cluster.

kbcli cluster create mysql --mode raftGroup --availability-policy none <clustername>
note
  • In the production environment, it is not recommended to deploy all replicas on one node, which may decrease the cluster availability.

  • Run the command below to view the flags for creating a MySQL cluster and the default values.

    kbcli cluster create mysql -h

Connect to a MySQL Cluster

kbcli cluster connect <clustername>  --namespace <name>

For the detailed database connection guide, refer to Connect database.