作业:实践练习一(必选):OceanBase Docker 体验

练习内容

请记录并分享下列内容:

  1. (必选)下载Docker 镜像:OceanBase 官方社区版镜像 126
  2. (必选)使用 OBD 命令完成后续的 OceanBase 集群部署。
  3. (必选)创建一个业务租户、一个业务数据库,以及一些表等。

安装docker

去官网下载相应的版本安装即可

设置docker资源

![image-20230317104023698](/Users/Kevin/Library/Application Support/typora-user-images/image-20230317104023698.png)

下载oceanbase-ce镜像

➜  ~ docker pull oceanbase/oceanbase-ce
Using default tag: latest
latest: Pulling from oceanbase/oceanbase-ce
2d473b07cdd5: Pull complete
e5ef8a4cc6a5: Pull complete
55a9f79139d5: Pull complete
01293d4f8764: Pull complete
Digest: sha256:a11744e176b6354334ccae70b118c2500d41dce0f062d09ee9cbabc9929bbc64
Status: Downloaded newer image for oceanbase/oceanbase-ce:latest
docker.io/oceanbase/oceanbase-ce:latest

➜  ~ docker image ls
REPOSITORY               TAG       IMAGE ID       CREATED       SIZE
oceanbase/oceanbase-ce   latest    cfffed8802fd   6 weeks ago   456MB
➜  ~

运行

➜  ~ docker run -p 2881:2881 --name flobce  -d oceanbase/oceanbase-ce
0fe0f46b28eaaa785698bce11fe861fa8a72e6e48df45905a8a8b7a697dd98d2
➜  ~ docker logs flobce | tail -1
boot success!
➜  ~ docker ps
CONTAINER ID   IMAGE                    COMMAND              CREATED          STATUS          PORTS                    NAMES
0fe0f46b28ea   oceanbase/oceanbase-ce   "/bin/sh -c _boot"   51 seconds ago   Up 49 seconds   0.0.0.0:2881->2881/tcp   flobce

obd查看集群

➜  ~
➜  ~ docker exec -it flobce bash
[root@0fe0f46b28ea ~]#
[root@0fe0f46b28ea ~]# obd cluster list
+------------------------------------------------------------+
|                        Cluster List                        |
+-----------+------------------------------+-----------------+
| Name      | Configuration Path           | Status (Cached) |
+-----------+------------------------------+-----------------+
oceanbase-ce:
  servers:
    # Please don't use hostname, only IP can be supported
  - 127.0.0.1
  global:
    home_path: /root/ob
    devname: lo
    zone: zone1
    cluster_id: 1
    # please set memory limit to a suitable value which is matching resource.
| obcluster | /root/.obd/cluster/obcluster | running         |
+-----------+------------------------------+-----------------+
[root@0fe0f46b28ea ~]#
[root@0fe0f46b28ea ~]# obd cluster display obcluster
Get local repositories and plugins ok
Open ssh connection ok
Cluster status check ok
Connect to observer ok
Wait for observer init ok
+---------------------------------------------+
|                   observer                  |
+-----------+---------+------+-------+--------+
| ip        | version | port | zone  | status |
+-----------+---------+------+-------+--------+
| 127.0.0.1 | 4.0.0.0 | 2881 | zone1 | ACTIVE |
+-----------+---------+------+-------+--------+
obclient -h127.0.0.1 -P2881 -uroot -Doceanbase -A

+------------------------------------------------+
|                    obagent                     |
+------------+-------------+------------+--------+
| ip         | server_port | pprof_port | status |
+------------+-------------+------------+--------+
| 172.17.0.2 | 8088        | 8089       | active |
+------------+-------------+------------+--------+
[root@0fe0f46b28ea ~]#
[root@0fe0f46b28ea ~]#
[root@0fe0f46b28ea ~]# exit
exit
➜  ~

官方命令连接数据库

# 连接 sys 租户的 root 用户
➜  ~ docker exec -it flobce ob-mysql sys
login as root@sys
Command is: obclient -h127.1 -uroot@sys -A -Doceanbase -P2881
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221487622
Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:57:18)

Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

