MySQL service integration example
In this guide, you’ll learn how to define a MySQL service as a reusable service in nullplatform. This allows you to manage it centrally and link it to other entities.
How it works
A MySQL service configuration represents a MySQL database instance. It includes key attributes used to connect and operate with the database.
This service refers to a MySQL database instance, which includes key parameters for connecting to the database:
Attributes:
- Host: The address of the MySQL database server.
- Port: The port number used for MySQL connections.
- Size: The tier of the database instance.
Links: development and production environments
The MySQL service is linked to the application through two environments, each with its own configuration:
- Development link - properties:
- Database: The development database name.
- Username: Credential for accessing the MySQL database in development.
- Password: Password for the development database.
- Production link - properties:
- Database: The production database name.
- Username: Credential for accessing the MySQL database in production.
- Password: Password for the production database.
Automatic parameter integration
These attributes and properties are passed as parameters into the application configuration, making it easy to switch between environments without code changes.
This setup helps manage MySQL database connections in a straightforward way, ensuring that configurations can easily switch between development and production environments.
1. Craft your service specification
The example below shows how to craft a MySQL service specification tailored to your organization's settings.
You can create a service spec using our CLI or API.
- CLI
- cURL
np service-specification create \
--body '{
"name": "MySQL service",
"visible_to": ["organization=12345:account=12345:namespace=28"],
"type": "dependency",
"dimensions": {},
"use_default_actions": true,
"attributes" : {
"schema": {
"type": "object",
"required": ["host", "port"],
"properties": {
"host": {
"type": "string",
"export": true,
"readOnly": true,
"visibleOn": [
"read",
"update"
],
"editableOn": []
},
"port": {
"type": "integer",
"export": true,
"default": 3306,
"readOnly": true,
"visibleOn": [
"read",
"update"
],
"editableOn": []
},
"size": {
"enum": [
"small",
"medium",
"large"
],
"type": "string",
"default": "small",
"visibleOn": [
"read",
"create",
"update"
],
"editableOn": ["create"]
}
},
"additionalProperties": false
},
"values": {}
},
"selectors": {
"category": "Database",
"imported": false,
"provider": "AWS",
"sub_category": "Relational Database"
}
}
curl -L -X POST 'https://api.nullplatform.com/service_specification' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer the-token' \
-d '{
"name": "MySQL service",
"visible_to": ["organization=12345:account=12345:namespace=28"],
"type": "dependency",
"dimensions": {},
"use_default_actions": true,
"attributes" : {
"schema": {
"type": "object",
"required": ["host", "port"],
"properties": {
"host": {
"type": "string",
"export": true,
"readOnly": true,
"visibleOn": [
"read",
"update"
],
"editableOn": []
},
"port": {
"type": "integer",
"export": true,
"default": 3306,
"readOnly": true,
"visibleOn": [
"read",
"update"
],
"editableOn": []
},
"size": {
"enum": [
"small",
"medium",
"large"
],
"type": "string",
"default": "small",
"visibleOn": [
"read",
"create",
"update"
],
"editableOn": ["create"]
}
},
"additionalProperties": false
},
"values": {}
},
"selectors": {
"category": "Database",
"imported": false,
"provider": "AWS",
"sub_category": "Relational Database"
}
}
-
visible_to
: This service is exclusively visible within the namespace28
of the specified organization and account:organization=12345:account=12345:namespace=28
. -
use_default_actions
: Enables the default set of actions (create, update, and delete) for this service. -
attributes
define the required connection and configuration details used by applications that rely on this MySQL instance:host
: The hostname or IP address where the MySQL server is running. This value is marked as read-only and is exported for use in downstream services.port
: The port number MySQL uses to accept connections, typically3306
. This is also read-only and exported.size
: An enum field representing the size tier of the database instance. Accepts values"small"
,"medium"
, or"large"
. Editable during creation only and visible throughout the lifecycle.
-
visibleOn
: Controls when a property is shown in the UI (e.g.,read
,create
,update
).editableOn
: Controls when a property can be edited. An empty array means the property cannot be modified at any stage.
For more details, refer to Create service specification in our API docs.
2. Create the link specification
Next, define how other entities can connect to the service — specifying credentials and database name.
As with service specs, you can craft link specifications using our CLI or our API.
- CLI
- cURL
np link_specification create \
--body '{
"name": "Link MySQL Database",
"unique": false,
"attributes" : {
"schema": {
"type": "object",
"required": ["username", "password", "name"],
"properties": {
"name": {
"type": "string",
"export": true,
"readOnly": false,
"visibleOn": [
"create",
"update"
],
"editableOn": ["create"]
},
"password": {
"type": "string",
"export": {
"type": "environment_variable",
"secret": true
},
"readOnly": true,
"visibleOn": [
"create"
],
"editableOn": []
},
"username": {
"type": "string",
"export": true,
"readOnly": true,
"visibleOn": [
"create"
],
"editableOn": []
}
},
"additionalProperties": false
},
"values": {}
},
"specification_id": "f3da5e42-87cb-49d3-b108-4c6b9fd7202b"
}
curl -L 'https://api.nullplatform.com/link_specification' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer the-token' \
-d '{
"name": "Link MySQL Database",
"unique": false,
"attributes" : {
"schema": {
"type": "object",
"required": ["username", "password", "name"],
"properties": {
"name": {
"type": "string",
"export": true,
"readOnly": false,
"visibleOn": [
"create",
"update"
],
"editableOn": ["create"]
},
"password": {
"type": "string",
"export": {
"type": "environment_variable",
"secret": true
},
"readOnly": true,
"visibleOn": [
"create"
],
"editableOn": []
},
"username": {
"type": "string",
"export": true,
"readOnly": true,
"visibleOn": [
"create"
],
"editableOn": []
}
},
"additionalProperties": false
},
"values": {}
},
"specification_id": "f3da5e42-87cb-49d3-b108-4c6b9fd7202b"
}
This link exports credentials and schema parameters to any application using this MySQL service, with sensitive data managed securely as secrets.
For more details, refer to Create a link specification in our API docs.
Security and permissions
Each defined element comes with its own permissions and access control, allowing for the management of who can create and use resources and where these resources can be deployed.