首页 > 数据库 > > GreatDB数据库的管理和使用(2)
[root@greatdb1 ~]# greatsqld --version /greatdb/svr/greatdb-cluster-5.0.7-fbb08fbed60-Linux-glibc2.17-x86_64/bin/greatsqld Ver 8.0.25-15-greatdbcluster5.0.7-GA for Linux on x86_64 (GreatDB Cluster, Release GA, Revision fbb08fbed60) [root@greatdb1 ~]# greatdbd --version /greatdb/svr/greatdb-cluster-5.0.7-fbb08fbed60-Linux-glibc2.17-x86_64/bin/greatsqld Ver 8.0.25-15-greatdbcluster5.0.7-GA for Linux on x86_64 (GreatDB Cluster, Release GA, Revision fbb08fbed60)
[root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P3306 GreatDB Cluster[(none)]> select version(); +----------------------------------+ | version() | +----------------------------------+ | 8.0.25-15-greatdbcluster5.0.7-GA | +----------------------------------+ 1 row in set (0.00 sec)
[root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P3306 GreatDB Cluster[(none)]> show global variables like 'greatdb_version'; +-----------------+---------+ | Variable_name | Value | +-----------------+---------+ | greatdb_version | 5.0.7.3 | +-----------------+---------+ 1 row in set (0.00 sec)
[root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P3306 GreatDB Cluster[(none)]> \s -------------- greatsql Ver 8.0.25-15-greatdbcluster5.0.7-GA for Linux on x86_64 (GreatDB Cluster, Release GA, Revision fbb08fbed60) Connection id: 389 Current database: Current user: greatdb@192.168.0.81 SSL: Cipher in use is ECDHE-RSA-AES128-GCM-SHA256 Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 8.0.25-15-greatdbcluster5.0.7-GA GreatDB Cluster, Release GA, Revision fbb08fbed60 Protocol version: 10 Connection: 192.168.0.81 via TCP/IP Server characterset: utf8mb4 Db characterset: utf8mb4 Client characterset: utf8mb4 Conn. characterset: utf8mb4 TCP port: 3306 Binary data as: Hexadecimal Uptime: 29 min 43 sec Threads: 14 Questions: 1562 Slow queries: 3 Opens: 406 Flush tables: 4 Open tables: 192 Queries per second avg: 0.876 -------------- GreatDB Cluster[(none)]>
[root@greatdb1 ~]# greatsqladmin -ugreatdb -pgreatdb -h192.168.0.81 -P3306 shutdown 或 [root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P3306 GreatDB Cluster[(none)]> shutdown; 或 GreatDB Cluster[(none)]> CALL mysql.greatdb_stop_sqlnode_server('192.168.0.83', 3306); Query OK, 1 row affected (0.04 sec)
[root@greatdb1 ~]# cat /greatdb/sh/sqlnode3306.sh #!/bin/sh MYSQL_BASE=/greatdb/svr/greatdb MYSQL_CONF=/greatdb/conf/sqlnode3306.cnf MYSQL_SOCKET=/greatdb/dbdata/sqlnode3306/data/greatdb.sock export PATH=$MYSQL_BASE/bin:/usr/sbin:/usr/bin:/sbin:/bin export LD_LIBRARY_PATH=$MYSQL_BASE/lib if [ "$1" = "stop" ] ; then $MYSQL_BASE/bin/greatsqladmin --defaults-file=$MYSQL_CONF -uroot -p --socket=$MYSQL_SOCKET shutdown elif [ "$1" = "restart" ]; then $MYSQL_BASE/bin/greatsqladmin --defaults-file=$MYSQL_CONF -uroot -p --socket=$MYSQL_SOCKET shutdown $MYSQL_BASE/bin/greatsqld_safe --defaults-file=$MYSQL_CONF & elif [ "$1" = "start" ]; then $MYSQL_BASE/bin/greatsqld_safe --defaults-file=$MYSQL_CONF & else echo "usage: $0 start|stop|restart" fi
[root@greatdb1 ~]# /greatdb/sh/sqlnode3306.sh usage: /greatdb/sh/sqlnode3306.sh start|stop|restart [root@greatdb1 ~]# /greatdb/sh/sqlnode3306.sh stop Enter password:

[root@greatdb1 ~]# greatsqld_safe --defaults-file=/greatdb/conf/sqlnode3306.cnf &
[root@greatdb1 ~]# /greatdb/sh/sqlnode3306.sh start

[root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P3306 GreatDB Cluster[(none)]> restart; 或 GreatDB Cluster[(none)]> CALL mysql.greatdb_restart_sqlnode_server('192.168.0.83', 3306); Query OK, 1 row affected (0.02 sec)
[root@greatdb1 ~]# /greatdb/sh/sqlnode3306.sh restart Enter password:
[root@greatdb1 ~]# greatsqladmin -ugreatdb -pgreatdb -h192.168.0.81 -P4406 shutdown 或 [root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P4406 GreatDB Cluster[(none)]> shutdown;
[root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P3306 GreatDB Cluster[(none)]> select NODE_ID,NODE_NAME,SHARD_ID,SHARD_NAME,HOST,PORT,NODE_STATE from information_schema.GREATDB_DATANODES; +---------+-----------+----------+------------+--------------+------+---------------+ | NODE_ID | NODE_NAME | SHARD_ID | SHARD_NAME | HOST | PORT | NODE_STATE | +---------+-----------+----------+------------+--------------+------+---------------+ | 36 | datanode1 | 36 | shard1 | 192.168.0.81 | 4406 | STATE_STANDBY | | 43 | datanode2 | 36 | shard1 | 192.168.0.82 | 4406 | STATE_ACTIVE | | 50 | datanode3 | 36 | shard1 | 192.168.0.83 | 4406 | STATE_STANDBY | | 64 | datanode4 | 64 | shard2 | 192.168.0.81 | 4407 | STATE_ACTIVE | | 71 | datanode5 | 64 | shard2 | 192.168.0.82 | 4407 | STATE_STANDBY | | 78 | datanode6 | 64 | shard2 | 192.168.0.83 | 4407 | STATE_STANDBY | | 92 | datanode7 | 92 | shard3 | 192.168.0.81 | 4408 | STATE_ACTIVE | | 99 | datanode8 | 92 | shard3 | 192.168.0.82 | 4408 | STATE_STANDBY | | 106 | datanode9 | 92 | shard3 | 192.168.0.83 | 4408 | STATE_STANDBY | +---------+-----------+----------+------------+--------------+------+---------------+ 9 rows in set (0.01 sec) GreatDB Cluster[(none)]> call mysql.greatdb_stop_datanode_server('datanode1'); Query OK, 1 row affected (0.02 sec)
[root@greatdb1 ~]# cat /greatdb/sh/datanode4406.sh #!/bin/sh MYSQL_BASE=/greatdb/svr/greatdb MYSQL_CONF=/greatdb/conf/datanode4406.cnf MYSQL_SOCKET=/greatdb/dbdata/datanode4406/data/greatdb.sock export PATH=$MYSQL_BASE/bin:/usr/sbin:/usr/bin:/sbin:/bin export LD_LIBRARY_PATH=$MYSQL_BASE/lib if [ "$1" = "stop" ] ; then $MYSQL_BASE/bin/greatsqladmin --defaults-file=$MYSQL_CONF -uroot -p --socket=$MYSQL_SOCKET shutdown elif [ "$1" = "restart" ]; then $MYSQL_BASE/bin/greatsqladmin --defaults-file=$MYSQL_CONF -uroot -p --socket=$MYSQL_SOCKET shutdown $MYSQL_BASE/bin/greatdbd_safe --defaults-file=$MYSQL_CONF & elif [ "$1" = "start" ]; then $MYSQL_BASE/bin/greatdbd_safe --defaults-file=$MYSQL_CONF & else echo "usage: $0 start|stop|restart" fi
[root@greatdb1 ~]# /greatdb/sh/datanode4406.sh usage: /greatdb/sh/datanode4406.sh start|stop|restart [root@greatdb1 ~]# /greatdb/sh/datanode4406.sh stop Enter password:

[root@greatdb1 ~]# greatsqld_safe --defaults-file=/greatdb/conf/datanode4406.cnf &
[root@greatdb1 ~]# /greatdb/sh/datanode4406.sh start

DataNode 重启以后状态由原来的 ACTIVE 变为 STANDBY 。
[root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P4406 GreatDB Cluster[(none)]> restart;
[root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P3306 GreatDB Cluster[(none)]> select NODE_ID,NODE_NAME,SHARD_ID,SHARD_NAME,HOST,PORT,NODE_STATE from information_schema.GREATDB_DATANODES; +---------+-----------+----------+------------+--------------+------+---------------+ | NODE_ID | NODE_NAME | SHARD_ID | SHARD_NAME | HOST | PORT | NODE_STATE | +---------+-----------+----------+------------+--------------+------+---------------+ | 36 | datanode1 | 36 | shard1 | 192.168.0.81 | 4406 | STATE_STANDBY | | 43 | datanode2 | 36 | shard1 | 192.168.0.82 | 4406 | STATE_ACTIVE | | 50 | datanode3 | 36 | shard1 | 192.168.0.83 | 4406 | STATE_STANDBY | | 64 | datanode4 | 64 | shard2 | 192.168.0.81 | 4407 | STATE_ACTIVE | | 71 | datanode5 | 64 | shard2 | 192.168.0.82 | 4407 | STATE_STANDBY | | 78 | datanode6 | 64 | shard2 | 192.168.0.83 | 4407 | STATE_STANDBY | | 92 | datanode7 | 92 | shard3 | 192.168.0.81 | 4408 | STATE_ACTIVE | | 99 | datanode8 | 92 | shard3 | 192.168.0.82 | 4408 | STATE_STANDBY | | 106 | datanode9 | 92 | shard3 | 192.168.0.83 | 4408 | STATE_STANDBY | +---------+-----------+----------+------------+--------------+------+---------------+ 9 rows in set (0.01 sec) GreatDB Cluster[(none)]> call mysql.greatdb_restart_datanode_server('datanode1'); Query OK, 1 row affected (0.02 sec)
[root@greatdb1 ~]# /greatdb/sh/datanode4406.sh restart Enter password:
[root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P3306 GreatDB Cluster[(none)]> show processlist;

每个 SHARD 是一套主从复制,STATE_ACTIVE 状态的是主节点,可以对 SqlNode 提供读写服务,STATE_STANDBY 状态的为从节点,只提供只读服务。

# 人工手动做主从角色切换,例如将 shard1 的主节点切换到 datanode2 上 [root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P3306 # 传递两个参数,一个是要做主从角色切换的 SHARD_NAME,另一个是要将主节点切换到哪个 NODE_NAME 上。 GreatDB Cluster[(none)]> call mysql.greatdb_change_shard_primary_node('shard1','datanode2'); Query OK, 1 row affected (1.08 sec)

[root@greatdb1 ~]# /greatdb/sh/sqlnode3306.sh stop [root@greatdb2 ~]# /greatdb/sh/sqlnode3306.sh stop [root@greatdb3 ~]# /greatdb/sh/sqlnode3306.sh stop
[root@greatdb1 ~]# /greatdb/sh/datanode4406.sh stop [root@greatdb1 ~]# /greatdb/sh/datanode4407.sh stop [root@greatdb1 ~]# /greatdb/sh/datanode4408.sh stop [root@greatdb2 ~]# /greatdb/sh/datanode4406.sh stop [root@greatdb2 ~]# /greatdb/sh/datanode4407.sh stop [root@greatdb2 ~]# /greatdb/sh/datanode4408.sh stop [root@greatdb3 ~]# /greatdb/sh/datanode4406.sh stop [root@greatdb3 ~]# /greatdb/sh/datanode4407.sh stop [root@greatdb3 ~]# /greatdb/sh/datanode4408.sh stop
[root@greatdb1 ~]# /greatdb/sh/datanode4406.sh start [root@greatdb1 ~]# /greatdb/sh/datanode4407.sh start [root@greatdb1 ~]# /greatdb/sh/datanode4408.sh start [root@greatdb2 ~]# /greatdb/sh/datanode4406.sh start [root@greatdb2 ~]# /greatdb/sh/datanode4407.sh start [root@greatdb2 ~]# /greatdb/sh/datanode4408.sh start [root@greatdb3 ~]# /greatdb/sh/datanode4406.sh start [root@greatdb3 ~]# /greatdb/sh/datanode4407.sh start [root@greatdb3 ~]# /greatdb/sh/datanode4408.sh start
[root@greatdb1 ~]# /greatdb/sh/sqlnode3306.sh start [root@greatdb2 ~]# /greatdb/sh/sqlnode3306.sh start [root@greatdb3 ~]# /greatdb/sh/sqlnode3306.sh start
[root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P3306 GreatDB Cluster[(none)]> call mysql.greatdb_restart_cluster; Query OK, 1 row affected (11.15 sec)




[root@greatdb1 log]# pwd /greatdb/dbdata/datanode4406/log [root@greatdb1 log]# ll total 4227132 # BINLOG -rw-r----- 1 greatdb greatdb 232 Feb 27 01:38 binlog.000011 -rw-r----- 1 greatdb greatdb 211 Feb 27 01:38 binlog.000012 -rw-r----- 1 greatdb greatdb 894 Feb 27 01:42 binlog.000013 -rw-r----- 1 greatdb greatdb 141 Feb 27 01:40 binlog.index # REDO LOG -rw-r-----. 1 greatdb greatdb 1073741824 Feb 27 01:44 ib_logfile0 -rw-r-----. 1 greatdb greatdb 1073741824 Feb 26 2021 ib_logfile1 -rw-r-----. 1 greatdb greatdb 1073741824 Feb 26 2021 ib_logfile2 -rw-r-----. 1 greatdb greatdb 1073741824 Feb 26 2021 ib_logfile3 # RELAY LOG -rw-r----- 1 greatdb greatdb 220 Feb 27 01:40 relaylog-group_replication_applier.000021 -rw-r----- 1 greatdb greatdb 341 Feb 27 01:42 relaylog-group_replication_applier.000022 -rw-r----- 1 greatdb greatdb 967 Feb 27 01:42 relaylog-group_replication_applier.000023 -rw-r----- 1 greatdb greatdb 225 Feb 27 01:42 relaylog-group_replication_applier.index -rw-r-----. 1 greatdb greatdb 221 Feb 26 2021 relaylog-group_replication_recovery.000001 -rw-r-----. 1 greatdb greatdb 342 Feb 26 2021 relaylog-group_replication_recovery.000002 -rw-r-----. 1 greatdb greatdb 292 Feb 26 2021 relaylog-group_replication_recovery.000003 -rw-r----- 1 greatdb greatdb 221 Feb 27 01:38 relaylog-group_replication_recovery.000004 -rw-r----- 1 greatdb greatdb 171 Feb 27 01:38 relaylog-group_replication_recovery.000005 -rw-r----- 1 greatdb greatdb 152 Feb 27 01:40 relaylog-group_replication_recovery.000006 -rw-r----- 1 greatdb greatdb 456 Feb 27 01:40 relaylog-group_replication_recovery.index # UNDO LOG -rw-r-----. 1 greatdb greatdb 16777216 Feb 27 01:44 undo_001 -rw-r-----. 1 greatdb greatdb 16777216 Feb 27 01:44 undo_002
[root@greatdb1 logs]# pwd /greatdb/logs [root@greatdb1 logs]# ls -lrt error* -rw-r-----. 1 greatdb greatdb 246739 Feb 26 2021 error3306.log -rw-r-----. 1 greatdb greatdb 26872 Feb 26 2021 error4408.log -rw-r-----. 1 greatdb greatdb 280950 Feb 26 2021 error4406.log -rw-r-----. 1 greatdb greatdb 41437 Feb 26 2021 error4407.log
[root@greatdb1 logs]# pwd /greatdb/logs [root@greatdb1 logs]# ls -lrt slow* -rw-r-----. 1 greatdb greatdb 3430 Feb 27 01:40 slow4406.log -rw-r-----. 1 greatdb greatdb 1581 Feb 27 01:40 slow4407.log -rw-r-----. 1 greatdb greatdb 1317 Feb 27 01:40 slow4408.log -rw-r-----. 1 greatdb greatdb 4445 Feb 27 01:42 slow3306.log
[root@greatdb1 logs]# yum -y groupinstall perl* [root@greatdb1 logs]# pt-query-digest slow3306.log > a.log [root@greatdb1 logs]# cat a.log

general log 默认是关闭的,可以设置 general_log 参数开启
[root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P3306 GreatDB Cluster[(none)]> show variables like 'general%'; +------------------+-------------------------------+ | Variable_name | Value | +------------------+-------------------------------+ | general_log | OFF | | general_log_file | /greatdb/logs/general3306.log | +------------------+-------------------------------+ 2 rows in set (0.06 sec) # 配置参数开启 general_log GreatDB Cluster[(none)]> set global general_log=ON; Query OK, rows affected (0.00 sec) # 配置参数关闭 general_log GreatDB Cluster[(none)]> set global general_log=ON; Query OK, rows affected (0.00 sec)
GreatDB 引入新的 GreatDB 存储引擎,支持多种表分布策略。
[root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P3306 GreatDB Cluster> create table test.t_normal(c1 int primary key, c2 int) engine=greatdb comment "disttype=normal";
GreatDB Cluster[(none)]> select * from information_schema.greatdb_table_distribution; +-------------+------------+----------------+-----------------+------------+----------------+--------------+ | SCHEMA_NAME | TABLE_NAME | BACKEND_ENGINE | DISTRIBUTE_MODE | SHARD_NAME | PARTITION_NAME | PARTITION_ID | +-------------+------------+----------------+-----------------+------------+----------------+--------------+ | test | t_normal | InnoDB | NORMAL | shard2 | | 0 | +-------------+------------+----------------+-----------------+------------+----------------+--------------+ 1 row in set (0.02 sec)
information_schema.greatdb_table_distribution 可以查询表在 Shard 上的分布情况,可以发现 t_normal 表只分布在 shard2 上。
GreatDB Cluster> create table test.t_global(c1 int primary key, c2 int) engine=greatdb comment "disttype=global";
GreatDB Cluster[(none)]> select * from information_schema.greatdb_table_distribution where TABLE_NAME='t_global'; +-------------+------------+----------------+-----------------+------------+----------------+--------------+ | SCHEMA_NAME | TABLE_NAME | BACKEND_ENGINE | DISTRIBUTE_MODE | SHARD_NAME | PARTITION_NAME | PARTITION_ID | +-------------+------------+----------------+-----------------+------------+----------------+--------------+ | test | t_global | InnoDB | GLOBAL | shard1 | | 0 | | test | t_global | InnoDB | GLOBAL | shard2 | | 0 | | test | t_global | InnoDB | GLOBAL | shard3 | | 0 | +-------------+------------+----------------+-----------------+------------+----------------+--------------+ 3 rows in set (0.01 sec)
由此可见,Global表被分到了所有的 Shard 上,下面向Global表插入数据,观察数据在 Shard 上的存储情况
GreatDB Cluster[(none)]> insert into test.t_global values (1,1),(2,2),(3,3); Query OK, 3 rows affected (0.06 sec) Records: 3 Duplicates: 0 Warnings: 0 GreatDB Cluster[(none)]> select * from test.t_global; +----+------+ | c1 | c2 | +----+------+ | 1 | 1 | | 2 | 2 | | 3 | 3 | +----+------+ 3 rows in set (0.00 sec)
连接到 DataNode 节点查看表的数据
[root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P4406 -e 'select * from test.t_global' greatsql: [Warning] Using a password on the command line interface can be insecure. +-------------+----+------+ | _hidden_pk_ | c1 | c2 | +-------------+----+------+ | 1 | 1 | 1 | | 8 | 2 | 2 | | 15 | 3 | 3 | +-------------+----+------+ [root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P4407 -e 'select * from test.t_global' greatsql: [Warning] Using a password on the command line interface can be insecure. +-------------+----+------+ | _hidden_pk_ | c1 | c2 | +-------------+----+------+ | 1 | 1 | 1 | | 8 | 2 | 2 | | 15 | 3 | 3 | +-------------+----+------+ [root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P4408 -e 'select * from test.t_global' greatsql: [Warning] Using a password on the command line interface can be insecure. +-------------+----+------+ | _hidden_pk_ | c1 | c2 | +-------------+----+------+ | 1 | 1 | 1 | | 8 | 2 | 2 | | 15 | 3 | 3 | +-------------+----+------+
由此可见,Global表在每个 Shard 上的数据完全一致。
-- hash分区: create table test.t_hash(c1 int primary key, c2 int) partition by hash(c1) partitions 8; -- range分区: create table test.t_range(c1 int primary key, c2 int) partition by range(c1) (partition p0 values less than (10), partition p1 values less than (100), partition p4 values less than maxvalue); -- list分区: create table test.t_list(c1 int primary key, c2 varchar(20)) partition by list(c1) (partition beijing values in (1,2,3), partition shanghai values in (4,5,6));
GreatDB Cluster[(none)]> select * from information_schema.greatdb_table_distribution where TABLE_NAME='t_hash'; +-------------+------------+----------------+-----------------+------------+----------------+--------------+ | SCHEMA_NAME | TABLE_NAME | BACKEND_ENGINE | DISTRIBUTE_MODE | SHARD_NAME | PARTITION_NAME | PARTITION_ID | +-------------+------------+----------------+-----------------+------------+----------------+--------------+ | test | t_hash | InnoDB | PARTITION | shard1 | p0 | 0 | | test | t_hash | InnoDB | PARTITION | shard1 | p4 | 4 | | test | t_hash | InnoDB | PARTITION | shard2 | p1 | 1 | | test | t_hash | InnoDB | PARTITION | shard2 | p3 | 3 | | test | t_hash | InnoDB | PARTITION | shard2 | p5 | 5 | | test | t_hash | InnoDB | PARTITION | shard2 | p7 | 7 | | test | t_hash | InnoDB | PARTITION | shard3 | p2 | 2 | | test | t_hash | InnoDB | PARTITION | shard3 | p6 | 6 | +-------------+------------+----------------+-----------------+------------+----------------+--------------+ 8 rows in set (0.01 sec)
由此可见,分区被分散在存储层的多个 Shard 中,插入数据,查看 Shard 中的数据存储情况
GreatDB Cluster[(none)]> insert into test.t_hash values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8); Query OK, 8 rows affected (0.02 sec) Records: 8 Duplicates: 0 Warnings: 0 GreatDB Cluster[(none)]> select * from test.t_hash partition (p0); +----+------+ | c1 | c2 | +----+------+ | 8 | 8 | +----+------+ 1 row in set (0.00 sec) GreatDB Cluster[(none)]> select * from test.t_hash partition (p4); +----+------+ | c1 | c2 | +----+------+ | 4 | 4 | +----+------+ 1 row in set (0.00 sec)
登录到 DataNode 查看表的存储情况
# 分区表的 p0 和 p4 分区在 shard1 上,登录到 shard1 所在的 DataNode 上 [root@greatdb1 ~]# greatsql -ugreatdb -pgreatdb -h192.168.0.81 -P4406 GreatDB Cluster[(none)]> use test 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 GreatDB Cluster[test]> show tables like 't_hash%'; +--------------------------+ | Tables_in_test (t_hash%) | +--------------------------+ | t_hash#p#0 | | t_hash#p#4 | +--------------------------+ 2 rows in set (0.00 sec) GreatDB Cluster[test]> select * from `t_hash#p#0`; +-------------+----+------+ | _hidden_pk_ | c1 | c2 | +-------------+----+------+ | 1 | 8 | 8 | +-------------+----+------+ 1 row in set (0.00 sec) GreatDB Cluster[test]> select * from `t_hash#p#4`; +-------------+----+------+ | _hidden_pk_ | c1 | c2 | +-------------+----+------+ | 1 | 4 | 4 | +-------------+----+------+ 1 row in set (0.00 sec)
mysql.greatdb_migrate_table(‘db_name’, ‘table_name’, part_id, ‘shard_name’ );GreatDB Cluster[(none)]> select * from information_schema.greatdb_table_distribution where TABLE_NAME='t_normal'; +-------------+------------+----------------+-----------------+------------+----------------+--------------+ | SCHEMA_NAME | TABLE_NAME | BACKEND_ENGINE | DISTRIBUTE_MODE | SHARD_NAME | PARTITION_NAME | PARTITION_ID | +-------------+------------+----------------+-----------------+------------+----------------+--------------+ | test | t_normal | InnoDB | NORMAL | shard2 | | 0 | +-------------+------------+----------------+-----------------+------------+----------------+--------------+ 1 row in set (0.00 sec)
CALL `mysql`.`greatdb_migrate_table`('SCHEMA_NAME', 'TABLE_NAME', PARTITION_ID, 'SHARD_NAME' ); -- 例如: CALL `mysql`.`greatdb_migrate_table`('test', 't_normal', , 'shard1' );
GreatDB Cluster[(none)]> SELECT * FROM information_schema.greatdb_task WHERE task_type='MIGRATE_TABLE'; +---------+---------------+-------------------------------------+----------+---------------------+---------------------+ | TASK_ID | TASK_TYPE | INFO | STATUS | OWNER_INSTANCE_HOST | OWNER_INSTANCE_PORT | +---------+---------------+-------------------------------------+----------+---------------------+---------------------+ | 43 | MIGRATE_TABLE | test.t_normal from shard2 to shard1 | COMPLETE | 192.168.0.81 | 3306 | +---------+---------------+-------------------------------------+----------+---------------------+---------------------+ 1 row in set (0.00 sec)
GreatDB Cluster[(none)]> select * from information_schema.greatdb_table_distribution where TABLE_NAME='t_normal'; +-------------+------------+----------------+-----------------+------------+----------------+--------------+ | SCHEMA_NAME | TABLE_NAME | BACKEND_ENGINE | DISTRIBUTE_MODE | SHARD_NAME | PARTITION_NAME | PARTITION_ID | +-------------+------------+----------------+-----------------+------------+----------------+--------------+ | test | t_normal | InnoDB | NORMAL | shard1 | | | +-------------+------------+----------------+-----------------+------------+----------------+--------------+ 1 row in set (0.01 sec)
GreatDB Cluster[(none)]> SELECT * FROM information_schema.greatdb_migrate_table_task; +---------+---------------+-------------------------------------+----------------+----------------+------------------+-----------------------+---------------------+-------------+ | TASK_ID | OBJECT_NAME | INFO | MIGRATE_STATUS | STAGE_SEQUENCE | STAGE | COMPLETED_SUBTASK_NUM | UNKNOWN_SUBTASK_NUM | SUBTASK_NUM | +---------+---------------+-------------------------------------+----------------+----------------+------------------+-----------------------+---------------------+-------------+ | 43 | test.t_normal | test.t_normal from shard2 to shard1 | COMPLETE | 1 | CREATE TABLE | 1 | | 1 | | 43 | test.t_normal | test.t_normal from shard2 to shard1 | COMPLETE | 2 | COPY REMOTE DATA | 1 | | 1 | | 43 | test.t_normal | test.t_normal from shard2 to shard1 | COMPLETE | 3 | APPLY_REMOTE_LOG | 1 | | 1 | | 43 | test.t_normal | test.t_normal from shard2 to shard1 | COMPLETE | 4 | CATCH_REMOTE_LOG | 1 | | 1 | | 43 | test.t_normal | test.t_normal from shard2 to shard1 | COMPLETE | 5 | CHANGE_TOPOLOGY | 1 | | 1 | +---------+---------------+-------------------------------------+----------------+----------------+------------------+-----------------------+---------------------+-------------+ 5 rows in set (0.03 sec)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69946831/viewspace-3163844/ ,如需转载,请注明出处,否则将追究法律责任。