obclient [oceanbase]>
obclient [oceanbase]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| LBACSYS            |
| mysql              |
| oceanbase          |
| ORAAUDITOR         |
| SYS                |
| test               |
+--------------------+
7 rows in set (0.020 sec)

obclient [oceanbase]> 
obclient [oceanbase]> select host,user,authentication_string from mysql.user;
+------+------------+-----------------------+
| host | user       | authentication_string |
+------+------------+-----------------------+
| %    | root       |                       |
| %    | ORAAUDITOR |                       |
+------+------------+-----------------------+
2 rows in set (0.008 sec)

obclient [oceanbase]> exit
Bye
➜  ~
 # 连接 test 租户的 root 用户
➜  ~ docker exec -it flobce ob-mysql root
login as root@test
Command is: obclient -h127.1 -uroot@test -A -Doceanbase -P2881
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221487623
Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:57:18)

Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

obclient [oceanbase]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| oceanbase          |
| test               |
+--------------------+
4 rows in set (0.005 sec)

obclient [oceanbase]> select host,user,authentication_string from mysql.user;
+------+------------+-----------------------+
| host | user       | authentication_string |
+------+------------+-----------------------+
| %    | root       |                       |
| %    | ORAAUDITOR |                       |
| %    | test       |                       |
+------+------------+-----------------------+
3 rows in set (0.008 sec)

obclient [oceanbase]> exit
Bye
# 连接 test 租户的 test 用户
➜  ~ docker exec -it flobce ob-mysql test
login as test@test
Command is: obclient -h127.1 -utest@test -A -Dtest -P2881
Welcome to the OceanBase.  Commands end with ; or \g.
Your OceanBase connection id is 3221487624
Server version: OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:57:18)

Copyright (c) 2000, 2018, OceanBase and/or its affiliates. All rights reserved.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

obclient [test]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| test               |
+--------------------+
2 rows in set (0.007 sec)

obclient [test]> select host,user,authentication_string from mysql.user;
ERROR 1142 (42000): SELECT command denied to user 'test'@'%' for table 'user'
obclient [test]>
obclient [test]> exit
Bye
#本地客户端mycli连接数据库 漏了租户名,但是居然也连接成功了,还是连到了sys租户的root用户
➜  ~ mycli -uroot -h127.0.0.1 -P2881
MySQL
mycli 1.26.1
Home: http://mycli.net
Bug tracker: https://github.com/dbcli/mycli/issues
Thanks to the contributor - Lennart Weller
MySQL root@127.0.0.1:(none)> select version()
+------------------------------+
| version()                    |
+------------------------------+
| 5.7.25-OceanBase_CE-v4.0.0.0 |
+------------------------------+
1 row in set
Time: 0.014s
MySQL root@127.0.0.1:(none)> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| LBACSYS            |
| mysql              |
| oceanbase          |
| ORAAUDITOR         |
| SYS                |
| test               |
+--------------------+
7 rows in set
Time: 0.020s
MySQL root@127.0.0.1:(none)> exit
Goodbye!
➜  ~
➜  ~

创建租户

