MySQL HeatWave Quickstart (快速入门)

Posted dingdingfish

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL HeatWave Quickstart (快速入门)相关的知识,希望对你有一定的参考价值。

本实验参考文档HeatWave Quickstart

今天快速体验了一把mysql HeatWave,整个过程比较顺畅,应该算是入了门了。
建议把HeatWave User Guide快速看一遍,也就60多页。

创建一个MySQL数据库系统

在OCI上创建一个MDS(MySQL Data Service),其实就是一个MySQL数据库。

过程可以参考LiveLabs上的实验:MySQL, Data Integration and Data Science for Marine Life Workshop。其中的Lab2就是如何创建MySQL。

输入以下信息:

  • Name:mysql-analytics
  • Username: root
  • Password: ********
  • Shape:MySQL.HeatWave.VM.Standard.E3 (目前唯一可选择的Shape,16 OCPU,512G内存)
  • 网络:选私有网络
  • 其它参数:保持默认值

记录私网地址:10.0.1.248

注意需要在防火墙中开放3306和33060端口,分别表示MySQL 和 MySQL X Protocol。

创建一个堡垒机

仍然可以参照上一步中提到的LiveLabs中的实验。
主机名mysql-bastion, 和MySQL数据库在同一VCN,但是在公网。
记录公网地址:152.67.199.254

登录堡垒机,安装MySQL Shell:

sudo yum update -y
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
sudo yum localinstall -y mysql80-community-release-el7-3.noarch.rpm
sudo yum install mysql-shell mysql-community-client -y

验证:

$ mysqlsh --version
mysqlsh   Ver 8.0.25 for Linux on x86_64 - for MySQL 8.0.25 (MySQL Community Server (GPL))

$ mysqlsh --mysql root@10.0.1.248
Please provide the password for 'root@10.0.1.248': *********
Save password for 'root@10.0.1.248'? [Y]es/[N]o/Ne[v]er (default No): Y
MySQL Shell 8.0.25

Copyright (c) 2016, 2021, 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 '\\?' for help; '\\quit' to exit.
Creating a Classic session to 'root@10.0.1.248'
Fetching schema names for autocompletion... Press ^C to stop.
Your MySQL connection id is 11
Server version: 8.0.25-u3-cloud MySQL Enterprise - Cloud
No default schema selected; type \\use <schema> to set one.
MySQL  10.0.1.248:3306 ssl  JS > 
Bye!

在MySQL中创建数据库

连接到MySQL:

mysqlsh --mysql root@10.0.1.248

切换到SQL执行模式:

 MySQL  10.0.1.248:3306 ssl  JS > \\sql
Switching to SQL mode... Commands end with ;

执行SQL,创建数据库和空表:

CREATE DATABASE tpch character set utf8mb4;
USE tpch;

CREATE TABLE nation  ( N_NATIONKEY INTEGER primary key,
    N_NAME       CHAR(25) NOT NULL,
    N_REGIONKEY  INTEGER NOT NULL,
    N_COMMENT    VARCHAR(152));
							
CREATE TABLE region  ( R_REGIONKEY INTEGER primary key,
    R_NAME       CHAR(25) NOT NULL,
    R_COMMENT    VARCHAR(152));
							
CREATE TABLE part  ( P_PARTKEY INTEGER primary key,
    P_NAME        VARCHAR(55) NOT NULL,
    P_MFGR        CHAR(25) NOT NULL,
    P_BRAND       CHAR(10) NOT NULL,
    P_TYPE        VARCHAR(25) NOT NULL,
    P_SIZE        INTEGER NOT NULL,
    P_CONTAINER   CHAR(10) NOT NULL,
    P_RETAILPRICE DECIMAL(15,2) NOT NULL,
    P_COMMENT     VARCHAR(23) NOT NULL );
						  
CREATE TABLE supplier  ( S_SUPPKEY INTEGER primary key,
    S_NAME        CHAR(25) NOT NULL,
    S_ADDRESS     VARCHAR(40) NOT NULL,
    S_NATIONKEY   INTEGER NOT NULL,
    S_PHONE       CHAR(15) NOT NULL,
    S_ACCTBAL     DECIMAL(15,2) NOT NULL,
    S_COMMENT     VARCHAR(101) NOT NULL);
							 
