> 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/connectors/mariadb-connector-c/api-functions/mysql_init.md).

# mysql\_init

## Syntax

```c
MYSQL * mysql_init(MYSQL * mysql);
```

## Parameter

* `mysql` - a pointer to `MYSQL` or `NULL`. In case of passing a `NULL` pointer mysql\_init() will allocate memory and return a pointer to a MYSQL structure.

## Description

Prepares and initializes a MYSQL structure to be used with [mysql\_real\_connect()](/docs/connectors/mariadb-connector-c/api-functions/mysql_real_connect.md).

If `mysql_thread_init()` was not called before, `mysql_init()` will also initialize the thread subsystem for the current thread.

## Return Value

The `mysql_init()` function returns an address of a `MYSQL` structure, or NULL in case of memory allocation error.

{% hint style="info" %}
Members of the MYSQL structure are not intended for application use.

Any subsequent calls to any mysql function (except mysql\_options()) will fail until [mysql\_real\_connect()](/docs/connectors/mariadb-connector-c/api-functions/mysql_real_connect.md) was called.

Memory allocated by mysql\_init() must be freed with [mysql\_close()](/docs/connectors/mariadb-connector-c/api-functions/mysql_close.md).
{% endhint %}

## See Also

* [mysql\_real\_connect()](/docs/connectors/mariadb-connector-c/api-functions/mysql_real_connect.md)
* [mysql\_options()](/docs/connectors/mariadb-connector-c/api-functions/mysql_options.md)
* [mysql\_thread\_init()](/docs/connectors/mariadb-connector-c/api-functions/mysql_thread_init.md)
* [mysql\_close()](/docs/connectors/mariadb-connector-c/api-functions/mysql_close.md)

{% @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:

```
GET https://mariadb.com/docs/connectors/mariadb-connector-c/api-functions/mysql_init.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