➜  ~
➜  ~ mysql -uroot@sys -h127.0.0.1 -P2881
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3221225473
Server version: 5.7.25 OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:57:18)

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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql> use oceanbase;
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> 
mysql> select * from DBA_OB_UNITS;
+---------+-----------+--------+------------------+---------------+----------------------------+----------------------------+-------+-----------+----------+---------------------+-----------------------+----------------+----------------+---------+---------+-------------+---------------+----------+----------+-------------+
| UNIT_ID | TENANT_ID | STATUS | RESOURCE_POOL_ID | UNIT_GROUP_ID | CREATE_TIME                | MODIFY_TIME                | ZONE  | SVR_IP    | SVR_PORT | MIGRATE_FROM_SVR_IP | MIGRATE_FROM_SVR_PORT | MANUAL_MIGRATE | UNIT_CONFIG_ID | MAX_CPU | MIN_CPU | MEMORY_SIZE | LOG_DISK_SIZE | MAX_IOPS | MIN_IOPS | IOPS_WEIGHT |
+---------+-----------+--------+------------------+---------------+----------------------------+----------------------------+-------+-----------+----------+---------------------+-----------------------+----------------+----------------+---------+---------+-------------+---------------+----------+----------+-------------+
|       1 |         1 | ACTIVE |                1 |             1 | 2023-03-17 10:54:50.900272 | 2023-03-17 10:54:50.900272 | zone1 | 127.0.0.1 |     2882 | NULL                |                  NULL | NULL           |              1 |       1 |       1 |  2147483648 |    2147483648 |    10000 |    10000 |           1 |
|    1001 |      1002 | ACTIVE |             1001 |          1001 | 2023-03-17 10:55:08.280739 | 2023-03-17 10:55:08.347665 | zone1 | 127.0.0.1 |     2882 | NULL                |                  NULL | NULL           |           1001 |      15 |      15 |  3221225472 |    3221225472 |   150000 |   150000 |          15 |
+---------+-----------+--------+------------------+---------------+----------------------------+----------------------------+-------+-----------+----------+---------------------+-----------------------+----------------+----------------+---------+---------+-------------+---------------+----------+----------+-------------+
2 rows in set (0.01 sec)

mysql> select * from DBA_OB_UNITS_config;
ERROR 1146 (42S02): Table 'oceanbase.DBA_OB_UNITS_config' doesn't exist
mysql> select * from DBA_OB_UNIT_CONFIGS;
+----------------+-----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+
| UNIT_CONFIG_ID | NAME            | CREATE_TIME                | MODIFY_TIME                | MAX_CPU | MIN_CPU | MEMORY_SIZE | LOG_DISK_SIZE | MAX_IOPS | MIN_IOPS | IOPS_WEIGHT |
+----------------+-----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+
|              1 | sys_unit_config | 2023-03-17 10:54:50.889096 | 2023-03-17 10:54:50.889096 |       1 |       1 |  2147483648 |    2147483648 |    10000 |    10000 |           1 |
|           1001 | test_unit       | 2023-03-17 10:55:08.255369 | 2023-03-17 10:55:08.255369 |      15 |      15 |  3221225472 |    3221225472 |   150000 |   150000 |          15 |
|           1002 | flunit          | 2023-03-17 11:47:04.807172 | 2023-03-17 11:47:04.807172 |       1 |       1 |  1073741824 |    2147483648 |     1024 |     1024 |           1 |
+----------------+-----------------+----------------------------+----------------------------+---------+---------+-------------+---------------+----------+----------+-------------+
3 rows in set (0.01 sec)

mysql> alter resource unit test_unit MAX_CPU 2,MIN_CPU 2;
Query OK, 0 rows affected (0.03 sec)

mysql>
mysql> CREATE RESOURCE POOL flpool     UNIT='flunit',     UNIT_NUM =1;
ERROR 1235 (0A000): unit MEMORY_SIZE less than __min_full_resource_pool_memory not supported
mysql>
mysql>
mysql> CREATE RESOURCE POOL flpool     UNIT='flunit',     UNIT_NUM =1;
ERROR 4733 (HY000): zone 'zone1' resource not enough to hold 1 unit. You can check resource info by views: DBA_OB_UNITS, GV$OB_UNITS, GV$OB_SERVERS.
server '"127.0.0.1:2882"' MEMORY resource not enough

