TDSQL數據庫考試實操題


第一題: 演練二 物理備份(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

--------------------

  1. 分布式數據庫特性測試:分布式數據庫,驗證事務提交與回滾(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';

  1. 分布式數據庫特性測試:二級分區(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)
  1. 分布式數據庫特性測試:異常場景處理:死鎖處理機制(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)
  1. 分布式數據庫特性測試:異常場景處理:非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
  1. 分布式數據庫特性測試:三種建表方案:支持廣播表(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)

  1. 分布式數據庫特性測試:三種建表方案:支持分表(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

  1. 分布式數據庫特性測試:三種建表方案:支持單表(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)
  1. 分布式數據庫特性測試:字符集支持(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
  1. 分布式數據庫特性測試:透明水平拆分(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方法:

  1. 創建數據庫實例:多租戶方案(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

  1. 創建數據庫實例:創建非分布式實例(5分)

創建非分布式實例結果:

  1. 創建數據庫實例:查詢實例(5分)

集群總覽總搜索的結果:

  1. 創建數據庫實例:創建分布式實例(5分)

創建分布式實例結果:

  1. 安裝部署:寫上自己姓名和機器IP(15分) (15分)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM