What command returns the current version of a MySQL database?
This question is related to
mysql
Many answers suggest to use mysql --version
. But the mysql
programm is the client. The server is mysqld
. So the command should be
mysqld --version
or
mysqld --help
That works for me on Debian and Windows.
When connected to a MySQL server with a client you can use
select version()
or
select @@version
Try this function -
SELECT VERSION();
-> '5.7.22-standard'
Or for more details use :
SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------------------+
| protocol_version | 10 |
| version | 5.0.27-standard |
| version_comment | MySQL Community Edition - Standard (GPL) |
| version_compile_machine | i686 |
| version_compile_os | pc-linux-gnu |
+-------------------------+------------------------------------------+
5 rows in set (0.04 sec)
MySQL 5.0 Reference Manual (pdf) - Determining Your Current MySQL Version - page 42
Simply login to the Mysql with
mysql -u root -p
Then type in this command
select @@version;
This will give the result as,
+-------------------------+
| @@version |
+-------------------------+
| 5.7.16-0ubuntu0.16.04.1 |
+-------------------------+
1 row in set (0.00 sec)
From the console you can try:
mysqladmin version -u USER -p PASSWD
You can also look at the top of the MySQL shell when you first log in. It actually shows the version right there.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 67971
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Use mysql -V
works fine for me on Ubuntu.
I found a easy way to get that.
Example: Unix command(this way you don't need 2 commands.),
$ mysql -u root -p -e 'SHOW VARIABLES LIKE "%version%";'
Sample outputs:
+-------------------------+-------------------------+
| Variable_name | Value |
+-------------------------+-------------------------+
| innodb_version | 5.5.49 |
| protocol_version | 10 |
| slave_type_conversions | |
| version | 5.5.49-0ubuntu0.14.04.1 |
| version_comment | (Ubuntu) |
| version_compile_machine | x86_64 |
| version_compile_os | debian-linux-gnu |
+-------------------------+-------------------------+
In above case mysql version is 5.5.49.
Please find this useful reference.
Here two more methods:
Linux: Mysql view version: from PHP
From a PHP function, we can see the version used:
mysql_get_server_info ([resource $ link_identifier = NULL]): string
Linux: Mysql view version: Package version
For RedHat / CentOS operating systems:
rpm -qa | grep mysql
For Debian / Ubuntu operating systems:
rpm -qa | grep mysql
Extracted from: https://www.sysadmit.com/2019/03/linux-mysql-ver-version.html
Only this code works for me
/usr/local/mysql/bin/mysql -V
For Mac,
login to mysql server.
execute the following command:
SHOW VARIABLES LIKE "%version%";
For UBUNTU you can try the following command to check mysql version :
mysql --version
try
mysql --version
for instance. Or dpkg -l 'mysql-server*'
.
E:\>mysql -u root -p
Enter password: *******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1026
Server version: 5.6.34-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select @@version;
+------------+
| @@version |
+------------+
| 5.6.34-log |
+------------+
1 row in set (0.00 sec)
mysqladmin version
OR mysqladmin -V
SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------------------+
| protocol_version | 10 |
| version | 5.0.27-standard |
| version_comment | MySQL Community Edition - Standard (GPL) |
| version_compile_machine | i686 |
| version_compile_os | pc-linux-gnu |
+-------------------------+------------------------------------------+
5 rows in set (0.04 sec)
MySQL 5.0 Reference Manual (pdf) - Determining Your Current MySQL Version - page 42
With CLI in one line :
mysql --user=root --password=pass --host=localhost db_name --execute='select version()';
or
mysql -uroot -ppass -hlocalhost db_name -e 'select version()';
return something like this :
+-----------+
| version() |
+-----------+
| 5.6.34 |
+-----------+
In windows ,open Command Prompt and type MySQL -V
or MySQL --version
. If you use Linux get terminal and type MySQL -v
Source: Stackoverflow.com