mysql>
mysql> select * from DBA_OB_UNITS;
+---------+-----------+--------+------------------+---------------+----------------------------+----------------------------+-------+-----------+----------+---------------------+-----------------------+----------------+----------------+---------+---------+-------------+---------------+----------+----------+-------------+
| UNIT_ID | TENANT_ID | STATUS | RESOURCE_POOL_ID | UNIT_GROUP_ID | CREATE_TIME                | MODIFY_TIME                | ZONE  | SVR_IP    | SVR_PORT | MIGRATE_FROM_SVR_IP | MIGRATE_FROM_SVR_PORT | MANUAL_MIGRATE | UNIT_CONFIG_ID | MAX_CPU | MIN_CPU | MEMORY_SIZE | LOG_DISK_SIZE | MAX_IOPS | MIN_IOPS | IOPS_WEIGHT |
+---------+-----------+--------+------------------+---------------+----------------------------+----------------------------+-------+-----------+----------+---------------------+-----------------------+----------------+----------------+---------+---------+-------------+---------------+----------+----------+-------------+
|       1 |         1 | ACTIVE |                1 |             1 | 2023-03-17 10:54:50.900272 | 2023-03-17 10:54:50.900272 | zone1 | 127.0.0.1 |     2882 | NULL                |                  NULL | NULL           |              1 |       1 |       1 |  2147483648 |    2147483648 |    10000 |    10000 |           1 |
|    1001 |      1002 | ACTIVE |             1001 |          1001 | 2023-03-17 10:55:08.280739 | 2023-03-17 10:55:08.347665 | zone1 | 127.0.0.1 |     2882 | NULL                |                  NULL | NULL           |           1001 |       2 |       2 |  3221225472 |    3221225472 |   150000 |   150000 |          15 |
+---------+-----------+--------+------------------+---------------+----------------------------+----------------------------+-------+-----------+----------+---------------------+-----------------------+----------------+----------------+---------+---------+-------------+---------------+----------+----------+-------------+
2 rows in set (0.01 sec)

mysql> DROP TENANT test purge;

Query OK, 0 rows affected (1 min 3.12 sec)

mysql>
mysql> select * from DBA_OB_UNITS;
+---------+-----------+--------+------------------+---------------+----------------------------+----------------------------+-------+-----------+----------+---------------------+-----------------------+----------------+----------------+---------+---------+-------------+---------------+----------+----------+-------------+
| UNIT_ID | TENANT_ID | STATUS | RESOURCE_POOL_ID | UNIT_GROUP_ID | CREATE_TIME                | MODIFY_TIME                | ZONE  | SVR_IP    | SVR_PORT | MIGRATE_FROM_SVR_IP | MIGRATE_FROM_SVR_PORT | MANUAL_MIGRATE | UNIT_CONFIG_ID | MAX_CPU | MIN_CPU | MEMORY_SIZE | LOG_DISK_SIZE | MAX_IOPS | MIN_IOPS | IOPS_WEIGHT |
+---------+-----------+--------+------------------+---------------+----------------------------+----------------------------+-------+-----------+----------+---------------------+-----------------------+----------------+----------------+---------+---------+-------------+---------------+----------+----------+-------------+
|       1 |         1 | ACTIVE |                1 |             1 | 2023-03-17 10:54:50.900272 | 2023-03-17 10:54:50.900272 | zone1 | 127.0.0.1 |     2882 | NULL                |                  NULL | NULL           |              1 |       1 |       1 |  2147483648 |    2147483648 |    10000 |    10000 |           1 |
|    1001 |      NULL | ACTIVE |             1001 |             0 | 2023-03-17 10:55:08.280739 | 2023-03-17 15:20:35.659512 | zone1 | 127.0.0.1 |     2882 | NULL                |                  NULL | NULL           |           1001 |       2 |       2 |  3221225472 |    3221225472 |   150000 |   150000 |          15 |
+---------+-----------+--------+------------------+---------------+----------------------------+----------------------------+-------+-----------+----------+---------------------+-----------------------+----------------+----------------+---------+---------+-------------+---------------+----------+----------+-------------+
2 rows in set (0.01 sec)

mysql> select * from __all_resource_pool;
+----------------------------+----------------------------+------------------+-----------+------------+----------------+-----------+-----------+--------------+--------------------+
| gmt_create                 | gmt_modified               | resource_pool_id | name      | unit_count | unit_config_id | zone_list | tenant_id | replica_type | is_tenant_sys_pool |
+----------------------------+----------------------------+------------------+-----------+------------+----------------+-----------+-----------+--------------+--------------------+
| 2023-03-17 10:54:50.894577 | 2023-03-17 10:54:50.905384 |                1 | sys_pool  |          1 |              1 | zone1     |         1 |            0 |                  0 |
| 2023-03-17 10:55:08.270949 | 2023-03-17 15:20:35.657611 |             1001 | test_pool |          1 |           1001 | zone1     |        -1 |            0 |                  0 |
+----------------------------+----------------------------+------------------+-----------+------------+----------------+-----------+-----------+--------------+--------------------+
2 rows in set (0.01 sec)

