# Public Cloud › Databases › MySQL › Queries API

> Part of the OVHcloud developer hub. Index of every page and section: https://developers.eu.ovhcloud.com/llms.txt
> The Public Cloud product's sections: https://developers.eu.ovhcloud.com/reference/public-cloud/llms.txt
> Everything in one file: https://developers.eu.ovhcloud.com/llms-full.txt

> 5 operations of the OVHcloud API. Calls carry `authorization: Bearer $OVH_TOKEN`; the EU host is shown, Canada and the United States answer on api.ca.ovhcloud.com and api.us.ovhcloud.com.

Page: https://developers.eu.ovhcloud.com/reference/public-cloud/databases/mysql/queries/

OpenAPI v1: https://api.eu.ovhcloud.com/1.0/__schemas/developer-hub-navigation/public-cloud/databases/mysql/queries.json?format=openapi3
OpenAPI v2: https://api.eu.ovhcloud.com/v2/__schemas/developer-hub-navigation/public-cloud/databases/mysql/queries.json?format=openapi3

## Operations

- `GET /publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries` — List running queries
- `GET /publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries/{queryPid}` — Get a running query
- `POST /publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries/{queryPid}/cancel` — Cancel a running query
- `GET /publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/queryStatistics` — List query statistics
- `POST /publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/queryStatistics/reset` — Reset query statistics

## List running queries

`GET /v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries`

Link: https://developers.eu.ovhcloud.com/reference/public-cloud/databases/mysql/queries/#get-publiccloud-project-projectid-manageddatabase-mysql-serviceid-currentqueries

**Status:** Beta version  
**IAM actions:** `publicCloudProject:apiovh:database/mysql/currentQueries/get`

Returns the queries running on the service, with their client, user, state and duration.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `X-Pagination-Cursor` | header | string |  | Pagination cursor |
| `X-Pagination-Size` | header | integer |  | Pagination size |
| `projectId` | path | string | yes | Project ID |
| `serviceId` | path | string (uuid) | yes | Service ID |

### Responses

| Status | Type | Description |
| --- | --- | --- |
| 200 | publicCloud.database.CurrentQuery[] | successful operation |

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `applicationName` | string | read-only | Name of the application that initiated the query |
| `backendStartedAt` | string (date-time) | read-only | Timestamp when the backend process started |
| `clientIp` | ip | read-only | IP address of the client |
| `clientPort` | integer | read-only | Port of the client connection |
| `databaseName` | string | read-only | Name of the database the query is running on |
| `pid` | integer | read-only | Process ID of the connection |
| `query` | string | read-only | SQL text of the currently running query |
| `queryDuration` | number | read-only | Duration of the query in seconds |
| `queryStartedAt` | string (date-time) | read-only | Timestamp when the query started |
| `state` | publicCloud.database.CurrentQueryStateEnum | read-only | Current state of the connection — one of `ACTIVE`, `DISABLED`, `FASTPATH_FUNCTION_CALL`, `IDLE`, `IDLE_IN_TRANSACTION`, `IDLE_IN_TRANSACTION_ABORTED` |
| `userName` | string | read-only | Name of the user running the query |
| `waitEvent` | string | read-only | Name of the wait event the connection is waiting on, if any |
| `waitEventType` | publicCloud.database.CurrentQueryWaitEventTypeEnum | read-only | Type of wait event the connection is waiting on, if any — one of `ACTIVITY`, `BUFFER_PIN`, `CLIENT`, `EXTENSION`, `IO`, `IPC`, `LOCK`, `LWLOCK`, `TIMEOUT` |

```json
[
  {
    "applicationName": "string",
    "backendStartedAt": "2024-01-01T12:00:00Z",
    "clientIp": "192.0.2.0",
    "clientPort": 0,
    "databaseName": "string",
    "pid": 0,
    "query": "string",
    "queryDuration": 0,
    "queryStartedAt": "2024-01-01T12:00:00Z",
    "state": "ACTIVE",
    "userName": "string",
    "waitEvent": "string",
    "waitEventType": "ACTIVITY"
  }
]
```

