I have installed countless
LAMP environments
over these years and the optimal configuration of the database is perhaps one of the finest jobs we face. Today we are going to deal with a very basic topic, but that the novel webmaster may need. This is how to
find out which version of MySQL or MariaDB is installed in the operating system
.
To solve this issue there are endless possibilities, but here we will collect the simplest. We will propose solutions that can be used from the terminal and others from the browser itself. This way, whether you have a VPS server or a shared hosting, you can find out the version of MySQL or MariaDB that you have installed.
How to get the version of MySQL or MariaDB installed in the system?
Let's start with the possibilities we have using the terminal. Once we have the terminal session open, just execute the
mysql --version
command and we will have the output on screen as follows:
zeokat@serverdeprueba:~$ mysql --version
mysql Ver 15.1 Distrib 10.1.34-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
Well, in this case we have MariaDB installed in
version 10.1.34
, that is, you have to pay attention to the number that appears after
«Distrib»
.
From the console we can also connect to the MySQL or MariaDB server as explained in
this tutorial
. Basically, you have to execute the
mysql -u'USUARIO' -p'CONTRASEÑA'
and
the server version usually appears in the welcome message
. Even so, we can execute the
SELECT version();
query
SELECT version();
and it will show us the version of the MySQL server installed.
We can also execute the query
SHOW VARIABLES LIKE "%version%";
which gives us more information about the version. For example we can see the architecture of the server, the compilation operating system, etc.
Check the MySQL version installed in a shared hosting.
In general, shared hosting does not allow remote sessions to be opened by SSH, so we cannot use the terminal. In this case we have two options:
-
The first option is to
use an installed database manager
(for example, in cPanel, phpMyAdmin or Adminer is very common)
. For me it is the recommended and fastest option.
-
The second option is to
run our own PHP script to find out the version of MariaDB or MySQL installed
. It takes us a little longer, but it is equally effective.
If we are using the first option, we only have to access
phpMyAdmin
or
Adminer
and the information with the MySQL version already appears on the screen.
If we are going to use our own script, we will have to place it in the public folder (usually
public_html
) and with a
.php
extension. The content of the file would be:
<?php
//Editar los parametros USUARIO y CONTRASEÑA con los de nuestro servidor
$mysql = mysqli_connect('localhost', 'USUARIO', 'CONTRASEÑA');
//Intentamos conectarnos al servidor
if (mysqli_connect_errno()) {
printf("Conexion fallida: %s\n", mysqli_connect_error());
exit();
}
//Mostramos en pantalla la versión de lservidor MySQL o MariaDB
printf("Version del servidor MySQL: %s\n", mysqli_get_server_info($mysql));
//Cerramos la conexion
mysqli_close($mysql);
?>
Then we access this script through the browser and the browser version will be displayed. As you can see there are several ways to determine the version of the MySQL server, but each one that chooses the one that is easier for him.