mysql>
mysql> drop resource pool test_pool;
Query OK, 0 rows affected (0.02 sec)

mysql>
mysql> select * from __all_resource_pool;
+----------------------------+----------------------------+------------------+----------+------------+----------------+-----------+-----------+--------------+--------------------+
| gmt_create                 | gmt_modified               | resource_pool_id | name     | unit_count | unit_config_id | zone_list | tenant_id | replica_type | is_tenant_sys_pool |
+----------------------------+----------------------------+------------------+----------+------------+----------------+-----------+-----------+--------------+--------------------+
| 2023-03-17 10:54:50.894577 | 2023-03-17 10:54:50.905384 |                1 | sys_pool |          1 |              1 | zone1     |         1 |            0 |                  0 |
+----------------------------+----------------------------+------------------+----------+------------+----------------+-----------+-----------+--------------+--------------------+
1 row in set (0.00 sec)

mysql>
mysql>
mysql> CREATE RESOURCE POOL flpool     UNIT='flunit',     UNIT_NUM =1;
Query OK, 0 rows affected (0.03 sec)

mysql>
mysql> exit
Bye
➜  ~
➜  ~ mysql -uroot@sys -h127.0.0.1 -P2881
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3221487621
Server version: 5.7.25 OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:57:18)

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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select tenant_id,tenant_name,primary_zone from __all_tenant;
ERROR 1046 (3D000): No database selected
mysql> use oceanbase
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>
mysql>
mysql> select tenant_id,tenant_name,primary_zone from __all_tenant;
+-----------+-------------+--------------+
| tenant_id | tenant_name | primary_zone |
+-----------+-------------+--------------+
|         1 | sys         | RANDOM       |
+-----------+-------------+--------------+
1 row in set (0.00 sec)

mysql>
mysql> CREATE TENANT fltenant charset='utf8mb4', replica_num=1, zone_list=('zone1'), primary_zone='zone1', resource_pool_list=('flpool') SET OB_TCP_INVITED_NODES='%',                ob_compatibility_mode='mysql';
Query OK, 0 rows affected (16.56 sec)

mysql>
mysql> select tenant_id,tenant_name,primary_zone from __all_tenant;
+-----------+-------------+--------------+
| tenant_id | tenant_name | primary_zone |
+-----------+-------------+--------------+
|         1 | sys         | RANDOM       |
|      1005 | META$1006   | zone1        |
|      1006 | fltenant    | zone1        |
+-----------+-------------+--------------+
3 rows in set (0.00 sec)

mysql>
mysql> exit
Bye
➜  ~
➜  ~ mysql -uroot@fltenant -h127.0.0.1 -P2881
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3221487622
Server version: 5.7.25 OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:57:18)

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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| oceanbase          |
| test               |
+--------------------+
4 rows in set (0.02 sec)

mysql>
mysql>

普通租户下创建数据库fldb,并创建该租户下的普通用户fl。用fl用户登录数据库fldb,创建并使用表

➜  ~ mysql -uroot@fltenant -h127.0.0.1 -P2881
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3221487622
Server version: 5.7.25 OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:57:18)

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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| oceanbase          |
| test               |
+--------------------+
4 rows in set (0.02 sec)

mysql>
mysql> select host,user,authentication_string from mysql.user;
+------+------------+-----------------------+
| host | user       | authentication_string |
+------+------------+-----------------------+
| %    | root       |                       |
| %    | ORAAUDITOR |                       |
+------+------------+-----------------------+
2 rows in set (0.01 sec)

mysql>
mysql> create database fldb;
Query OK, 1 row affected (0.09 sec)

mysql> show create database fldb;
+----------+------------------------------------------------------------------------+
| Database | Create Database                                                        |
+----------+------------------------------------------------------------------------+
| fldb     | CREATE DATABASE `fldb` DEFAULT CHARACTER SET = utf8mb4 REPLICA_NUM = 1 |
+----------+------------------------------------------------------------------------+
1 row in set (0.01 sec)

