Wednesday, December 24, 2025

Deploying on OCI with the starter equipment – half 8 (utilizing MySQL REST Service)


The starter equipment deploys a MySQL HeatWave DB System on OCI and allows the MySQL REST Service mechanically:

The REST Service allows us to supply entry to information with out requiring SQL. It additionally offers entry to some Gen AI functionalities out there in MySQL HeatWave.

Including information to MRS utilizing Visible Studio Code

To have the ability to use the MRS functionalities out there in MySQL Shell for Visible Studio Code, we have to grant some privileges to our admin person:

sql> GRANT 'mysql_rest_service_admin' TO 'admin'@'%';
sql> SET DEFAULT ROLE ALL TO 'admin'@'%';

It’s really useful to shut the connection and reconnect for speedy grants.

We’ll use MySQL Shell for Visible Studio Code to create a brand new desk and supply entry to it utilizing MRS.

sql> create database myproject;
sql> use myproject
sql> create desk myrecords (id int unsigned auto_increment main key, 
                            title varchar(20),
                            inserted timestamp default current_timestamp);
sql> insert into myrecords (title) values ('Scott'), ('Miguel'), ('Fred');

First, we have to create a brand new REST Service. There’s already one, nevertheless it’s devoted to HeatWave:

We name our service “MyService” and it’s accessible utilizing the trail /myService:

Then we have to add the schema and the desk to the service:

Because the schema hasn’t been added to the service (we used a shortcut), MySQL Shell asks whether or not we wish to add it. We are saying “sure”:

We additionally must create a person to entry our service. The MySQL App is enabled by default.

sql> create person myrest recognized by 'myrestPassw0rd!';

Accessing information utilizing curl

In our compute occasion, we are able to attempt to entry our REST service utilizing curl.

We’d like first to create a cookie (essentially the most simple technique with curl):

$ curl -c cookie.txt -k  -X POST  -H "Content material-Kind: software/json" 
   -d '{"username": "myrest",
        "password": "myrestPassw0rd!",
        "sessionType": "cookie",
        "authApp": "MySQL" }' 
  https://10.0.1.57/myService/authentication/login
{}
$ curl -s -b cookie.txt -k -X GET  https://10.0.1.57/myService/myproject/myrecords | jq
{
  "gadgets": [
    {
      "id": 1,
      "name": "Scott",
      "links": [
        {
          "rel": "self",
          "href": "/myService/myproject/myrecords/1"
        }
      ],
      "inserted": "2025-09-25 09:52:39.000000",
      "_metadata": {
        "etag": "C1D669130D63FD76C50E617DFA2A1A982DBCFC2B38A7D4E213BD2C8872580A6D"
      }
    },
    {
      "id": 2,
      "title": "Fred",
      "hyperlinks": [
        {
          "rel": "self",
          "href": "/myService/myproject/myrecords/2"
        }
      ],
      "inserted": "2025-09-25 09:52:39.000000",
      "_metadata": {
        "etag": "3E8174FCE3DBB38F0FA331E36460F9299C950522809213CC41A7AF954D0E83C4"
      }
    },
    {
      "id": 3,
      "title": "Miguel",
      "hyperlinks": [
        {
          "rel": "self",
          "href": "/myService/myproject/myrecords/3"
        }
      ],
      "inserted": "2025-09-25 09:52:39.000000",
      "_metadata": {
        "etag": "6519AE07EC7874D08071BD5F52209202EDECEE040FF00EDC314C0401CA51E729"
      }
    }
  ],
  "restrict": 25,
  "offset": 0,
  "hasMore": false,
  "rely": 3,
  "hyperlinks": [
    {
      "rel": "self",
      "href": "/myService/myproject/myrecords/"
    }
  ]
}

We will additionally specify a single file:

$ curl -s -b cookie.txt -k -X GET  https://10.0.1.57/myService/myproject/myrecords/2 | jq
{
  "id": 2,
  "title": "Fred",
  "hyperlinks": [
    {
      "rel": "self",
      "href": "/myService/myproject/myrecords/2"
    }
  ],
  "inserted": "2025-09-25 09:52:39.000000",
  "_metadata": {
    "etag": "3E8174FCE3DBB38F0FA331E36460F9299C950522809213CC41A7AF954D0E83C4"
  }
}

Examine the video to see the totally different steps in motion:

Utilizing the SDK

We will additionally use the SDK, which may be very easy.

We begin by downloading the SDK of our service:

I want to make use of the Personal IP of the MySQL HeatWave occasion and choose Python language for the SDK:

We copy that downloaded folder to our compute occasion, and we have to rename it as sdk:

[laptop]$ scp -r -i key.pem -r myService.mrs.sdk opc@:

[compute]$ mkdir myproject
[compute]$ mv myService.mrs.sdk myproject/sdk
[compute]$ cd myproject

We will now create our Python software:

from sdk.my_service import *

my_service = MyService(verify_tls_cert=False)

async def primary():
    await my_service.authenticate(
            username = "myrest",
            password = "myrestPassw0rd!",
            app = "MySQL",
            )
    data = await my_service.myproject.myrecords.discover()
    for file in data:
        print(file.title)

    await my_service.myproject.myrecords.create(information={"title": "Lenka"})

asyncio.run(primary())

And we are able to execute it:

[opc@webserver myproject]$ python3.12 venture.py 
Scott
Fred
Miguel

Examine the video to see how one can use the SDK:

Extra Information about MRS

Conclusion

With the MySQL REST Service deployed by the starter equipment, you’ve seen how simple it’s to reveal information from MySQL HeatWave with out writing a single line of SQL in your software. Ranging from a easy desk in your database, you granted the correct privileges, printed the schema to MRS, and accessed it securely over HTTPS – first with plain curl, then with a generated Python SDK.

This strategy provides you a clear, trendy API layer on prime of your database: good for hackathons, fast prototypes, and microservices that must eat MySQL information or name GenAI options with minimal boilerplate. From right here, you may lengthen the identical sample to extra complicated schemas, add authentication and authorization guidelines, or generate SDKs in different languages so each a part of your stack can converse REST to MySQL HeatWave.

Subscribe to Weblog by way of E mail

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles