默认情况 OceanBase 没有创建示例数据库 TPCC,需要手动创建。示例数据库必须在业务租户下创建。有关示例数据库介绍请参考关于示例数据库TPCC。
租户创建好后,需要创建相应的Schema来存放示例数据库的对象,还要分配相应的用户和访问权限。
示例
- 通过obclient连接Oracle租户。具体方法请参考通过obclient连接OceanBase租户。
$obclient -h192.168.1.101 -usys@t_oracle0_91#obdoc -P2883 -pabcABC123 sys
obclient: [Warning] Using a password on the command line interface can be insecure.
Welcome to the OceanBase monitor. Commands end with ; or \g.
Your OceanBase connection id is 58725
Server version: 5.6.25 OceanBase 2.2.20 (…) (Built Aug 10 2019 15:27:33)
<…省略…>
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
obclient>
- 创建一个Schema,即用户。
obclient> create user tpcc identified by 123456;
Query OK, 0 rows affected (0.02 sec)
obclient> grant all privileges on tpcc.* to tpcc;
Query OK, 0 rows affected (0.02 sec)
obclient> grant create,drop,select on *.* to tpcc;
Query OK, 0 rows affected (0.01 sec)
obclient> show grants for tpcc;
+--------------------------------------------+
| Grants for TPCC@% |
+--------------------------------------------+
| GRANT USAGE ON *.* TO 'TPCC' |
| GRANT SELECT ON "SYS".* TO 'TPCC' |
| GRANT ALL PRIVILEGES ON "TPCC".* TO 'TPCC' |
+--------------------------------------------+
3 rows in set (0.01 sec)
obclient>
- 通过用户tpcc登录到tpcc模式下。
$obclient -h192.168.1.101 -utpcc@t_oracle0_91#obdoc -P2883 -p123456 tpcc
- 创建数据库对象
obclient> source create_tables_oracle.sql
Query OK, 0 rows affected (0.21 sec)
<…省略…>
Query OK, 0 rows affected (0.07 sec)
+-----------+------------+-------------+-----------+
| SYSDATE | TABLE_NAME | PARTITIONED | TEMPORARY |
+-----------+------------+-------------+-----------+
| 01-APR-20 | CUST | YES | N |
| 01-APR-20 | DIST | YES | N |
| 01-APR-20 | HIST | YES | N |
| 01-APR-20 | ITEM | NO | N |
| 01-APR-20 | LOAD_HIST | NO | N |
| 01-APR-20 | LOAD_PROC | NO | N |
| 01-APR-20 | NORD | YES | N |
| 01-APR-20 | ORDL | YES | N |
| 01-APR-20 | ORDR | YES | N |
| 01-APR-20 | STOK | YES | N |
| 01-APR-20 | WARE | YES | N |
+-----------+------------+-------------+-----------+
11 rows in set (0.02 sec)
- 创建存储过程。
obclient> source create_procedures_oracle.sql
Query OK, 0 rows affected (0.08 sec)
<…省略…>
Query OK, 0 rows affected (0.03 sec)
+-------------+-------------+---------------+--------+
| OBJECT_NAME | OBJECT_TYPE | LAST_DDL_TIME | STATUS |
+-------------+-------------+---------------+--------+
| STOCKLEVEL | PROCEDURE | 01-APR-20 | VALID |
| PAYMENT | PROCEDURE | 01-APR-20 | VALID |
| DELIVERY | PROCEDURE | 01-APR-20 | VALID |
| ORDERSTATUS | PROCEDURE | 01-APR-20 | VALID |
| NEWORDER | PROCEDURE | 01-APR-20 | VALID |
| STOCK_ITEM | VIEW | 01-APR-20 | VALID |
+-------------+-------------+---------------+--------+
6 rows in set (0.03 sec)
obclient>
- 初始化表数据。
obclient> source init_data.sql
Query OK, 0 rows affected (0.01 sec)
<…省略…>
Query OK, 0 rows affected (0.01 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 0 rows affected (0.03 sec)
+------------+----------+
| TABLE_NAME | ROWS_CNT |
+------------+----------+
| WARE | 2 |
| DIST | 20 |
| NORD | 40 |
| ORDR | 60 |
| HIST | 240 |
| ITEM | 622 |
| ORDL | 626 |
| CUST | 1040 |
| STOK | 1244 |
+------------+----------+
9 rows in set (0.03 sec)