CREATE TABLE partsupp  ( PS_PARTKEY INTEGER NOT NULL,
    PS_SUPPKEY     INTEGER NOT NULL,
    PS_AVAILQTY    INTEGER NOT NULL,
    PS_SUPPLYCOST  DECIMAL(15,2)  NOT NULL,
    PS_COMMENT     VARCHAR(199) NOT NULL, primary key (ps_partkey, ps_suppkey) );
						
CREATE TABLE customer  ( C_CUSTKEY INTEGER primary key,
    C_NAME        VARCHAR(25) NOT NULL,
    C_ADDRESS     VARCHAR(40) NOT NULL,
    C_NATIONKEY   INTEGER NOT NULL,
    C_PHONE       CHAR(15) NOT NULL,
    C_ACCTBAL     DECIMAL(15,2)   NOT NULL,
    C_MKTSEGMENT  CHAR(10) NOT NULL,
    C_COMMENT     VARCHAR(117) NOT NULL);
							 
CREATE TABLE orders  ( O_ORDERKEY INTEGER primary key,
    O_CUSTKEY        INTEGER NOT NULL,
    O_ORDERSTATUS    CHAR(1) NOT NULL,
    O_TOTALPRICE     DECIMAL(15,2) NOT NULL,
    O_ORDERDATE      DATE NOT NULL,
    O_ORDERPRIORITY  CHAR(15) NOT NULL,
    O_CLERK          CHAR(15) NOT NULL,
    O_SHIPPRIORITY   INTEGER NOT NULL,
    O_COMMENT        VARCHAR(79) NOT NULL);
						   
CREATE TABLE lineitem ( L_ORDERKEY INTEGER NOT NULL,
    L_PARTKEY     INTEGER NOT NULL,
    L_SUPPKEY     INTEGER NOT NULL,
    L_LINENUMBER  INTEGER NOT NULL,
    L_QUANTITY    DECIMAL(15,2) NOT NULL,
    L_EXTENDEDPRICE  DECIMAL(15,2) NOT NULL,
    L_DISCOUNT    DECIMAL(15,2) NOT NULL,
    L_TAX         DECIMAL(15,2) NOT NULL,
    L_RETURNFLAG  CHAR(1) NOT NULL,
    L_LINESTATUS  CHAR(1) NOT NULL,
    L_SHIPDATE    DATE NOT NULL,
    L_COMMITDATE  DATE NOT NULL,
    L_RECEIPTDATE DATE NOT NULL,
    L_SHIPINSTRUCT CHAR(25) NOT NULL,
    L_SHIPMODE     CHAR(10) NOT NULL,
    L_COMMENT      VARCHAR(44) NOT NULL,
    primary key(L_ORDERKEY,L_LINENUMBER));

验证表已建:

 MySQL  10.0.1.248:3306 ssl  tpch  SQL > SHOW TABLES;
+----------------+
| Tables_in_tpch |
+----------------+
| customer       |
| lineitem       |
| nation         |
| orders         |
| part           |
| partsupp       |
| region         |
| supplier       |
+----------------+
8 rows in set (0.0011 sec)

切换回Java Script模式:

MySQL  10.0.1.248:3306 ssl  tpch  SQL > \\js
Switching to javascript mode...

生成TPC-H示例数据

参考HeatWave User Guide中的10.11 Generating tpch Sample Data

以下操作在堡垒机执行,其它任何可以连到MySQL的主机也可以。

TPC Download Current下载TPC-H Tools,目前的版本是3.0.0。

这个软件需要注册下载,因此wget,curl都不能用。只用sftp上传了。

$ ls -l
total 26536
-rw-rw-r--. 1 opc opc 27169393 Jul  6 03:12 tpc-h-tool.zip

$ unzip tpc-h-tool.zip

$ ls -l
total 28664
drwxrwxr-x. 5 opc opc     4096 Mar 10 16:23 TPC-H_Tools_v3.0.0
-rw-rw-r--. 1 opc opc 27169393 Jul  6 03:12 tpc-h-tool.zip
-rw-rw-r--. 1 opc opc   383884 Feb 10 12:08 tpc-h_v3.0.0.docx
-rw-rw-r--. 1 opc opc  1786522 Feb 10 07:55 tpc-h_v3.0.0.pdf

$ cd TPC-H_Tools_v3.0.0/dbgen/

$ cp makefile.suite makefile

$ vi makefile
按照以下修改Makefile中的环境变量
CC = gcc
DATABASE= ORACLE
MACHINE = LINUX
WORKLOAD = TPCH

$ make

