Understanding the sys.version_major() Function in MySQL

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

Syntax

The syntax goes like this:

sys.version_major()

So, no arguments are required or accepted.

Example

Here’s an example to demonstrate:

SELECT sys.version_major();

Result:

+---------------------+
| sys.version_major() |
+---------------------+
|                   8 |
+---------------------+

In this case, I’m using MySQL version 8.0.29, so the sys.version_major() function returns 8, because that’s the major release part of the version.

The return value is a TINYINT UNSIGNED value.

Get the Full Version

MySQL also has a sys.version_minor() function that returns the minor release version, and a sys.version_patch() function that returns the patch 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.