mysql>
mysql> create user fl@'%' identified by '111111';
Query OK, 0 rows affected (0.07 sec)

mysql> grant all on fldb.* to fl@'%';
Query OK, 0 rows affected (0.07 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| fldb               |
| information_schema |
| mysql              |
| oceanbase          |
| test               |
+--------------------+
5 rows in set (0.02 sec)

mysql> select host,user,authentication_string from mysql.user;
+------+------------+-----------------------+
| host | user       | authentication_string |
+------+------------+-----------------------+
| %    | root       |                       |
| %    | ORAAUDITOR |                       |
| %    | fl         |                       |
+------+------------+-----------------------+
3 rows in set (0.00 sec)

mysql> exit
Bye
➜  ~
➜  ~ mysql -ufl@fltenant -h127.0.0.1 -P2881
ERROR 1045 (42000): Access denied for user 'fl'@'xxx.xxx.xxx.xxx' (using password: NO)
➜  ~
➜  ~ mysql -ufl@fltenant -p111111 -h127.0.0.1 -P2881
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 3221487624
Server version: 5.7.25 OceanBase_CE 4.0.0.0 (r100000272022110114-6af7f9ae79cd0ecbafd4b1b88e2886ccdba0c3be) (Built Nov  1 2022 14:57:18)

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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| fldb               |
| information_schema |
+--------------------+
2 rows in set (0.02 sec)

mysql> use fldb;
Database changed
mysql> create table ss(a int(10),b varchar(20));
Query OK, 0 rows affected (0.29 sec)

mysql>
mysql> insert  into ss values(1,'aaaa');
Query OK, 1 row affected (0.05 sec)

mysql>
mysql> insert  into ss values(2,'bbb');
Query OK, 1 row affected (0.01 sec)

mysql>
mysql> insert  into ss values(3,'张三');
Query OK, 1 row affected (0.01 sec)

mysql>
mysql> select * from ss;
+------+--------+
| a    | b      |
+------+--------+
|    1 | aaaa   |
|    2 | bbb    |
|    3 | 张三   |
+------+--------+
3 rows in set (0.01 sec)

mysql> exit
Bye
➜  ~

关键命令

  1. 创建 unit

CREATE RESOURCE UNIT flunit MEMORY_SIZE = ‘1G’, MAX_CPU = 1, MIN_CPU = 1, LOG_DISK_SIZE = ‘2G’, MAX_IOPS = 1024, MIN_IOPS = 1024,IOPS_WEIGHT=1;

  1. 创建资源池

CREATE RESOURCE POOL flpool UNIT=‘flunit’, UNIT_NUM =1;

  1. 创建租户

CREATE TENANT fltenant charset=‘utf8mb4’, replica_num=1, zone_list=(‘zone1’), primary_zone=‘zone1’, resource_pool_list=(‘flpool’) SET OB_TCP_INVITED_NODES=’%’, ob_compatibility_mode=‘mysql’;

碰到的问题

  1. docker部署创建租户时,也有个小坑,要指定ob_tcp_invited_nodes,否则只能连到docker去登录。

    以下是官方文档说明:变量 ob_tcp_invited_nodes 用于指定租户连接的白名单,即允许哪些客户端 IP 连接该租户。如果不调整 ob_tcp_invited_nodes 的值,则默认租户的连接方式为只允许本机的 IP 连接数据库。

  2. docker镜像起来后会自动创建一个test_pool资源池,自动占用了除sys_pool cpu之外的所有cpu

    这里删除了test账户和test_pool,并把test_unit的cpu改成了2,才创建成功。

  3. 报错ERROR 1235 (0A000): unit MEMORY_SIZE less than __min_full_resource_pool_memory not supported

    系统默认最小值是5G,以下是官方文档说明

    ![image-20230320100332165](/Users/Kevin/Library/Application Support/typora-user-images/image-20230320100332165.png)

    执行以下语句更改隐藏参数值为1G即可:

    alter system __min_full_resource_pool_memory=1073741824;

1 个赞