第一题: 演练二 物理备份(5分)
答:
第二题:2. 演练一 请根据给定的演练方案,进行相关演练,并按如下要求提交截图 主备切换(5分)
答:
第三题:3. 演练一 请根据给定的演练方案,进行相关演练,并按如下要求提交截图 通过赤兔管理台修改参数(5分)
答题:
修改前:
修改后:
查询:
第四题:分布式数据库特性测试:全局唯一序列(5分)
1. web页面进入分布式数据库,创建用户test
group_1614079196_12
【分布式】正常(0)
2. 进入数据库管理页面创建一个用户test222,密码123456
3. 使用新账号连接数据库执行相关操作
mysql -utest22 -h192.168.1.160 -P15002 -p'123456'
4. 登录分布式数据库并执行下面命令
MySQL [(none)]> use test;
Database changed
MySQL [test]> create table mb_sequence (id int key auto_increment , seq int, cache char(20)) shardkey=id;
Query OK, 0 rows affected (0.18 sec)
MySQL [test]> show create table mb_sequence;
+-------------+------------------------------------------------------------------------------------+
| Table | Create Table |
+-------------+------------------------------------------------------------------------------------+
| mb_sequence | CREATE TABLE `mb_sequence` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`seq` int(11) DEFAULT NULL,
`cache` char(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 shardkey=id |
+-------------+------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
#查看创建语句:
MySQL [test]> show create table mb_sequence;
#插入数据:
MySQL [test]> INSERT INTO mb_sequence(ID,SEQ,CACHE) values('1111',2222,0);
Query OK, 1 row affected (0.01 sec)
MySQL [test]> INSERT INTO mb_sequence(ID,SEQ,CACHE) values('1112',2223,0);
Query OK, 1 row affected (0.01 sec)
#查看数据
MySQL [test]> explain insert into mb_sequence(id) values(null);
检查数据库端口
干掉这一台的tdsql看集群是否正常[检查端口过滤然后kill]:
[root@localhost bin]# ps -ef|grep 4002|awk '{print $2}' |xargs kill -9
--------------------
- 分布式数据库特性测试:分布式数据库,验证事务提交与回滚(5分)
mysql -utest22 -h192.168.1.160 -P15002 -p'123456' -c
show variables like "%log%";
show variables like "%general_log%";
set global general_log_file = '/etc/my.cnf';
- 分布式数据库特性测试:二级分区(5分)
web页面实例管理创建用户test22,然后用以下方式链接数据库:
#连接端口在 实例详情-网关列表中查看
mysql -utest22 -h192.168.1.160 -P15002 -p'123456'
create database test1;
use test1;
create table shard_table(a int key,b int, c char(20)) shardkey=a;
INSERT INTO shard_table(a, b, c)
VALUES
(1, 1, "aaa"),
(2, 1, "ccc"),
(3, 1, "ddd"),
(4, 1, "eee"),
(5, 1, "fff"),
(6, 1, "ggg");
#查询执行结果:
MySQL [test1]> select * from shard_table;
+---+------+------+
| a | b | c |
+---+------+------+
| 6 | 1 | ggg |
| 4 | 1 | eee |
| 1 | 1 | aaa |
| 2 | 1 | ccc |
| 5 | 1 | fff |
| 3 | 1 | ddd |
+---+------+------+
6 rows in set (0.00 sec)
- 分布式数据库特性测试:异常场景处理:死锁处理机制(5分)
1. 开启事务:
start transaction;
2. 执行语句:
use test1;
create table customer ( id int key ,name char(20)) shardkey=id;
begin;
select * from customer where id=6 for update;
update customer set name='dzyong' where id =5;
select * from customer where id=6 lock in share mode;
MySQL [test1]> select * from customer where id=6 lock in share mode;
+----+------+
| id | name |
+----+------+
| 6 | ggg |
+----+------+
1 row in set (0.00 sec)
- 分布式数据库特性测试:异常场景处理:非shardkey更新(5分)
mysql -utest22 -h192.168.1.160 -P15002 -p'123456'
create table shard_table1(a int key,b int,c char(20)) shardkey=a;
1. 发起无where提交的update;
MySQL [test1]> update shard_table1 set b=b+1;
ERROR 664 (HY000): Proxy ERROR:SQL is too complex, only applicable to noshard table: Shard table delete/update must have a where clause
2. 发起不指定shardkey的insert:
MySQL [test1]> insert into shard_table(b,c) values(1,1);
ERROR 693 (HY000): Proxy ERROR:Get shardkeys return error
- 分布式数据库特性测试:三种建表方案:支持广播表(5分)
MySQL [(none)]> 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 [test1]> create table global_table(a int, b int key) shardkey=noshardkey_allset;
Query OK, 0 rows affected (0.01 sec)
MySQL [test1]> show create table shard_table;
+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| shard_table | CREATE TABLE `shard_table` (
`a` int(11) NOT NULL,
`b` int(11) DEFAULT NULL,
`c` char(20) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin shardkey=a |
+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
#写入10条数据
INSERT INTO shard_table(a, b, c) VALUES
(110, 1, "aaa"),
(111, 1, "ccc"),
(112, 1, "ddd"),
(113, 1, "eee"),
(114, 1, "fff"),
(115, 1, "ggg"),
(116, 1, "ggg"),
(117, 1, "ggg"),
(118, 1, "ggg"),
(119, 1, "ggg"),
(120, 1, "ggg");
#查询数据
MySQL [test1]> /*sets:set_1614079282_1*/ select count(*) from shard_table;
+----------+
| count(1) |
+----------+
| 23 |
+----------+
1 row in set (0.00 sec)
- 分布式数据库特性测试:三种建表方案:支持分表(5分)
for i in {1..10};do mysql -utest22 -h192.168.1.160 -P15002 -p'123456' -e " use test1; INSERT INTO global_table2(a, b) VALUES (1,$i)";done;
CREATE TABLE global_table2 ( a int, b int key ) shardkey=noshardkey_allset;
/*proxy*/show status;
/*sets:set_1611893952_1*/ select count(*) from global_table2;
#多个查询
/*sets:set_1611893952_1,set_1611894125_3*/ select count(*) from global_table;
新建多个set
- 分布式数据库特性测试:三种建表方案:支持单表(5分)
use test1;
create table no_shard_table(a int,b int key);
show create table no_shard_table;
结果:
MySQL [test1]> create table no_shard_table(a int,b int key);
Query OK, 0 rows affected (0.01 sec)
MySQL [test1]> show create table no_shard_table;
+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
| no_shard_table | CREATE TABLE `no_shard_table` (
`a` int(11) DEFAULT NULL,
`b` int(11) NOT NULL,
PRIMARY KEY (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin |
+----------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
- 分布式数据库特性测试:字符集支持(5分)
for i in {1..10};do mysql -utest12 -h172.27.0.110 -P15002 -ptest123 -e " use test; INSERT INTO global_table(a, b) VALUES (1,$i)";done;
use test1;
/*proxy*/show status;
/*sets:set_1611893952_1*/ select count(*) from global_table;
/*sets:allsets*/ select count(*) from global_table;
/*sets:set_1611893952_1,set_1611894125_3*/ select count(*) from global_table;
#测试中文字符集支持:
MySQL [test1]> create table test123(a int key,b int,c char(20)) shardkey=a;
Query OK, 0 rows affected (0.15 sec)
MySQL [test1]> INSERT INTO test12(a, b, c) VALUES (92, 1, b'111001001011100010101101111001011001101110111101');
Query OK, 1 row affected (0.00 sec)
MySQL [test1]> select * from test12;
+----+------+--------+
| a | b | c |
+----+------+--------+
| 92 | 1 | 中国 |
+----+------+--------+
1 row in set (0.00 sec)
#中文转换二进制网站: https://www.qqxiuzi.cn/bianma/erjinzhi.php
- 分布式数据库特性测试:透明水平拆分(5分)
#1.数据库管理栏目创建用户test22:
#2.图形tdsql界面创建两个sets: 下面有创建截图:
set管理--->创建set
图形界面出现两个set:
set_1614241216_4
set_1614079282_1
#3. 连接proxy数据库,创建数据库:
mysql -utest22 -h192.168.1.160 -P15002 -p'123456'
create databasee test33;
#4. 进入test33库
mysql -utest22 -h192.168.1.160 -P15002 -p'123456' -D test33;
#创建表:
create table test123(a int key,b int,c char(20)) shardkey=a;
exit
for i in {1..50};do mysql -utest22 -h192.168.1.160 -P15002 -p'123456' -e " use test33; INSERT INTO test123(a,b,c) VALUES ($i,666,'ccl')";done;
#创建一个set(下图)
mysql -utest22 -h192.168.1.160 -P15002 -p'123456' -c
create database test33;
use test33;
create table test(a int key,b int,c char(20)) shardkey=a;
exit
for i in {1..50};do mysql -utest22 -h192.168.1.160 -P15002 -p123456 test33 -e "INSERT INTO test(a, b, c) VALUES ($i,1,2)";done;
for i in {1..50};do mysql -utest22 -h192.168.1.160 -P15002 -p'123456' -e " use test33; INSERT INTO test123(a,b,c) VALUES ($i,666,'ccl')";done;
#查询
mysql -utest22 -h192.168.1.160 -P15002 -p'123456' test33;
select * from test123;
MySQL [test33]> select count(*) from test123;
+----------+
| count(1) |
+----------+
| 50 |
+----------+
1 row in set (0.00 sec)
#查询分片count之和为50. set_1614079282_1 set_1614241216_4
#多个查询
MySQL [test33]> /*sets:allsets*/ select count(*) from test123;
+----------+------------------+
| count(*) | info |
+----------+------------------+
| 29 | set_1614241216_4 |
| 21 | set_1614079282_1 |
+----------+------------------+
2 rows in set (0.01 sec)
#单个查询
MySQL [test33]> /*sets:set_1614079282_1*/ select count(*) from test123;
+----------+------------------+
| count(*) | info |
+----------+------------------+
| 21 | set_1614079282_1 |
+----------+------------------+
1 row in set (0.00 sec)
MySQL [test33]> /*sets:set_1614241216_4*/ select count(*) from test123;
+----------+------------------+
| count(*) | info |
+----------+------------------+
| 29 | set_1614241216_4 |
+----------+------------------+
1 row in set (0.01 sec)
#查询分表分片信息:
MySQL [test33]> /*proxy*/show status;
+-----------------------------+-------------------------------------------------------------------+
| status_name | value |
+-----------------------------+-------------------------------------------------------------------+
| cluster | group_1614079196_12 |
| set_1614079282_1:ip | 192.168.1.202:4002;192.168.1.160:4002@1@IDC_SH_TYYX_0101_000001@0 |
| set_1614079282_1:hash_range | 0---31 |
| set_1614241216_4:ip | 192.168.1.160:4003;192.168.1.202:4003@1@IDC_SH_TYYX_0101_000002@0 |
| set_1614241216_4:hash_range | 32---63 |
| set | set_1614079282_1,set_1614241216_4 |
+-----------------------------+-------------------------------------------------------------------+
6 rows in set (0.00 sec)
创建一个set方法:
- 创建数据库实例:多租户方案(5分
MySQL [(none)]> show variables like "%log%";
+-------------------------------------------+----------------------+
| Variable_name | Value |
+-------------------------------------------+----------------------+
| back_log | 900 |
| binlog_cache_size | 32768 |
| binlog_checksum | NONE |
| binlog_direct_non_transactional_updates | OFF |
| binlog_error_action | ABORT_SERVER |
| binlog_format | ROW |
| binlog_format_free_change | ON |
| binlog_group_commit_sync_delay | 0 |
| binlog_group_commit_sync_no_delay_count | 0 |
| binlog_gtid_simple_recovery | ON |
| binlog_max_flush_queue_time | 0 |
| binlog_order_commits | ON |
| binlog_row_image | FULL |
| binlog_rows_query_log_events | OFF |
| binlog_stmt_cache_size | 32768 |
| binlog_write_threshold | 1610612736 |
| expire_logs_days | 0 |
| forbid_remote_change_sql_log_bin | ON |
| general_log | OFF |
| have_backup_safe_binlog_info | YES |
| innodb_api_enable_binlog | OFF |
| innodb_flush_log_at_timeout | 1 |
| innodb_flush_log_at_trx_commit | 1 |
| innodb_locks_unsafe_for_binlog | OFF |
| innodb_log_buffer_size | 268435456 |
| innodb_log_checksums | ON |
| innodb_log_compressed_pages | OFF |
| innodb_log_file_size | 1073741824 |
| innodb_log_files_in_group | 4 |
| innodb_log_write_ahead_size | 8192 |
| innodb_max_undo_log_size | 1073741824 |
| innodb_online_alter_log_max_size | 134217728 |
| innodb_undo_log_truncate | OFF |
| innodb_undo_logs | 128 |
| innodb_use_global_flush_log_at_trx_commit | ON |
| log_bin | ON |
| log_bin_trust_function_creators | ON |
| log_bin_use_v1_row_events | OFF |
| log_builtin_as_identified_by_password | OFF |
| log_error_verbosity | 3 |
| log_output | FILE |
| log_queries_not_using_indexes | OFF |
| log_slave_updates | ON |
| log_slow_admin_statements | OFF |
| log_slow_filter | |
| log_slow_rate_limit | 1 |
| log_slow_rate_type | session |
| log_slow_slave_statements | OFF |
| log_slow_sp_statements | ON |
| log_slow_verbosity | |
| log_statements_unsafe_for_binlog | OFF |
| log_syslog | OFF |
| log_syslog_facility | daemon |
| log_syslog_include_pid | ON |
| log_syslog_tag | |
| log_throttle_queries_not_using_indexes | 0 |
| log_timestamps | SYSTEM |
| log_warnings | 2 |
| loglevel | 1 |
| max_binlog_cache_size | 18446744073709547520 |
| max_binlog_files | 0 |
| max_binlog_size | 104857600 |
| max_binlog_stmt_cache_size | 18446744073709547520 |
| max_relay_log_size | 104857600 |
| max_slowlog_files | 0 |
| max_slowlog_size | 0 |
| relay_log_info_file | relay-log.info |
| relay_log_info_repository | TABLE |
| relay_log_purge | ON |
| relay_log_recovery | OFF |
| relay_log_space_limit | 0 |
| relay_log_sync_threshold | 20000 |
| relay_log_sync_timeout | 1000 |
| relay_log_sync_txn_count | 10 |
| slow_query_log | ON |
| slow_query_log_always_write_time | 10.000000 |
| slow_query_log_use_global_control | |
| sql_log_bin | ON |
| sql_log_off | OFF |
| sync_binlog | 1 |
| sync_relay_log | 0 |
| sync_relay_log_info | 0 |
| tdsql_compute_query_time_for_slow_logging | 2 |
| tdsql_relay_log_opt | OFF |
+-------------------------------------------+----------------------+
84 rows in set (0.01 sec)
2. 设置路径失败:
MySQL [(none)]> set global general_log_file = '/etc/my.cnf';
ERROR 655 (HY000): Proxy ERROR:Proxy does not support such usage yet: Do not support global set
- 创建数据库实例:创建非分布式实例(5分)
创建非分布式实例结果:
- 创建数据库实例:查询实例(5分)
集群总览总搜索的结果:
- 创建数据库实例:创建分布式实例(5分)
创建分布式实例结果:
- 安装部署:写上自己姓名和机器IP(15分) (15分)