2012-01-24 42 views

回答

359

試試這個功能 -

SELECT VERSION(); 
-> '5.7.22-standard' 

VERSION()

或瞭解更多詳細信息,使用方法:

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

+1

http://dev.mysql.com/doc/refman/5.0/en/ installation-version.html是404. –

+0

如果我不想運行任何與mysql本身相關的東西,該怎麼辦?這個版本信息存儲在哪裏? – Sajuuk

136

嘗試

mysql --version 

例如。或者dpkg -l 'mysql-server*'

+1

這是最好的快速選項,如果你懶惰 - 你甚至不需要登錄':-D'在Centos/RHEL命令行以及Ubuntu上都可以正常工作。 – user568458

+6

@ user568458,不過,它會給你客戶端的版本或本地服務器的版本,只要作爲一個包安裝的那個版本正在運行;) –

+0

命令mysql -version不是操作系統特定的。這將適用於任何Linux發行版,Windows和OS X. –

8
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

6

從控制檯,您可以嘗試:

mysqladmin version -u USER -p PASSWD 
13

對於UBUNTU你可以試試下面的命令來檢查MySQL的版本:

mysql --version 
+5

這與@MichaelKrelin的回答是一樣的! – dani24

7
shell> mysql --version 

shell> mysql -V 
2

登錄到你的MySQL,複製並粘貼此:

SHOW VARIABLES LIKE "%version%"; 

輸出示例:

mysql> SHOW VARIABLES LIKE "%version%"; 
+-------------------------+---------------------+ 
| Variable_name   | Value    | 
+-------------------------+---------------------+ 
| protocol_version  | 10     | 
| version     | 5.1.73    | 
| version_comment   | Source distribution | 
| version_compile_machine | i386    | 
| version_compile_os  | redhat-linux-gnu | 
+-------------------------+---------------------+ 
5 rows in set (0.00 sec) 
9

mysqladmin version OR mysqladmin -V

13

使用mysql -V在Ubuntu上爲我工作得很好。

11

我找到了一個簡單的方法來得到它。

實施例:Unix命令(這樣就不需要2個命令),

$ mysql -u root -p -e 'SHOW VARIABLES LIKE "%version%";' 

樣本輸出:

+-------------------------+-------------------------+ 
| 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  | 
+-------------------------+-------------------------+ 

在上述情況下,MySQL的版本49年5月5日

請發現this useful reference

1

在Ubuntu和其他linux varian,SELECT @@version上試過這個,並且工作得很好。

2

您也可以在第一次登錄時查看MySQL shell的頂部。它實際上顯示了當前的版本。

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> 
3

只需登錄到MySQL與

mysql -u root -p 

然後在一種類型的該命令中

select @@version; 

這會給該結果作爲,

+-------------------------+ 
| @@version    | 
+-------------------------+ 
| 5.7.16-0ubuntu0.16.04.1 | 
+-------------------------+ 
1 row in set (0.00 sec) 
2

隨着CLI行:

mysql --user=root --password=pass --host=localhost db_name --execute='select version()';

mysql -uroot -ppass -hlocalhost db_name -e 'select version()';

回報是這樣的:

+-----------+ 
| version() | 
+-----------+ 
| 5.6.34 | 
+-----------+ 
1
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) 
+0

您能否爲您的答案提供一些背景知識。雖然它清楚地表明瞭一種解決方案,但對於您的方法以及爲什麼它有一個好方法會有所幫助。通常只是發佈代碼塊在SO中被壓低。 –

+0

我不認爲需要任何解釋爲什麼'SELECT @@ version;',它顯示版本,將是一個很好的方法來顯示版本。國際海事組織的更大問題是,這個答案是以前答案的重複。 –

相關問題