> For the complete documentation index, see [llms.txt](https://mariadb.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mariadb.com/docs/server/reference/clientserver-protocol/2-text-protocol/com_query.md).

# COM\_QUERY

With the `COM_QUERY` command, the client sends the server an SQL statement to be executed immediately.

## Fields

* [int<1>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#fixed-length-integers) `0x03` : `COM_QUERY` header.
* [string\<EOF>](/docs/server/reference/clientserver-protocol/protocol-data-types.md#end-of-file-length-strings) SQL statement.

The SQL statement should be properly escaped. The escape character is usually a backslash (`\`) = `0x5c`. However, if the status flag returned by the last [OK Packet](/docs/server/reference/clientserver-protocol/4-server-response-packets/ok_packet.md#status-flag) had the `NO_BACKSLASH_ESCAPES` bit set, the escape character is a single quote (`'` = `0x60`).

If the escape character is a backslash, the following characters are escaped:

* Single quote (`'` = `0x60`).
* Backslash (`\` = `0x5c`).
* Double quote (`"` = `0x22`).
* Null character (`0x00`).

If the escape character is a single quote, only the single quote (`'` = `0x60`) can be escaped.

## Response

The server can answer with 4 different responses that can be differentiated by the first byte (packet header):

* `0xFF` - [ERR\_Packet](/docs/server/reference/clientserver-protocol/4-server-response-packets/err_packet.md) if any error occurs.
* `0x00` - [OK\_Packet](/docs/server/reference/clientserver-protocol/4-server-response-packets/ok_packet.md) when query execution works without result set.
* `0xFB` - [LOCAL\_INFILE Packet](/docs/server/reference/clientserver-protocol/4-server-response-packets/packet_local_infile.md) if the query was `LOCAL INFILE ...`.
* Or a [result set](/docs/server/reference/clientserver-protocol/4-server-response-packets/result-set-packets.md), when the query returns results (in case of a `SELECT` query, for example).

### Example

|                                                 |                 |
| ----------------------------------------------- | --------------- |
| 1b 00 00 00 03 44 52 4f 50 20 54 41 42 4c 45 20 | .....DROP TABLE |
| 49 46 20 45 58 49 53 54 53 20 62 75 6c 6b 31    | IF EXISTS bulk1 |

<sub>*This page is licensed: CC BY-SA / Gnu FDL*</sub>

{% @marketo/form formId="4316" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://mariadb.com/docs/server/reference/clientserver-protocol/2-text-protocol/com_query.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
