How To Check your MySQL (Or MariaDB) Version [Easy]

Check MySQL Version

Knowing which version of MySQL you are running is vital when making sure your code is compatible and that you are using supported features. Here’s how to find out which you are running.

For example, older versions of MySQL lack features for handling JSON data and modern character sets (including emojis!), so targeting the right MySQL version or making sure your MySQL version is up to date is pretty important if you want to support these popular functions!

MariaDB is a drop-in replacement for MySQL, so the same syntax will work.

Checking MySQL Version From the Command Line

From the Linux Shell, run:

mysqld --version

or;

mysqld -V

Which will output the version information for the currently installed version of MySQL, something like:

/usr/sbin/mysqld  Ver 8.0.22-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))

Checking the MySql Client Version

You can do the same for the MySQL client program:

mysql --version

or:

mysql -V

Which will output something like:

mysql  Ver 8.0.22-0ubuntu0.20.04.3 for Linux on x86_64 ((Ubuntu))

Checking Version From within MySQL/MariaDB

When you connect to a server, the version should be displayed like so:

Server version: 8.0.22-0ubuntu0.20.04.3 (Ubuntu)

If logged in as root, you can also run:

SHOW VARIABLES LIKE "%version%";

which will output:

+--------------------------+-------------------------------+
| Variable_name            | Value                         |
+--------------------------+-------------------------------+
| admin_tls_version        | TLSv1,TLSv1.1,TLSv1.2,TLSv1.3 |
| immediate_server_version | 999999                        |
| innodb_version           | 8.0.22                        |
| original_server_version  | 999999                        |
| protocol_version         | 10                            |
| slave_type_conversions   |                               |
| tls_version              | TLSv1,TLSv1.1,TLSv1.2,TLSv1.3 |
| version                  | 8.0.22-0ubuntu0.20.04.3       |
| version_comment          | (Ubuntu)                      |
| version_compile_machine  | x86_64                        |
| version_compile_os       | Linux                         |
| version_compile_zlib     | 1.2.11                        |
+--------------------------+-------------------------------+
12 rows in set (0.00 sec)

Checking From PHPMyAdmin

PHPMyAdmin is a popular web-based MySQL administration console, written in PHP, unsurprisingly.

The version of the currently-connected MySQL server is visible under the Database server banner to the right of the screen when you log in – labeled as “Server version.”

Checking MySQL Version From PHP

You can also get the MySQL server version in PHP and output it to a web page with the following code:

// Create a database connection
$db = mysqli_connect("localhost", "username", "password");

// Output the MySQL version
echo mysqli_get_server_info($db);

// Close connection
mysqli_close($db);

Note you’ll have the mysqli PHP extension installed and enabled.

When hosted in Apache or Nginx and accessed with a web browser, the following will be displayed:

8.0.22-0ubuntu0.20.04.3  

Click here for more database tutorials!

 

SHARE:
nv-author-image

Brad Morton

I'm Brad, and I'm nearing 20 years of experience with Linux. I've worked in just about every IT role there is before taking the leap into software development. Currently, I'm building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I'm up to.

Leave a Reply

Your email address will not be published. Required fields are marked *