### Example

```bash
curl -X GET \
  "https://api.eu.ovhcloud.com/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries" \
  -H "accept: application/json" \
  -H "authorization: Bearer $OVH_TOKEN"
```

```python
'''
First, install the latest release of Python wrapper: $ pip install ovh
'''
import json
import ovh

# Instantiate an OVH Client.
# You can generate new credentials with full access to your account on
# the token creation page (https://api.ovh.com/createToken/index.cgi?GET=/*&PUT=/*&POST=/*&DELETE=/*)
client = ovh.Client(
	endpoint='ovh-eu',               # Endpoint of API OVH (List of available endpoints: https://github.com/ovh/python-ovh#2-configure-your-application)
	application_key='xxxxxxxxxx',    # Application Key
	application_secret='xxxxxxxxxx', # Application Secret
	consumer_key='xxxxxxxxxx',       # Consumer Key
)

result = client.get("/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries")

# Pretty print
print(json.dumps(result, indent=4))
```

```php
<?php
/**
 * First, download the latest release of PHP wrapper on github
 * And include this script into the folder with extracted files
 */
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;

/**
 * Instantiate an OVH Client.
 * You can generate new credentials with full access to your account on
 * the token creation page (https://api.ovh.com/createToken/index.cgi?GET=/*&PUT=/*&POST=/*&DELETE=/*)
 */
$ovh = new Api('xxxxxxxxxx',  // Application Key
               'xxxxxxxxxx',  // Application Secret
               'ovh-eu',      // Endpoint of API OVH (List of available endpoints: https://github.com/ovh/python-ovh#2-configure-your-application)
               'xxxxxxxxxx'); // Consumer Key

$result = $ovh->get("/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries");

print_r($result);
?>
```

## Get a running query

`GET /v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries/{queryPid}`

Link: https://developers.eu.ovhcloud.com/reference/public-cloud/databases/mysql/queries/#get-publiccloud-project-projectid-manageddatabase-mysql-serviceid-currentqueries-querypid

**Status:** Beta version  
**IAM actions:** `publicCloudProject:apiovh:database/mysql/currentQueries/get`

Returns the SQL text, state and duration of a running query, identified by its process ID.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `limit` | query | integer |  | Maximum number of queries to return |
| `offset` | query | integer |  | Number of queries to skip before returning results |
| `projectId` | path | string | yes | Project ID |
| `queryPid` | path | integer | yes | Query pid |
| `serviceId` | path | string (uuid) | yes | Service ID |

### Responses

| Status | Type | Description |
| --- | --- | --- |
| 200 | publicCloud.database.CurrentQuery | successful operation |

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `applicationName` | string | read-only | Name of the application that initiated the query |
| `backendStartedAt` | string (date-time) | read-only | Timestamp when the backend process started |
| `clientIp` | ip | read-only | IP address of the client |
| `clientPort` | integer | read-only | Port of the client connection |
| `databaseName` | string | read-only | Name of the database the query is running on |
| `pid` | integer | read-only | Process ID of the connection |
| `query` | string | read-only | SQL text of the currently running query |
| `queryDuration` | number | read-only | Duration of the query in seconds |
| `queryStartedAt` | string (date-time) | read-only | Timestamp when the query started |
| `state` | publicCloud.database.CurrentQueryStateEnum | read-only | Current state of the connection — one of `ACTIVE`, `DISABLED`, `FASTPATH_FUNCTION_CALL`, `IDLE`, `IDLE_IN_TRANSACTION`, `IDLE_IN_TRANSACTION_ABORTED` |
| `userName` | string | read-only | Name of the user running the query |
| `waitEvent` | string | read-only | Name of the wait event the connection is waiting on, if any |
| `waitEventType` | publicCloud.database.CurrentQueryWaitEventTypeEnum | read-only | Type of wait event the connection is waiting on, if any — one of `ACTIVITY`, `BUFFER_PIN`, `CLIENT`, `EXTENSION`, `IO`, `IPC`, `LOCK`, `LWLOCK`, `TIMEOUT` |

