150 lines
3.0 KiB
Markdown
150 lines
3.0 KiB
Markdown
创建 OceanBase 示例数据库 TPCC
|
|
============================================
|
|
|
|
|
|
|
|
默认情况 OceanBase 没有创建示例数据库 TPCC,需要手动创建。示例数据库必须在业务租户下创建。有关示例数据库介绍请参考 [关于示例数据库 TPCC](../../7.developer-guide-1/1.preface-2/4.about-the-sample-database-tpcc-2.md)。
|
|
|
|
租户创建好后,需要创建相应的 DataBase 来存放示例数据库的对象,还要分配相应的用户和访问权限。
|
|
|
|
示例
|
|
-----------
|
|
|
|
1. 通过 obclient 连接 MySQL 租户。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
#obclient -h192.168.1.101 -uroot@obmysql#obdemo -P2883 -pabcABC123 -A oceanbase
|
|
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 57981
|
|
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.
|
|
```
|
|
|
|
|
|
|
|
2. 创建一个数据库。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
obclient> create database tpccdb;
|
|
Query OK, 1 row affected (0.02 sec)
|
|
obclient> show databases;
|
|
+--------------------+
|
|
| Database |
|
|
+--------------------+
|
|
| oceanbase |
|
|
| information_schema |
|
|
| mysql |
|
|
| test |
|
|
| tpccdb |
|
|
+--------------------+
|
|
5 rows in set (0.01 sec)
|
|
```
|
|
|
|
|
|
|
|
3. 创建一个用户并赋权。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
obclient> grant all privileges on tpccdb.* to tpcc identified by '123456';
|
|
Query OK, 0 rows affected (0.02 sec)
|
|
|
|
obclient> show grants for tpcc;
|
|
+----------------------------------------------+
|
|
| Grants for tpcc@% |
|
|
+----------------------------------------------+
|
|
| GRANT USAGE ON *.* TO 'tpcc' |
|
|
| GRANT SELECT ON `oceanbase`.* TO 'tpcc' |
|
|
| GRANT ALL PRIVILEGES ON `tpccdb`.* TO 'tpcc' |
|
|
+----------------------------------------------+
|
|
3 rows in set (0.01 sec)
|
|
|
|
obclient>
|
|
```
|
|
|
|
|
|
|
|
4. 创建数据库对象
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
obclient> use tpccdb;
|
|
Database changed
|
|
obclient> source create_mysql_tables.sql
|
|
Query OK, 0 rows affected (0.01 sec)
|
|
<...省略...>
|
|
Query OK, 0 rows affected (0.01 sec)
|
|
+------------------+
|
|
| Tables_in_tpccdb |
|
|
+------------------+
|
|
| cust |
|
|
| dist |
|
|
| hist |
|
|
| item |
|
|
| load_hist |
|
|
| load_proc |
|
|
| nord |
|
|
| ordl |
|
|
| ordr |
|
|
| stock_item |
|
|
| stok |
|
|
| ware |
|
|
+------------------+
|
|
12 rows in set (0.00 sec)
|
|
```
|
|
|
|
|
|
|
|
5. 初始化表数据。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```javascript
|
|
obclient> source init_data.sql
|
|
Query OK, 0 rows affected (0.01 sec)
|
|
<...省略...>
|
|
Query OK, 0 rows affected (0.01 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.01 sec)
|
|
```
|
|
|
|
|
|
|