# mysql\_init

## Syntax

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

`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()](https://mariadb.com/docs/connectors/mariadb-connector-c/api-functions/mysql_real_connect).

If mysql\_thread\_init() was not called before, mysql\_init() will also initialize the thread subsystem for the current thread.

{% 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()](https://mariadb.com/docs/connectors/mariadb-connector-c/api-functions/mysql_real_connect) was called.

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

## See also

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

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


---

# Agent Instructions: 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.