```json
{
  "applicationName": "string",
  "backendStartedAt": "2024-01-01T12:00:00Z",
  "clientIp": "192.0.2.0",
  "clientPort": 0,
  "databaseName": "string",
  "pid": 0,
  "query": "string",
  "queryDuration": 0,
  "queryStartedAt": "2024-01-01T12:00:00Z",
  "state": "ACTIVE",
  "userName": "string",
  "waitEvent": "string",
  "waitEventType": "ACTIVITY"
}
```

### Example

```bash
curl -X GET \
  "https://api.eu.ovhcloud.com/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries/{queryPid}" \
  -H "accept: application/json" \
  -H "authorization: Bearer $OVH_TOKEN"
```

```python
'''
First, install the latest release of Python wrapper: $ pip install ovh
'''
import json
import ovh

# Instantiate an OVH Client.
# You can generate new credentials with full access to your account on
# the token creation page (https://api.ovh.com/createToken/index.cgi?GET=/*&PUT=/*&POST=/*&DELETE=/*)
client = ovh.Client(
	endpoint='ovh-eu',               # Endpoint of API OVH (List of available endpoints: https://github.com/ovh/python-ovh#2-configure-your-application)
	application_key='xxxxxxxxxx',    # Application Key
	application_secret='xxxxxxxxxx', # Application Secret
	consumer_key='xxxxxxxxxx',       # Consumer Key
)

result = client.get("/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries/{queryPid}")

# Pretty print
print(json.dumps(result, indent=4))
```

```php
<?php
/**
 * First, download the latest release of PHP wrapper on github
 * And include this script into the folder with extracted files
 */
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;

/**
 * Instantiate an OVH Client.
 * You can generate new credentials with full access to your account on
 * the token creation page (https://api.ovh.com/createToken/index.cgi?GET=/*&PUT=/*&POST=/*&DELETE=/*)
 */
$ovh = new Api('xxxxxxxxxx',  // Application Key
               'xxxxxxxxxx',  // Application Secret
               'ovh-eu',      // Endpoint of API OVH (List of available endpoints: https://github.com/ovh/python-ovh#2-configure-your-application)
               'xxxxxxxxxx'); // Consumer Key

$result = $ovh->get("/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries/{queryPid}");

print_r($result);
?>
```

## Cancel a running query

`POST /v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries/{queryPid}/cancel`

Link: https://developers.eu.ovhcloud.com/reference/public-cloud/databases/mysql/queries/#post-publiccloud-project-projectid-manageddatabase-mysql-serviceid-currentqueries-querypid-cancel

**Status:** Beta version  
**IAM actions:** `publicCloudProject:apiovh:database/mysql/currentQueries/cancel`

Cancels a running query gracefully. Set terminate to true to force its termination instead.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `projectId` | path | string | yes | Project ID |
| `queryPid` | path | integer | yes | Query pid |
| `serviceId` | path | string (uuid) | yes | Service ID |

### Request body (required)

Type: `publicCloud.database.QueryCancelRequest`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `terminate` | boolean |  | Whether to forcefully terminate the query instead of gracefully canceling it |

```json
{
  "terminate": true
}
```

### Responses

| Status | Type | Description |
| --- | --- | --- |
| 200 | publicCloud.database.QueryCancelResult | successful operation |

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `success` | boolean | read-only | Whether the query was successfully canceled |

```json
{
  "success": true
}
```

### Example

```bash
curl -X POST \
  "https://api.eu.ovhcloud.com/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries/{queryPid}/cancel" \
  -H "accept: application/json" \
  -H "authorization: Bearer $OVH_TOKEN" \
  -H "content-type: application/json" \
  -d '{ }'
```

