All Products
Search
Document Center

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

Last Updated: May 13, 2019

Create a MySQL table

  1. create external table person (
  2. id int,
  3. name varchar(1023),
  4. age int
  5. ) tblproperties (
  6. table_mapping = "person"
  7. );

Query data from the MySQL table

  1. Log on to the Data Lake Analytics console.

  2. In the left-side navigation pane, click Endpoint. In the endpoint list, locate the row that contains the target endpoint and click Log on in DMS in the Actions column. On the DMS for Data Lake Analytics page that appears, query data from the MySQL table named person.

    You can also use the MySQL client to connect to the mapping database hello_mysql_vpc_rds in DLA, and to read and write data from and to the MySQL database.

    1. mysql> select * from person;
    2. +------+-------+------+
    3. | id | name | age |
    4. +------+-------+------+
    5. | 1 | james | 10 |
    6. | 2 | bond | 20 |
    7. | 3 | jack | 30 |
    8. | 4 | lucy | 40 |
    9. +------+-------+------+
    10. 4 rows in set (0.35 sec)

Cleanse data from OSS and write the data to ApsaraDB for RDS

DLA is seldom used to read data from ApsaraDB for RDS. ApsaraDB for RDS can handle only a limited amount of data and is not applicable for big data analysis. A more common DLA application scenario is to analyze massive amounts of data that is stored in OSS or Table Store, and then write the result back to ApsaraDB for RDS for frontend services to use.

Take the person table as an example. Execute the following statements to convert the first 10 customer records in the oss_db table, and then insert them into the hello_mysql_vpc_rds.person table:

For more information about how to read data from OSS in DLA, see Use DLA to read data from OSS.

  1. mysql> insert into hello_mysql_vpc_rds.person
  2. select c_custkey, c_name, c_custkey + 20 from oss_db.customer limit 10;
  3. + ---- +
  4. | rows |
  5. + ---- +
  6. | 10 |
  7. + ---- +
  8. 1 row in set (4.57 sec)
  9. mysql> select * from person;
  10. +------+--------------------+------+
  11. | id | name | age |
  12. +------+--------------------+------+
  13. | 1 | james | 10 |
  14. | 2 | bond | 20 |
  15. | 3 | jack | 30 |
  16. | 4 | lucy | 40 |
  17. | 1 | Customer#000000001 | 21 |
  18. | 3 | Customer#000000003 | 23 |
  19. | 5 | Customer#000000005 | 25 |
  20. | 2 | Customer#000000002 | 22 |
  21. | 4 | Customer#000000004 | 24 |
  22. | 7 | Customer#000000007 | 27 |
  23. | 6 | Customer#000000006 | 26 |
  24. | 9 | Customer#000000009 | 29 |
  25. | 8 | Customer#000000008 | 28 |
  26. | 10 | Customer#000000010 | 30 |
  27. +------+--------------------+------+
  28. 14 rows in set (0.26 sec)