check mysql version

How to Check MySQL Version in Ubuntu

MySQL is a popular database system used by many organizations and developers around the world. Every MySQL version offers new features and improvements over the previous versions. It also deprecates some of the functions and features. In some cases, the syntax of certain commands may also change from one version to another. So it is important to keep track of the MySQL version you are using to be able to make most of it. In this article, we will learn how to check MySQL version in Ubuntu.


How to Check MySQL Version in Ubuntu

There are two ways to check MySQL version in Ubuntu – from outside and inside MySQL shell. We will look at both these approaches.


1. Using -v option

From terminal (in Linux/Mac) or command prompt (in Windows), you can simply call MySQL command with a -v option to get its version number.

$ mysql -V
mysql  Ver 14.14 Distrib 5.7.36, for Linux (x86_64) using  EditLine wrapper

Please remember to use capital V in the above command. The above command can be used in Linux, Windows & Mac. It works for MySQL as well as Mariadb.

If you want to find and use the MySQL version number from within your shell script, then use this method. Sometimes you may want to execute commands conditionally, depending on MySQL version. In such cases, you can run the above command.


2. Using MySQL Shell

There are several ways to find out MySQL version from within its shell. Every time you log into MySQL shell, it will display the version information at the top for your reference.

$ sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11079
Server version: 5.7.36-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

You may also use SHOW VARIABLES command for this purpose as shown below.

mysql> SHOW VARIABLES LIKE '%version%';
+-------------------------+-------------------------+
| Variable_name           | Value                   |
+-------------------------+-------------------------+
| innodb_version          | 5.7.36                  |
| protocol_version        | 10                      |
| slave_type_conversions  |                         |
| tls_version             | TLSv1,TLSv1.1,TLSv1.2   |
| version                 | 5.7.36-0ubuntu0.18.04.1 |
| version_comment         | (Ubuntu)                |
| version_compile_machine | x86_64                  |
| version_compile_os      | Linux                   |
+-------------------------+-------------------------+

The above command will show several lines of output. Among them, the row with variable_name=’version’ will display MySQL version.

Alternatively, you may also use the following command to get MySQL version.

mysql> select version();
+-------------------------+
| version()               |
+-------------------------+
| 5.7.36-0ubuntu0.18.04.1 |
+-------------------------+

If you want to run specific queries of stored procedures, depending on the MySQL version, then you can use the above command.

You can also use the STATUS command to get the same information.

mysql> status;
--------------
mysql  Ver 14.14 Distrib 5.7.36, for Linux (x86_64) using  EditLine wrapper

Connection id:          11114
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.7.36-0ubuntu0.18.04.1 (Ubuntu)
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /var/run/mysqld/mysqld.sock
Uptime:                 21 hours 30 min 45 sec

Threads: 1  Questions: 839780  Slow queries: 0  Opens: 354  Flush tables: 1  Ope                                                                                        n tables: 347  Queries per second avg: 10.843
--------------

In this article, we have learnt several ways to get MySQL version in Ubuntu. You can use the same commands in any Linux version.

Also read:

How to Clear Temp Files in Ubuntu
Git Pull vs Fetch
How to Kill User Session in Linux
Git Tags vs Branches
How to Sleep Function in Python

Leave a Reply

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