How to Check MySQL Version in Ubuntu

Each version of MySQL adds new features to the database and some old features, and queries will be either removed or deprecated. So when you connect an application, it is important to determine the current MySQL version to make sure that your application is compatible with the database.

There are a couple of ways we can check mysql version in Ubuntu, the easiest and quickest method is to run the mysqladmin command from the terminal with version option:

sudo mysqladmin version

the output will be as follows:

Server version		5.7.24-0ubuntu0.18.04.1
Protocol version	10
Connection		Localhost via UNIX socket
UNIX socket		/var/run/mysqld/mysqld.sock
Uptime:			1 min 7 sec

The Server version number can be read as minor release number 7.23 of the major version 5.

Alternatively, you can log in to the MySQL Console:

sudo mysql

To get the server version, run the SELECT VERSION() statement:

SELECT VERSION();

The output will be the Mysql version on your Ubuntu server as seen in the following screenshot:

check mysql version ubuntu

Linux Shell Script

Now lets create a Linux shell script that output Ubuntu MySQL version. First, create a file called check_version.sh.

#!/bin/bash

MYSQL_VERSION=$(mysql -e "SELECT VERSION()" -sN)
echo $MYSQL_VERSION

Make the program executable, then execute with root privileges:

chmod +x check_version.sh
sudo ./check_version.sh

The output will be:

5.7.23-0ubuntu0.18.04.1

Note that MySQL root user on Ubuntu 18.04 does not have password by default, if you have set root password, then you should provide the password with -p option.

mysql -u root -p'123456'

This is also the case with mysqladmin command.