For AI agents: this documentation is indexed for you in llms.txt, and all of it in /llms.txt. Every page is also available as markdown: append .md to its address.

Create a database user

By default, after bootstrapping Cennso Database instances, only system user accounts are created. These accounts should be used only for tasks such as administration, monitoring, and database backups. To create additional database user accounts for your applications, you can either use the DBUser Custom Resource or create them manually. Both methods are described below.

Provision a user account using DBUser CR

The creation of a user account consists of two steps:

  1. Create a Kubernetes SecretOpens in a new tab on the Core Cluster that holds the password for the new user account. For example:

    yaml

    The Secret must be created in the same Kubernetes Namespace where the database instance is deployed. You can create the Secret using the following command:

    bash
  2. Create the user account with the DBUser Custom Resource on the Management Cluster, referencing the Secret you just created. For example:

    yaml

    You can apply the DBUser Custom Resource to your Management Cluster using the following command:

    bash

After you apply the DBUser manifest, a Kubernetes Job is created on the Core Cluster specified by {CORE-CLUSTER-NAME}. This Job creates a new user account with {USER-NAME} name in the {NAMESPACE-WITH-DATABASE-CLUSTER} namespace, using the password from the my-user-password Kubernetes Secret and privileges from the manifest.

To create a user account at the given database instance, the Job must be able to find the database cluster. The spec.dbInstanceName field is used for this purpose. Set it to the metadata.name of the DBInstance claim related to the target database cluster.

Besides the username and password, you can specify the host part of the MySQL account identity using the spec.host parameter. For example, % allows the user to connect from any host. For more information about the format of the host, see the official documentationOpens in a new tab.

You can also pick the MySQL authentication plugin via spec.authPlugin. Supported values are mysql_native_password (default) and caching_sha2_password.

According to the manifest above, the new user account is created with ALL PRIVILEGES on the mysql and example databases. In addition, it has the following grants on all other databases:

  • REPLICATION CLIENT
  • REPLICATION SLAVE
  • REPLICATION_SLAVE_ADMIN
  • GROUP_REPLICATION_STREAM
  • PROCESS
  • RELOAD
  • SYSTEM_VARIABLES_ADMIN
  • BINLOG_ADMIN
  • USAGE

You can control the behaviour and lifetime of the Kubernetes Job generated by this CR using the standard configuration options of the Kubernetes JobOpens in a new tab:

  • spec.backoffLimit
  • spec.ttlSecondsAfterFinished
  • spec.activeDeadlineSeconds

Provision a user manually

To provision a new user account manually, follow these steps:

  1. Get the credentials for the root user by running the following command:

    bash

    {NAMESPACE} is the Kubernetes Namespace where the Cennso Database is deployed, and {DBINSTANCE-NAME} is the metadata.name of the DBInstance claim.

  2. Connect to the MySQL primary instance using the root user account credentials:

    bash

    Enter the password when prompted. {MYSQL-PRIMARY-INSTANCE} is the address of the primary MySQL instance, for example the ps-db-{DBINSTANCE-NAME}-haproxy.{NAMESPACE}.svc Kubernetes Service, which routes the port 3306 to the primary MySQL instance.

  3. Create a new database userOpens in a new tab by running the following SQL command:

    sql

    Replace {USERNAME} with the desired username. Replace {PASSWORD} with the desired password.

  4. Grant the required privilegesOpens in a new tab to the user based on your application needs. For a list of available privileges, see MySQL privileges documentationOpens in a new tab.

    Example command to grant all privileges on a specific database:

    sql

    Replace {DATABASE} with your database name and {USERNAME} with the username created in step 3.

  5. Apply the permission changes:

    sql

For example, to create a user with all privileges on the example database, you can use the following SQL commands:

sql