|
| 1 | +English | [简体中文](../zh-cn/manage_mysql_user.md) |
| 2 | + |
| 3 | +Contents |
| 4 | +========== |
| 5 | + * [1. Prerequisite](#1-prerequisite) |
| 6 | + * [2. Create user accounts](#2-create-user-accounts) |
| 7 | + * [2.1 Validate CRD](#21-validate-crd) |
| 8 | + * [2.2 Create users](#22-create-users) |
| 9 | + * [2.3 View users](#23-view-users) |
| 10 | + * [3. Log on as a user](#3-log-on-as-a-user) |
| 11 | + * [4. Delete users](#4-delete-users) |
| 12 | + * [5. Parameters](#5-parameters) |
| 13 | + |
| 14 | +# Manage MySQL users with MysqlUser CRD |
| 15 | + |
| 16 | +## 1. Prerequisite |
| 17 | + |
| 18 | +* The [RadonDB MySQL cluster](deploy_radondb-mysql_operator_on_k8s.md) has been deployed. |
| 19 | + |
| 20 | +## 2. Create user accounts |
| 21 | + |
| 22 | +### 2.1 Validate CRD |
| 23 | + |
| 24 | +Run the following command, and the `mysqlusers.mysql.radondb.com` CRD is displayed. |
| 25 | + |
| 26 | +```plain |
| 27 | +kubectl get crd | grep mysqluser |
| 28 | +mysqlusers.mysql.radondb.com 2021-09-21T09:15:08Z |
| 29 | +``` |
| 30 | + |
| 31 | +### 2.2 Create users |
| 32 | + |
| 33 | +Run the following command to create a normal user named `normal_user` and a superuser named `super_user`. The user password is saved in the `sample-user-password` [Secret](https://kubernetes.io/docs/concepts/configuration/secret/). |
| 34 | + |
| 35 | +```plain |
| 36 | +kubectl apply -f https://github.com/radondb/radondb-mysql-kubernetes/releases/latest/download/mysql_v1alpha1_mysqluser.yaml |
| 37 | +``` |
| 38 | + |
| 39 | +> **Note:** In the example, the passwords for the normal user and superuser are both `RadonDB@123`. |
| 40 | +
|
| 41 | +### 2.3 View users |
| 42 | + |
| 43 | +```plain |
| 44 | +kubectl get mysqluser -o wide |
| 45 | +NAME USERNAME SUPERUSER HOSTS TLSTYPE CLUSTER NAMESPACE AVAILABLE SECRETNAME SECRETKEY |
| 46 | +normal-user normal_user false ["%"] NONE sample default True sample-user-password normalUser |
| 47 | +super-user super_user true ["%"] NONE sample default True sample-user-password superUser |
| 48 | +``` |
| 49 | + |
| 50 | +## 3. Log on as a user |
| 51 | + |
| 52 | +Run the following command to connect to the primary node of the MySQL cluster as `super_user`. |
| 53 | + |
| 54 | +```plain |
| 55 | +kubectl exec -it svc/sample-leader -c mysql -- mysql -usuper_user -pRadonDB@123 |
| 56 | +``` |
| 57 | + |
| 58 | +## 4. Delete users |
| 59 | +Run the following command to delete the `MysqlUser` CRD and the users created in the example. |
| 60 | +```plain |
| 61 | +kubectl delete mysqluser normal-user super-user |
| 62 | +``` |
| 63 | + |
| 64 | +## 5. Parameters |
| 65 | +| Parameters | Description | |
| 66 | +| ------------------------- | ------------------------------------------------------------------ | |
| 67 | +| user | User name | |
| 68 | +| hosts | Hosts allowed to access; `%` indicates all hosts can be accessed. | |
| 69 | +| withGrantOption | Whether a user can authorize other users; default value: `false` | |
| 70 | +| tlsOptions.type | TLS type; valid values: `NONE`/`SSL`/`X509`; default value: `NONE` | |
| 71 | +| permissions.database | Authorized databases; `*` indicates all databases are authorized. | |
| 72 | +| permissions.tables | Authorized tables; `*` indicates all tables are authorized. | |
| 73 | +| permissions.privileges | Privileges | |
| 74 | +| userOwner.clusterName | Name of the cluster that the user is in | |
| 75 | +| userOwner.nameSpace | Namespace of the cluster that the user is in | |
| 76 | +| secretSelector.secretName | Name of the Secret saving the user password | |
| 77 | +| secretSelector.secretKey | Key of the Secret saving the user password | |
| 78 | + |
| 79 | +> For more details, see [Account Management Statements](https://dev.mysql.com/doc/refman/5.7/en/account-management-statements.html). |
| 80 | +
|
| 81 | +> Note: Modifying `spec.user` directly will create a user with the new username. To create multiple users, ensure that `metadata.name` (CRD instance name) is consistent with `spec.user` (username). |
0 commit comments