All Products
Search
Document Center

Create a PolarDB table and read data from and write data to the table

Last Updated: Mar 23, 2021

This topic describes how to create a PolarDB table in Data Lake Analytics (DLA). It also provides further details about how to read data from and write data to the PolarDB table.

Create a PolarDB table

  1. Log on to the DLA console.

  2. In the left-side navigation pane, choose Serverless SQL > SQL access point. On the SQL access point page, find your VPC in the VPC Network section and click Log on in DMS in the Actions column to create the person table by using the following statement:

     create external table polardb_person (
            id int,
            name varchar(1023),
            age int
     )TBLPROPERTIES (
         TABLE_MAPPING = 'person'
     )

Read data from the PolarDB table

After you create a PolarDB schema and table, you can use a MySQL client or MySQL command-line tool to connect to DLA. Then, you can execute standard SQL statements to read data from the table.

In this example, a MySQL command-line tool is used to connect to DLA and read data from the person table in the PolarDB database.

mysql> select * from polardb_person;
+------+-------+------+
| id   | name  | age  |
+------+-------+------+
|    1 | james |   10 |
|    2 | bond  |   20 |
|    3 | jack  |   30 |
|    4 | lucy  |   40 |
+------+-------+------+
4 rows in set (0.35 sec)

Write data to the PolarDB table

In this example, a MySQL command-line tool is used to connect to DLA and write data to the person table in the PolarDB database.

mysql> insert into polardb_person 
  values (5, 'Alan', 50), (6, 'Alice', 60);

 mysql> select * from polardb_person;
+------+-------+------+
| id   | name  | age  |
+------+-------+------+
|    1 | james |   10 |
|    2 | bond  |   20 |
|    3 | jack  |   30 |
|    4 | lucy  |   40 |
|    5 | Alan  |   50 |
|    6 | Alice  |   60 |