```python
'''
First, install the latest release of Python wrapper: $ pip install ovh
'''
import json
import ovh

# Instantiate an OVH Client.
# You can generate new credentials with full access to your account on
# the token creation page (https://api.ovh.com/createToken/index.cgi?GET=/*&PUT=/*&POST=/*&DELETE=/*)
client = ovh.Client(
	endpoint='ovh-eu',               # Endpoint of API OVH (List of available endpoints: https://github.com/ovh/python-ovh#2-configure-your-application)
	application_key='xxxxxxxxxx',    # Application Key
	application_secret='xxxxxxxxxx', # Application Secret
	consumer_key='xxxxxxxxxx',       # Consumer Key
)

# Request body type: publicCloud.database.QueryCancelRequest
result = client.post("/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries/{queryPid}/cancel",
	terminate = None, # Whether to forcefully terminate the query instead of gracefully canceling it (type: boolean, nullable)
)

# Pretty print
print(json.dumps(result, indent=4))
```

```php
<?php
/**
 * First, download the latest release of PHP wrapper on github
 * And include this script into the folder with extracted files
 */
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;

/**
 * Instantiate an OVH Client.
 * You can generate new credentials with full access to your account on
 * the token creation page (https://api.ovh.com/createToken/index.cgi?GET=/*&PUT=/*&POST=/*&DELETE=/*)
 */
$ovh = new Api('xxxxxxxxxx',  // Application Key
               'xxxxxxxxxx',  // Application Secret
               'ovh-eu',      // Endpoint of API OVH (List of available endpoints: https://github.com/ovh/python-ovh#2-configure-your-application)
               'xxxxxxxxxx'); // Consumer Key

// Request body type: publicCloud.database.QueryCancelRequest
$result = $ovh->post("/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/currentQueries/{queryPid}/cancel", array(
	terminate => null, // Whether to forcefully terminate the query instead of gracefully canceling it (type: boolean, nullable)
));

print_r($result);
?>
```

## List query statistics

`GET /v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/queryStatistics`

Link: https://developers.eu.ovhcloud.com/reference/public-cloud/databases/mysql/queries/#get-publiccloud-project-projectid-manageddatabase-mysql-serviceid-querystatistics

**Status:** Beta version  
**IAM actions:** `publicCloudProject:apiovh:database/mysql/queryStatistics/get`

Returns execution statistics for each query pattern: number of calls, rows and execution times.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `X-Pagination-Cursor` | header | string |  | Pagination cursor |
| `X-Pagination-Size` | header | integer |  | Pagination size |
| `limit` | query | integer |  | Maximum number of entries to return |
| `offset` | query | integer |  | Number of entries to skip before returning results |
| `projectId` | path | string | yes | Project ID |
| `serviceId` | path | string (uuid) | yes | Service ID |

### Responses

| Status | Type | Description |
| --- | --- | --- |
| 200 | publicCloud.database.QueryStatistic[] | successful operation |

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `calls` | integer | read-only | Number of times this query pattern has been executed |
| `databaseName` | string | read-only | Name of the database |
| `digest` | string | read-only | Digest hash of the normalized query |
| `firstSeen` | string (date-time) | read-only | Timestamp of the first execution |
| `lastSeen` | string (date-time) | read-only | Timestamp of the most recent execution |
| `maxTime` | number | read-only | Maximum execution time in milliseconds |
| `meanTime` | number | read-only | Mean execution time in milliseconds |
| `minTime` | number | read-only | Minimum execution time in milliseconds |
| `query` | string | read-only | Representative SQL text of the query pattern |
| `rows` | integer | read-only | Total number of rows retrieved or affected |
| `totalTime` | number | read-only | Total cumulative execution time in milliseconds |
| `username` | string | read-only | Name of the user who executed the query |

```json
[
  {
    "calls": 0,
    "databaseName": "string",
    "digest": "string",
    "firstSeen": "2024-01-01T12:00:00Z",
    "lastSeen": "2024-01-01T12:00:00Z",
    "maxTime": 0,
    "meanTime": 0,
    "minTime": 0,
    "query": "string",
    "rows": 0,
    "totalTime": 0,
    "username": "string"
  }
]
```

### Example

```bash
curl -X GET \
  "https://api.eu.ovhcloud.com/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/queryStatistics" \
  -H "accept: application/json" \
  -H "authorization: Bearer $OVH_TOKEN"
```

