How to Show the MySQL Version

Summary: in this tutorial, you will learn how to show the MySQL version of the server you’re using.

Showing MySQL version using the version system variable

When working with MySQL, it’s important to know the version of the server that you’re using. The @@version variable provides you with a quick and easy way to obtain this information.

Step 1. Connect to MySQL Server

Let’s start by connecting to your MySQL server using the command-line client or GUI tool like MySQL Workbench.

If you use a command-line client like mysql program, you can use the following command to connect to the MySQL server:

mysql -u your_username -pCode language: SQL (Structured Query Language) (sql)

You need to replace your_username with your MySQL username and enter your password when prompted.

Step 2: Use @@version to Show MySQL Version

Once connected, you can execute the following SQL query to display the MySQL version:

SELECT @@version AS 'MySQL Version';Code language: SQL (Structured Query Language) (sql)

This query provides a concise output containing your MySQL server version, including version number and additional details. For example:

+---------------+
| MySQL Version |
+---------------+
| 8.0.34        |
+---------------+
1 row in set (0.00 sec)Code language: SQL (Structured Query Language) (sql)

Showing MySQL version using mysql

Another way to show the MySQL version is to use the mysql command line with the –version option.

First, open the Command Prompt on Windows or Terminal on macOS and Linux.

Second, use the mysql command with the -V option

mysql -VCode language: SQL (Structured Query Language) (sql)

It’ll return the MySQL version of the server:

C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe  Ver 8.0.34 for Win64 on x86_64 (MySQL Community Server - GPL)Code language: SQL (Structured Query Language) (sql)

Getting the MySQL version using the version() function

If you want to use the version of MySQL in a query, you can use the version() function.

The following statement uses the version() function to get the version of the MySQL server:

SELECT version();Code language: SQL (Structured Query Language) (sql)

Output:

+-----------+
| version() |
+-----------+
| 8.0.34    |
+-----------+
1 row in set (0.00 sec)Code language: SQL (Structured Query Language) (sql)

For example, you can use the version() function with the CONCAT_WS() function:

SELECT 
  CONCAT(
    'MySQL', 
    ' ', 
    VERSION()
  ) version;Code language: SQL (Structured Query Language) (sql)

Output:

+--------------+
| version      |
+--------------+
| MySQL 8.0.34 |
+--------------+
1 row in set (0.00 sec)Code language: SQL (Structured Query Language) (sql)

Summary

  • Use the @@version system variable or mysql --version command to show the MySQL version of the server.
Was this tutorial helpful?