> 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_ping.md).

# mysql\_ping

mysql\_ping checks whether a MariaDB server connection is still active and attempts an automatic reconnect if the connection has dropped and reconnect is enabled.

## Syntax

```c
int mysql_ping(MYSQL * mysql);
```

## Parameter

* `mysql` - a mysql handle, which was previously allocated by [mysql\_init()](/docs/connectors/mariadb-connector-c/api-functions/mysql_init.md) or [mysql\_real\_connect()](/docs/connectors/mariadb-connector-c/api-functions/mysql_real_connect.md).

## Description

Checks whether the connection to the server is working. If it has gone down, and global option reconnect is enabled an automatic reconnection is attempted.

This function can be used by clients that remain idle for a long while, to check whether the server has closed the connection and reconnect if necessary.

## Return Value

Returns zero on success, nonzero if an error occurred.

{% hint style="info" %}
If a reconnect occurred the `thread_id` will change. Also resources bundled to the connection (prepared statements, locks, temporary tables, ...) will be released.
{% endhint %}

## See Also

* [mysql\_options()](/docs/connectors/mariadb-connector-c/api-functions/mysql_options.md)
* [mysql\_kill()](/docs/connectors/mariadb-connector-c/api-functions/mysql_kill.md)

<sub>*This page is: Copyright © 2026 MariaDB. All rights reserved.*</sub>

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