生成TPC-H测试数据,8张表,大约1G:

$ time ./dbgen -s 1
TPC-H Population Generator (Version 3.0.0)
Copyright Transaction Processing Performance Council 1994 - 2010

real    0m26.640s
user    0m26.216s
sys     0m0.419s

$ ls -l *tbl
-rw-rw-r--. 1 opc opc  24346144 Jul  6 03:18 customer.tbl
-rw-rw-r--. 1 opc opc 759863287 Jul  6 03:18 lineitem.tbl
-rw-rw-r--. 1 opc opc      2224 Jul  6 03:18 nation.tbl
-rw-rw-r--. 1 opc opc 171952161 Jul  6 03:18 orders.tbl
-rw-rw-r--. 1 opc opc 118984616 Jul  6 03:18 partsupp.tbl
-rw-rw-r--. 1 opc opc  24135125 Jul  6 03:18 part.tbl
-rw-rw-r--. 1 opc opc       389 Jul  6 03:18 region.tbl
-rw-rw-r--. 1 opc opc   1409184 Jul  6 03:18 supplier.tbl

$ du -ch *tbl
24M     customer.tbl
725M    lineitem.tbl
4.0K    nation.tbl
164M    orders.tbl
114M    partsupp.tbl
24M     part.tbl
4.0K    region.tbl
1.4M    supplier.tbl
1.1G    total

执行以下脚本:

for  t in *.tbl; do
	echo "util.importTable(\\"file://$t\\", {schema:\\"tpch\\", table:\\"${t%.*}\\", fieldsTerminatedBy:\\"|\\", bytesPerChunk:\\"100M\\", threads:16})"
done

生成以下命令,在MySQL中以JavaScript模式执行,导入数据:

util.importTable("file://customer.tbl", {schema:"tpch", table:"customer", fieldsTerminatedBy:"|", bytesPerChunk:"100M", threads:16})
util.importTable("file://lineitem.tbl", {schema:"tpch", table:"lineitem", fieldsTerminatedBy:"|", bytesPerChunk:"100M", threads:16})
util.importTable("file://nation.tbl", {schema:"tpch", table:"nation", fieldsTerminatedBy:"|", bytesPerChunk:"100M", threads:16})
util.importTable("file://orders.tbl", {schema:"tpch", table:"orders", fieldsTerminatedBy:"|", bytesPerChunk:"100M", threads:16})
util.importTable("file://partsupp.tbl", {schema:"tpch", table:"partsupp", fieldsTerminatedBy:"|", bytesPerChunk:"100M", threads:16})
util.importTable("file://part.tbl", {schema:"tpch", table:"part", fieldsTerminatedBy:"|", bytesPerChunk:"100M", threads:16})
util.importTable("file://region.tbl", {schema:"tpch", table:"region", fieldsTerminatedBy:"|", bytesPerChunk:"100M", threads:16})
util.importTable("file://supplier.tbl", {schema:"tpch", table:"supplier", fieldsTerminatedBy:"|", bytesPerChunk:"100M", threads:16})

导入后,看一下最大的一张表:

 MySQL  10.0.1.248:3306 ssl  tpch  SQL > select count(*) from lineitem;
+----------+
| count(*) |
+----------+
|  6001240 |
+----------+
1 row in set (0.0461 sec)

添加HeatWave Cluster

之前建立MDS时,虽然选的是HeatWave Shape,但是尚未激活。因此进入菜单MySQL>MySQL DB Systems>MySQL DB System Details,单击Add HeatWave Cluster。
选择Node Count为2,每个节点有16 CPU core,512GB内存。对于1GB的测试数据足够了。

HeatWave的节点数后续可以扩展,最多到64个。

把数据加载到HeatWave Cluster

连接到MySQL:

mysqlsh --mysql root@10.0.1.248

切换到SQL执行模式:

MySQL  10.0.1.248:3306 ssl  JS > \\sql
Switching to SQL mode... Commands end with ;

执行以下SQL。其实就是指定需要加载到HeatWave内存中的表,非常类似Database In-Memory中的alter table ... inmemory

USE tpch;

ALTER TABLE nation modify `N_NAME` CHAR(25) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE nation modify `N_COMMENT` VARCHAR(152) COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE nation SECONDARY_ENGINE=RAPID;
ALTER TABLE nation SECONDARY_LOAD;

