Understanding the sys.version_patch() Function in MySQL

In MySQL, we can use the sys.version_patch() function to return the patch release version of the MySQL server.

For example, if we’re using MySQL 8.0.33, sys.version_patch() returns 33.

Syntax

The syntax goes like this:

sys.version_patch()

So, no arguments are required or accepted.

Example

Here’s an example to demonstrate:

SELECT sys.version_patch();

Result:

+---------------------+
| sys.version_patch() |
+---------------------+
|                  29 |
+---------------------+

In this case, I’m using MySQL version 8.0.29, so the sys.version_patch() function returns 29, because that’s the patch part of the version.

The return value is a TINYINT UNSIGNED value.

Get the Full Version

MySQL also has a sys.version_major() function that returns the major release version, and a sys.version_minor() function that returns the minor version.

There’s also a version() function that gets the whole thing.

Here’s an example of using all of the above functions for getting the full version and also the various parts of the version:

SELECT 
    version() full_version,
    sys.version_major() AS major, 
    sys.version_minor() AS minor,
    sys.version_patch() AS patch;

Result:

+--------------+-------+-------+-------+
| full_version | major | minor | patch |
+--------------+-------+-------+-------+
| 8.0.29       |     8 |     0 |    29 |
+--------------+-------+-------+-------+

Also see 7 Ways to Check your MySQL Version for more ways to return your MySQL version.