```python
'''
First, install the latest release of Python wrapper: $ pip install ovh
'''
import json
import ovh

# Instantiate an OVH Client.
# You can generate new credentials with full access to your account on
# the token creation page (https://api.ovh.com/createToken/index.cgi?GET=/*&PUT=/*&POST=/*&DELETE=/*)
client = ovh.Client(
	endpoint='ovh-eu',               # Endpoint of API OVH (List of available endpoints: https://github.com/ovh/python-ovh#2-configure-your-application)
	application_key='xxxxxxxxxx',    # Application Key
	application_secret='xxxxxxxxxx', # Application Secret
	consumer_key='xxxxxxxxxx',       # Consumer Key
)

result = client.get("/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/queryStatistics")

# Pretty print
print(json.dumps(result, indent=4))
```

```php
<?php
/**
 * First, download the latest release of PHP wrapper on github
 * And include this script into the folder with extracted files
 */
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;

/**
 * Instantiate an OVH Client.
 * You can generate new credentials with full access to your account on
 * the token creation page (https://api.ovh.com/createToken/index.cgi?GET=/*&PUT=/*&POST=/*&DELETE=/*)
 */
$ovh = new Api('xxxxxxxxxx',  // Application Key
               'xxxxxxxxxx',  // Application Secret
               'ovh-eu',      // Endpoint of API OVH (List of available endpoints: https://github.com/ovh/python-ovh#2-configure-your-application)
               'xxxxxxxxxx'); // Consumer Key

$result = $ovh->get("/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/queryStatistics");

print_r($result);
?>
```

## Reset query statistics

`POST /v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/queryStatistics/reset`

Link: https://developers.eu.ovhcloud.com/reference/public-cloud/databases/mysql/queries/#post-publiccloud-project-projectid-manageddatabase-mysql-serviceid-querystatistics-reset

**Status:** Beta version  
**IAM actions:** `publicCloudProject:apiovh:database/mysql/queryStatistics/reset`

Resets all aggregated query statistics of the service.

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `projectId` | path | string | yes | Project ID |
| `serviceId` | path | string (uuid) | yes | Service ID |

### Responses

| Status | Type | Description |
| --- | --- | --- |
| 200 | — | successful operation |

### Example

```bash
curl -X POST \
  "https://api.eu.ovhcloud.com/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/queryStatistics/reset" \
  -H "accept: application/json" \
  -H "authorization: Bearer $OVH_TOKEN"
```

```python
'''
First, install the latest release of Python wrapper: $ pip install ovh
'''
import json
import ovh

# Instantiate an OVH Client.
# You can generate new credentials with full access to your account on
# the token creation page (https://api.ovh.com/createToken/index.cgi?GET=/*&PUT=/*&POST=/*&DELETE=/*)
client = ovh.Client(
	endpoint='ovh-eu',               # Endpoint of API OVH (List of available endpoints: https://github.com/ovh/python-ovh#2-configure-your-application)
	application_key='xxxxxxxxxx',    # Application Key
	application_secret='xxxxxxxxxx', # Application Secret
	consumer_key='xxxxxxxxxx',       # Consumer Key
)

result = client.post("/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/queryStatistics/reset")

# Pretty print
print(json.dumps(result, indent=4))
```

```php
<?php
/**
 * First, download the latest release of PHP wrapper on github
 * And include this script into the folder with extracted files
 */
require __DIR__ . '/vendor/autoload.php';
use \Ovh\Api;

/**
 * Instantiate an OVH Client.
 * You can generate new credentials with full access to your account on
 * the token creation page (https://api.ovh.com/createToken/index.cgi?GET=/*&PUT=/*&POST=/*&DELETE=/*)
 */
$ovh = new Api('xxxxxxxxxx',  // Application Key
               'xxxxxxxxxx',  // Application Secret
               'ovh-eu',      // Endpoint of API OVH (List of available endpoints: https://github.com/ovh/python-ovh#2-configure-your-application)
               'xxxxxxxxxx'); // Consumer Key

$result = $ovh->post("/v2/publicCloud/project/{projectId}/managedDatabase/mysql/{serviceId}/queryStatistics/reset");

print_r($result);
?>
```