ALTER TABLE region modify `R_NAME` CHAR(25) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE region modify `R_COMMENT` VARCHAR(152) COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE region SECONDARY_ENGINE=RAPID;
ALTER TABLE region SECONDARY_LOAD;

ALTER TABLE part modify `P_MFGR` CHAR(25) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE part modify `P_BRAND` CHAR(10) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE part modify `P_CONTAINER` CHAR(10) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE part modify `P_COMMENT` VARCHAR(23) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE part SECONDARY_ENGINE=RAPID;
ALTER TABLE part SECONDARY_LOAD;

ALTER TABLE supplier modify `S_NAME` CHAR(25) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE supplier modify `S_ADDRESS` VARCHAR(40) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE supplier modify `S_PHONE` CHAR(15) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE supplier SECONDARY_ENGINE=RAPID;
ALTER TABLE supplier SECONDARY_LOAD;

ALTER TABLE partsupp modify `PS_COMMENT` VARCHAR(199) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE partsupp SECONDARY_ENGINE=RAPID;
ALTER TABLE partsupp SECONDARY_LOAD;

ALTER TABLE customer modify `C_NAME` VARCHAR(25) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE customer modify `C_ADDRESS` VARCHAR(40) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE customer modify `C_MKTSEGMENT` CHAR(10) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE customer modify `C_COMMENT` VARCHAR(117) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE customer SECONDARY_ENGINE=RAPID;
ALTER TABLE customer SECONDARY_LOAD;

ALTER TABLE orders modify `O_ORDERSTATUS` CHAR(1) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE orders modify `O_ORDERPRIORITY` CHAR(15) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE orders modify `O_CLERK` CHAR(15) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE orders SECONDARY_ENGINE=RAPID;
ALTER TABLE orders SECONDARY_LOAD;

ALTER TABLE lineitem modify `L_RETURNFLAG` CHAR(1) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE lineitem modify `L_LINESTATUS` CHAR(1) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE lineitem modify `L_SHIPINSTRUCT` CHAR(25) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE lineitem modify `L_SHIPMODE` CHAR(10) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE lineitem modify `L_COMMENT` VARCHAR(44) NOT NULL COMMENT 'RAPID_COLUMN=ENCODING=SORTED';
ALTER TABLE lineitem SECONDARY_ENGINE=RAPID;
ALTER TABLE lineitem SECONDARY_LOAD;

确认表已加载到HeatWave:

USE performance_schema;
SELECT NAME, LOAD_STATUS FROM rpd_tables,rpd_table_id WHERE rpd_tables.ID = rpd_table_id.ID;

输出如下:

+---------------+---------------------+
| NAME          | LOAD_STATUS         |
+---------------+---------------------+
| tpch.supplier | AVAIL_RPDGSTABSTATE |
| tpch.partsupp | AVAIL_RPDGSTABSTATE |
| tpch.orders   | AVAIL_RPDGSTABSTATE |
| tpch.lineitem | AVAIL_RPDGSTABSTATE |
| tpch.customer | AVAIL_RPDGSTABSTATE |
| tpch.nation   | AVAIL_RPDGSTABSTATE |
| tpch.region   | AVAIL_RPDGSTABSTATE |
| tpch.part     | AVAIL_RPDGSTABSTATE |
+---------------+---------------------+
8 rows in set (0.0008 sec)

执行以下SQL, \\G表示grid view,就是输出翻转90度:

use tpch;
EXPLAIN SELECT SUM(l_extendedprice * l_discount) AS revenue 
           FROM lineitem WHERE l_shipdate >= date '1994-01-01'\\G

输出如下,Extra部分的Using secondary engine RAPID说明SQL操作已卸载到HeatWave:

*************************** 1. row ***************************
           id: 1
  select_type: SIMPLE
        table: lineitem
   partitions: NULL
         type: ALL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 5816186
     filtered: 33.33
        Extra: Using where; Using secondary engine RAPID
1 row in set, 1 warning (0.0038 sec)
Note (code 1003): /* select#1 */ select sum((`tpch`.`lineitem`.`L_EXTENDEDPRICE` 以上是关于MySQL HeatWave Quickstart (快速入门)的主要内容,如果未能解决你的问题,请参考以下文章

MySQL HeatWave Quickstart AutoPilot简介

Oracle CloudWorld 2022:重磅推出MySQL湖仓产品-MySQL HeatWave Lakehouse

QGIS Server Quickstart

Jackson - Quickstart

maven_创建quickstart模板时异常

Quickstart: DataFrame