How to Check the MySQL Version

Published on

3 min read

Check MySQL Version

MySQL (and its drop-in replacement MariaDB) is the most popular open-source relational database management system. There are some important differences between MySQL versions, so knowing which version is running on your server might be important in some situations.

For example, if you are installing an application that requires a specific MySQL version before starting with the installation you’ll need to find out the version of your MySQL server.

In this article, we’ll show you how to check the version of the MySQL or MariaDB server that is installed on your system.

From the Command Line

If you have SSH access to the server, there are several different commands that can help you determine the version of your MySQL.

The MySQL server binary is named mysqld. To get the server version run the binary using the --version or -V option:

mysqld --version

The command will output information about the MySQL version and exit. In this example the version of the MySQL server is 5.7.27:

mysqld  Ver 5.7.27-0ubuntu0.18.04.1 for Linux on x86_64 ((Ubuntu))

mysqladmin is a client utility that is used to perform administrative operations on the MySQL servers. It can be also used to query the MySQL version:

mysqladmin -V

The output will be slightly different from the previous command:

mysqladmin  Ver 8.42 Distrib 5.7.27, for Linux on x86_64

From the MySQL Shell

A command client utility such as mysql, can also be used to determine the version of the MySQL server.

To connect to the MySQL server simply type mysql:

mysql

Once connected to the MySQL shell, the version will be printed on the screen:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.27-0ubuntu0.18.04.1 (Ubuntu)

To get the information about the MySQL version and other components, query the version variables:

SHOW VARIABLES LIKE "%version%";
+-------------------------+-------------------------+
| Variable_name           | Value                   |
+-------------------------+-------------------------+
| innodb_version          | 5.7.27                  |
| protocol_version        | 10                      |
| slave_type_conversions  |                         |
| tls_version             | TLSv1,TLSv1.1           |
| version                 | 5.7.27-0ubuntu0.18.04.1 |
| version_comment         | (Ubuntu)                |
| version_compile_machine | x86_64                  |
| version_compile_os      | Linux                   |
+-------------------------+-------------------------+
8 rows in set (0.02 sec)

There are also some other statements and commands that can show you the server version. SELECT VERSION() statement will display only the MySQL version.

SELECT VERSION();

The STATUS command shows the MySQL version as well as the information about the server status:

STATUS;

Using PHP

If you are on a shared hosting and you don’t have access to the command line or to a MySQL client like PhpMyAdmin, you can determine the version of the MySQL server using PHP.

In your website document root directory upload the following PHP file using a FTP or SFTP client. Make sure you change the my_user and my_password with an actual MySQL user account :

mysql-version.php
<?php

// Create a database connection.
$link = mysqli_connect("localhost", "my_user", "my_password");

// Print the MySQL version.
echo mysqli_get_server_info($link);

// Close the connection.
mysqli_close($link);

Open the file in your browser and the version of the MySQL server will be displayed on your screen:

5.7.27-0ubuntu0.18.04.1

Conclusion

Determining the version of the MySQL server is a relatively easy task. In this guide, we have shown several different options about how to find the MySQL version running on your system.

Feel free to leave a comment if you have any questions.