MySQL-PXC 节点停机。
集群有足够 CPU、内存、存储等资源创建与 MySQL-PXC 相同规格的 MySQL-MGR 集群。
应用侧更新 MySQL 驱动至 MySQL-MGR 版本,您可以参考 Connectors and APIs。
使用 utf8mb4
字符。
应用侧使用 utf8mb4
。
数据库侧将库表转换成 utf8mb4
。
字符转换 SQL 如下。
# 将数据库字符集转换成 uft8mb4
ALTER DATABASE db_name DEFAULT CHARACTER SET = utf8mb4;
# 将表字符集转换成 uft8mb4
ALTER TABLE db_name.table_name CONVERT TO CHARACTER SET utf8mb4;
提示:表数据量越大,转换时间越长。
MySQL-MGR 强制要求表必须有主键。
即使没有主键的表,在导入 MySQL-MGR 时会自动为其创建 INVISIBLE
主键,建议业务侧使用显式主键。
提示:在 SHOW TABLE
时会显示出来,但 SELECT
会隐藏该字段。
查找没有主键的业务库表。
SELECT
CONCAT(t1.TABLE_SCHEMA, '.', t1.TABLE_NAME)
FROM
information_schema.tables t1
LEFT JOIN
(SELECT DISTINCT
t.TABLE_SCHEMA, t.TABLE_NAME, t.COLUMN_KEY
FROM
information_schema.`COLUMNS` t
WHERE
t.COLUMN_KEY = 'PRI') t2 ON t1.TABLE_SCHEMA = t2.TABLE_SCHEMA
AND t1.TABLE_NAME = t2.TABLE_NAME
WHERE
t1.TABLE_SCHEMA NOT IN ('information_schema' , 'mysql', 'performance_schema', 'sys')
AND t2.COLUMN_KEY IS NULL;
ALTER TABLE table_name ADD COLUMN id BITINT NOT NULL AUTO_INCREMENT PRIMARY KEY;
注意:使用本文中的示例代码时请替换实际实例参数。
MySQL-PXC 集群状态必须正常才能备份数据。
在左侧导航栏中,单击 MySQL-PXC。
单击 命名空间的名称。
单击 实例名称。
在 详情信息 页签中,基本信息、资源配置、ProxySQL 状态为 运行中。
在 拓扑 页签中,各 ProxySQL 和 MySQL 节点状态为 正常。
[root@g1-rm1 ~]# kubectl get pod -n demo-ds1 -owide | grep 'proxysql'
demo-proxysql-0 3/3 Running 0 4h57m 10.4.0.28 192.168.176.247 <none> <none>
demo-proxysql-1 3/3 Running 0 4h57m 10.4.0.49 192.168.177.35 <none> <none>
demo-proxysql-2 3/3 Running 0 4h57m 10.4.0.54 192.168.176.25 <none> <none>
# kubectl exec -it demo-proxysql-0 -c proxysql -n demo-ds1 -- mysql -uproxyadmin -h10.4.0.28 -p'jtr8eO0kS?lq' -P6032 -e "SELECT * FROM runtime_mysql_servers WHERE hostgroup_id=11"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------+------------------------------------------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| hostgroup_id | hostname | port | gtid_port | status | weight | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment |
+--------------+------------------------------------------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
| 11 | demo-pxc-0.demo-pxc.demo-ds1.svc.cluster.local | 3306 | 0 | ONLINE | 1001 | 0 | 600 | 0 | 0 | 0 | |
+--------------+------------------------------------------------+------+-----------+--------+--------+-------------+-----------------+---------------------+---------+----------------+---------+
根据输出的信息 demo-pxc-0.demo-pxc.demo-ds1.svc.cluster.local
确定读写节点所属 MySQL-PXC 的名称。
[root@g1-rm1 ~]# kubectl exec -it demo-pxc-0 -n demo-ds1 -- mysql -uroot -hlocalhost -p'jtr8eO0kS?lq' -e "SHOW GLOBAL STATUS LIKE 'wsrep_cluster_state_uuid'"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------------+--------------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------------+
| wsrep_cluster_state_uuid | 60fd1cc7-1628-11ee-90b2-c6e61fc5eaef |
+--------------------------+--------------------------------------+
[root@g1-rm1 ~]# kubectl exec -it demo-pxc-1 -n demo-ds1 -- mysql -uroot -hlocalhost -p'jtr8eO0kS?lq' -e "SHOW GLOBAL STATUS LIKE 'wsrep_cluster_state_uuid'"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------------+--------------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------------+
| wsrep_cluster_state_uuid | 60fd1cc7-1628-11ee-90b2-c6e61fc5eaef |
+--------------------------+--------------------------------------+
[root@g1-rm1 ~]# kubectl exec -it demo-pxc-2 -n demo-ds1 -- mysql -uroot -hlocalhost -p'jtr8eO0kS?lq' -e "SHOW GLOBAL STATUS LIKE 'wsrep_cluster_state_uuid'"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------------+--------------------------------------+
| Variable_name | Value |
+--------------------------+--------------------------------------+
| wsrep_cluster_state_uuid | 60fd1cc7-1628-11ee-90b2-c6e61fc5eaef |
+--------------------------+--------------------------------------+
注意:请勿在应用侧进行写入操作,否则将导致备份不完整。
在左侧导航栏中,单击 MySQL-PXC。
单击 命名空间的名称。
单击 实例名称。
单击 操作 > 更新。
单击 YAML。
将 pxc.proxysql.size
参数值改为 0
。
单击 更新。
注意:创建的 MySQL-MGR 实例的资源规格应不低于 MySQL-PXC 实例的资源规格。
在左侧导航栏中,单击 MySQL-MGR。
单击 命名空间的名称。
单击 实例名称。
在 详情信息 页签中,基本信息、资源配置、MySQL Router 状态为 运行中。
在 YAML 页签中,status.conditions.type
和 status.state
值为 ready
。
MEMBER_ROLE
为 PRIMARY
的节点则是 MySQL-MGR 的读写节点。
[root@g1-rm1 ~]# kubectl exec -it demo-0 -c mysql -n demo-ds1 -- mysql -uroot -hlocalhost -p'GLK1nqWF17JqrvpJ' -e "SELECT * FROM performance_schema.replication_group_members"
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+----------------------------+
| CHANNEL_NAME | MEMBER_ID | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+----------------------------+
| group_replication_applier | 5bc1839e-162a-11ee-a212-00000071f44e | demo-0.demo | 3306 | ONLINE | PRIMARY | 8.0.30 | MySQL |
| group_replication_applier | 6f9f1f36-162a-11ee-a21a-000000ade638 | demo-1.demo | 3306 | ONLINE | SECONDARY | 8.0.30 | MySQL |
| group_replication_applier | 96300b66-162a-11ee-a33f-00000093bb13 | demo-2.demo | 3306 | ONLINE | SECONDARY | 8.0.30 | MySQL |
+---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+----------------------------+
MySQL系统库:排除 information_schema
、mysql
、performance_schema
、sys
。
业务数据库:需要将业务数据库记录下来,使用 mysqldump
备份工具进行备份时,通过 -B
选项指定需要备份的数据库。
例如,在下面查询到的数据库列表中,需要备份 test1
、test2
、test3
业务数据库。
[root@g1-rm1 ~]# kubectl exec -it demo-pxc-0 -n demo-ds1 -c pxc -- mysql -uroot -p'jtr8eO0kS?lq' -h10.4.0.35 -e "SHOW DATABASES"
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test1 |
| test2 |
| test3 |
+--------------------+
在 Container Platform 视图左侧导航栏中,单击 存储 > 持久卷声明。
单击 创建持久卷声明。
填写 PVC 配置参数。
注意:存储类使用 TopoLVM。
单击 创建,PVC 状态为 等待挂载后绑定。
请联系 平台管理员 根据以下 YAML 创建 PV。创建 PV 后,查看 PVC 状态为 已绑定。
apiVersion: v1
kind: PersistentVolume
metadata:
name: mgr-backcup-pv # pv名称
annotations: {}
labels: {}
spec:
capacity:
storage: 5Gi # 指定存储容量
csi:
driver: topolvm.cybozu.com
volumeHandle: baef103d-d2de-4ca9-bb4b-1dad722975b9
fsType: xfs
accessModes:
- ReadWriteOnce
claimRef:
kind: PersistentVolumeClaim
namespace: demo-ds1 # 指定命名空间
name: mgr-backcup-pvc # 指定要绑定PVC的名称
persistentVolumeReclaimPolicy: Delete
storageClassName: sc-topolvm # 指定存储类
volumeMode: Filesystem
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: topology.topolvm.cybozu.com/node
operator: In
values:
- 192.168.177.35 # 指定创建PV所在的宿主机IP
查看 MySQL-MGR 的镜像地址。
[root@g1-rm1 ~]# kubectl get pod demo-0 -n demo-ds1 -o yaml | grep 'image:' | grep 'mysql-server'
image: idc1.xmysql.com/3rdparty/mysql/mysql-server:8.0.30-cfd84cde
image: idc1.xmysql.com/3rdparty/mysql/mysql-server:8.0.30-cfd84cde
在 Container Platform 视图左侧导航栏中,单击 计算组件 > 部署。
单击 创建部署。
选择 输入 方式,填写镜像地址,单击 确定。
在 容器组 > 存储卷 中单击 添加。
填写存储卷配置,使用本文中创建的 PVC 作为 MySQL 容器的存储卷。
单击 添加。
填写容器配置。
单击 创建。
获取 MySQL-PXC 读写 Pod 的 IP。
[root@g1-rm1 ~]# kubectl get pod -o wide -n demo-ds1 | grep 'pxc'
demo-pxc-0 3/3 Running 0 4d4h 10.4.0.35 192.168.176.227 <none> <none>
demo-pxc-1 3/3 Running 0 4d4h 10.4.0.70 192.168.176.247 <none> <none>
demo-pxc-2 3/3 Running 0 4d4h 10.4.0.162 192.168.176.25 <none> <none>
获取 MySQL-PXC 的 root 密码。
[root@g1-rm1 ~]# kubectl exec -it demo-pxc-0 -n demo-ds1 -c pxc -- /bin/bash
bash-5.1$ env | grep 'MYSQL_ROOT_PASSWORD'
MYSQL_ROOT_PASSWORD=jtr8eO0kS?lq
进入本文中创建的 MySQL 备份恢复容器,例如 Pod 名称为 mgr-backcup-9f87d46c4-kwkps
。
[root@g1-rm1 ~]# kubectl exec -it mgr-backcup-9f87d46c4-kwkps -n demo-ds1 -- /bin/bash
提示:Pod 名称可在该部署的容器组列表中查看。
备份业务数据库。
[root@mgr-backcup-9f87d46c4-kwkps /]# mysqldump --user=root --host=10.4.0.35 --password='jtr8eO0kS?lq' --column-statistics=0 --single-transaction --source-data=1 --set-gtid-purged=AUTO --triggers -R -E -B test1 test2 test3 > /var/lib/mysql/$(date +"%Y%m%d%H%M%S")_fullbackup.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
参数说明:
--password
:MySQL-PXC 的 root 密码。
--host
:指定 MySQL-PXC 的读写 Pod 的 IP 地址。
-B
:指定需要备份 MySQL-PXC 的业务数据库名称,以空格分隔。
查看逻辑备份的大小。
[root@mgr-backcup-9f87d46c4-kwkps /]# du -lh /var/lib/mysql/20230705102203_fullbackup.sql
677M /var/lib/mysql/20230705102203_fullbackup.sql
[root@g1-rm1 ~]# kubectl get pod demo-0 -n demo-ds1 -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
demo-0 3/3 Running 0 20h 10.4.0.170 192.168.177.35 <none> <none>
[root@g1-rm1 ~]# kubectl exec -it mgr-backcup-9f87d46c4-kwkps -n demo-ds1 -- /bin/bash
[root@mgr-backcup-9f87d46c4-kwkps /]# mysql -uroot -h10.4.0.170 -p'GLK1nqWF17JqrvpJ' < /var/lib/mysql/20230705102203_fullbackup.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@mgr-backcup-9f87d46c4-kwkps /]# mysql -uroot -h10.4.0.170 -p'GLK1nqWF17JqrvpJ'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 367123
Server version: 8.0.30 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Cannot read termcap database;
using dumb terminal settings.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW DATABASES;
+-------------------------------+
| Database |
+-------------------------------+
| information_schema |
| mysql |
| mysql_innodb_cluster_metadata |
| performance_schema |
| sys |
| test1 |
| test2 |
| test3 |
+-------------------------------+
8 rows in set (0.01 sec)
mysql> use test1;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> SHOW TABLES;
+-----------------+
| Tables_in_test1 |
+-----------------+
| sbtest1 |
| sbtest2 |
| sbtest3 |
| sbtest4 |
| sbtest5 |
| sbtest6 |
+-----------------+
6 rows in set (0.01 sec)
mysql> SELECT COUNT(1) FROM test1.sbtest1;
+----------+
| COUNT(1) |
+----------+
| 200000 |
+----------+
1 row in set (0.03 sec)
mysql> SHOW CREATE TABLE test2.sbtest1\G
*************************** 1. row ***************************
Table: sbtest1
Create Table: CREATE TABLE `sbtest1` (
`my_row_id` bigint unsigned NOT NULL AUTO_INCREMENT /*!80023 INVISIBLE */,
`k` int NOT NULL DEFAULT '0',
`c` char(120) NOT NULL DEFAULT '',
`pad` char(60) NOT NULL DEFAULT '',
PRIMARY KEY (`my_row_id`),
KEY `k_1` (`k`)
) ENGINE=InnoDB AUTO_INCREMENT=200003 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
1 row in set (0.00 sec)
mysql> SHOW CREATE TABLE test3.sbtest1\G
*************************** 1. row ***************************
Table: sbtest1
Create Table: CREATE TABLE `sbtest1` (
`id` int NOT NULL AUTO_INCREMENT,
`k` int NOT NULL DEFAULT '0',
`c` char(120) NOT NULL DEFAULT '',
`pad` char(60) NOT NULL DEFAULT '',
PRIMARY KEY (`id`),
KEY `k_1` (`k`)
) ENGINE=InnoDB AUTO_INCREMENT=600001 DEFAULT CHARSET=utf8mb3
1 row in set (0.00 sec)
进入 MySQL-MGR 的 Pod 中备份 MySQL-PXC 用户表。
[root@g1-rm1 ~]# kubectl exec -it mgr-backcup-9f87d46c4-kwkps -n demo-ds1 -- /bin/bash
[root@mgr-backcup-9f87d46c4-kwkps /]# mysqldump --user=root --host=10.4.0.35 --password='jtr8eO0kS?lq' --column-statistics=0 --single-transaction --source-data=1 --set-gtid-purged=AUTO --triggers -R -E mysql user > /var/lib/mysql/$(date +"%Y%m%d%H%M%S")_mysql.user.sql
[root@mgr-backcup-9f87d46c4-kwkps /]# du -lh /var/lib/mysql/20230705132502_mysql.user.sql
8.0K /var/lib/mysql/20230705132502_mysql.user.sql
获取账号的 SQL 语句 INSERT INTO
。
[root@mgr-backcup-9f87d46c4-kwkps /]# cat /var/lib/mysql/20230705132502_mysql.user.sql | grep 'INSERT INTO'
INSERT INTO `user` VALUES ('localhost','root','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*40C19F6316A46A0E68DCCBC18034271BE5DDD704','N','2023-06-29 02:55:28',NULL,'N'),('localhost','mysql.session','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0,'mysql_native_password','*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE','N','2023-06-29 02:55:09',NULL,'Y'),('localhost','mysql.sys','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0,'mysql_native_password','*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE','N','2023-06-29 02:55:09',NULL,'Y'),('%','root','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*40C19F6316A46A0E68DCCBC18034271BE5DDD704','N','2023-06-29 02:55:28',NULL,'N'),('%','operator','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*40C19F6316A46A0E68DCCBC18034271BE5DDD704','N','2023-06-29 02:55:28',NULL,'N'),('%','xtrabackup','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*40C19F6316A46A0E68DCCBC18034271BE5DDD704','N','2023-06-29 02:55:28',NULL,'N'),('%','monitor','Y','N','N','N','N','N','Y','N','Y','N','N','N','N','N','N','Y','N','N','N','N','Y','N','N','N','N','N','N','N','N','','','','',0,0,0,100,'mysql_native_password','*40C19F6316A46A0E68DCCBC18034271BE5DDD704','N','2023-06-29 02:55:28',NULL,'N'),('localhost','clustercheck','N','N','N','N','N','N','N','N','Y','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','N','','','','',0,0,0,0,'mysql_native_password','*40C19F6316A46A0E68DCCBC18034271BE5DDD704','N','2023-06-29 02:55:28',NULL,'N'),('%','test_user_2','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*BFC6130681D565DDE4C938BCDCD36073776A8F99','N','2023-07-03 07:13:13',NULL,'N'),('%','test_user_3','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*BFC6130681D565DDE4C938BCDCD36073776A8F99','N','2023-07-03 07:13:13',NULL,'N'),('%','test_user_1','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*BFC6130681D565DDE4C938BCDCD36073776A8F99','N','2023-07-03 07:14:52',NULL,'N');
删除 MySQL-PXC 的系统用户,仅保留业务应用账号。
删除系统账号:'localhost','root'
、'localhost','mysql.session'
、'localhost','mysql.sys'
、'%','root'
、'%','operator'
、'%','monitor'
、'localhost','clustercheck'
保留业务应用账号:test_user_1
、test_user_2
、test_user_3
INSERT INTO `user` VALUES ('%','test_user_2','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*BFC6130681D565DDE4C938BCDCD36073776A8F99','N','2023-07-03 07:13:13',NULL,'N'),('%','test_user_3','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*BFC6130681D565DDE4C938BCDCD36073776A8F99','N','2023-07-03 07:13:13',NULL,'N'),('%','test_user_1','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*BFC6130681D565DDE4C938BCDCD36073776A8F99','N','2023-07-03 07:14:52',NULL,'N');
修改插入账号记录。
注意:禁止导入root账号。
MySQL-MGR 比 MySQL-PXC 的 mysql.user
增加了 6 个字段,因此插入账号记录时需要增加 6 个字段: Create_role_priv: Y
、Drop_role_priv: Y
、Password_reuse_history: NULL
、Password_reuse_time: NULL
、Password_require_current: NULL
、User_attributes: NULL
,即每条插入记录后增加:, 'Y', 'Y', NULL, NULL, NULL, NULL
字段值。
INSERT INTO `user` VALUES ('%','test_user_2','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*BFC6130681D565DDE4C938BCDCD36073776A8F99','N','2023-07-03 07:13:13',NULL,'N', 'Y', 'Y', NULL, NULL, NULL, NULL),('%','test_user_3','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*BFC6130681D565DDE4C938BCDCD36073776A8F99','N','2023-07-03 07:13:13',NULL,'N', 'Y', 'Y', NULL, NULL, NULL, NULL),('%','test_user_1','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*BFC6130681D565DDE4C938BCDCD36073776A8F99','N','2023-07-03 07:14:52',NULL,'N', 'Y', 'Y', NULL, NULL, NULL, NULL);
向 MySQL-MGR 插入账号记录。
[root@g1-rm1 ~]# kubectl exec -it mgr-backcup-9f87d46c4-kwkps -n demo-ds1 -- /bin/bash
[root@mgr-backcup-9f87d46c4-kwkps /]# mysql -uroot -h10.4.0.170 -p'GLK1nqWF17JqrvpJ'
mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
mysql> INSERT INTO `user` VALUES ('%','test_user_2','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','
Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*BFC6130681D565DDE4C938BCDCD36073776A8F99','N
','2023-07-03 07:13:13',NULL,'N', 'Y', 'Y', NULL, NULL, NULL, NULL),('%','test_user_3','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','N
','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,'mysql_native_password','*BFC613068
1D565DDE4C938BCDCD36073776A8F99','N','2023-07-03 07:13:13',NULL,'N', 'Y', 'Y', NULL, NULL, NULL, NULL),('%','test_user_1','Y','Y'
,'Y','Y','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',0,0,0,0,
'mysql_native_password','*BFC6130681D565DDE4C938BCDCD36073776A8F99','N','2023-07-03 07:14:52',NULL,'N', 'Y', 'Y', NULL, NULL, NUL
L, NULL);
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> SELECT user,host,plugin FROM mysql.user WHERE user LIKE 'test%';
+-------------+------+-----------------------+
| user | host | plugin |
+-------------+------+-----------------------+
| test_user_1 | % | mysql_native_password |
| test_user_2 | % | mysql_native_password |
| test_user_3 | % | mysql_native_password |
+-------------+------+-----------------------+
3 rows in set (0.00 sec)
验证账号是否正常。
[root@g1-rm1 ~]# kubectl get pod -n demo-ds1 -o wide | grep demo
demo-0 3/3 Running 0 4d11h 10.4.0.170 192.168.177.35 <none> <none>
demo-1 3/3 Running 1 (4d11h ago) 4d11h 10.4.0.176 192.168.176.247 <none> <none>
demo-2 3/3 Running 1 (4d11h ago) 4d11h 10.4.0.198 192.168.176.227 <none> <none>
[root@mgr-backcup-9f87d46c4-kwkps /]# mysql -utest_user_1 -h10.4.0.170 -p'zEjQM96Ha1=v' -e "SELECT USER()";
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------------------+
| USER() |
+-------------------------+
| test_user_1@10.4.210.58 |
+-------------------------+
[root@mgr-backcup-9f87d46c4-kwkps /]# mysql -utest_user_2 -h10.4.0.176 -p'zEjQM96Ha1=v' -e "SELECT USER()";
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------------------+
| USER() |
+-------------------------+
| test_user_2@10.4.210.58 |
+-------------------------+
[root@mgr-backcup-9f87d46c4-kwkps /]# mysql -utest_user_3 -h10.4.0.198 -p'zEjQM96Ha1=v' -e "SELECT USER()";
mysql: [Warning] Using a password on the command line interface can be insecure.
+-------------------------+
| USER() |
+-------------------------+
| test_user_3@10.4.210.58 |
+-------------------------+
当前集群资源不足,没有部署同规格 MySQL-MGR 集群时,可以在宿主机上使用 mysqldump
进行备份。
操作步骤:
MySQL-PXC 集群状态正常。
停止业务读写,将 ProxySQL 副本集设置为 0。
对 MySQL-PXC 进行备份。