How to check the version of MySQL

MySQL and MariaDB alternatives is the most popular open source relational database management systems. There are some important differences between MySQL version, so in some cases, to know the version running on the server may be important.

For example, if you want to install the application requires a specific version of MySQL, you need to determine the MySQL server version before the installation begins.

In this article, we will show you how to check the version installed on your system MySQL or MariaDB server.

Using the command line version to view

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

MySQL server binary file named mysqld. To get the server version, use the --version or -V option to run binaries:

mysqld --version

This command will output about MySQL version. In this example, the MySQL server version is 5.7.27:

mysqld  Ver 5.7.27-00.18.04.1 for Linux on x86_64 ((Ubuntu))

If the MySQL server requires authentication, you need to use sudo mysql or mysql -u username -p.

mysqladmin is a client utility for performing management operations on the MySQL server. It can also be used to query MySQL version:

mysqladmin -V

Output on a slightly different order:

mysqladmin  Ver 8.42 Distrib 5.7.27, for Linux on x86_64

View the MySQL client version

Utility command mysql client can also be used to determine the MySQL server version.

To connect to the MySQL server, simply type mysql:

mysql

After connecting to the MySQL shell, this 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)

For information about MySQL version and other components, please consult 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 other statements and commands to display server version. SELECT VERSION () statement will only display the MySQL version.

SELECT VERSION();

STATUS command will display information about server and MySQL version states:

STATUS;

View version using PHP

Like MySQL client PhpMyAdmin, you can use PHP MySQL server version to determine if you are on a shared host and can not access the command line or access.

In the document root of your site using FTP or SFTP client to upload the PHP file. Sure to change my_user and actual use of MySQL user account: my_password value

File: 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 a browser, MySQL server version will be displayed on the screen:

5.7.27-0ubuntu0.18.04.1

in conclusion

Determine the MySQL server version is a relatively easy task. In this guide, we show several different ways on how to find MySQL version running on the system.

If you have any questions, please leave a message below.

Guess you like

Origin www.linuxidc.com/Linux/2019-08/159845.htm