由於各個 MySQL 的版本都略有不同,而且又有 MaridDB 或 Percona 等分支版本, 很多時系統管理員都需要查詢系統內的 MySQL 版本,要查詢系統內的 MySQL 版本,以下列出幾種查詢 MySQL 版本的方法。
CLI
在 CLI 查詢 MySQL 版本十分簡單,用 mysql 指令便可以, 而且不用登入 MySQL:
$ mysql -V
執行後會輸出 MySQL 的版本, 以下是在 CentOS 用 yum 安裝 MariaDB 版本例子:
mysql Ver 15.1 Distrib 5.5.52-MariaDB, for Linux (x86_64) using readline 5.1
除了用 mysql 指令外,如果 MySQL 是用系統的套件管理工具安裝,也可以用套件管理工具查詢, 但這個方法的缺點是, 必須要知道 MySQL 版本的分支, 例如是 MySQL, MariaDB 或 Percona, 以下是查詢 MariaDB 版本的例子:
# rpm -qa | grep mariadb
執行後會有類似下的輸出:
mariadb-libs-5.5.52-1.el7.x86_64
mariadb-5.5.52-1.el7.x86_64
mariadb-server-5.5.52-1.el7.x86_64
mariadb-5.5.52-1.el7.x86_64
mariadb-server-5.5.52-1.el7.x86_64
MySQL Client
除了用以上方法外, 也可以登入 MySQL 查詢, 先登入 MySQL:
1 2 3 4 5 6 7 8 9 |
$ mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 7600 Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. |
執行 “select VERSIOM()” 這個 MySQL 指令, 可以查詢 MySQL 版本:
1 |
MariaDB [(none)]> select VERSION(); |
會有以下輸出:
1 2 3 4 5 6 7 |
MariaDB [(none)]> select VERSION(); +----------------+ | VERSION() | +----------------+ | 5.5.52-MariaDB | +----------------+ 1 row in set (0.00 sec) |
如果不能存取 CLI, 也可以用 PHP 或 phpMyAdmin 檢查,以下的 PHP 使用內建的 mysql_get_server_info() 函式檢查, 先建立一支簡單的 PHP Script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<!--?php ### 改成你的 MySQL 登入資訊 $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } printf("MySQL server version: %s\n", mysql_get_server_info()); </pre--> 用瀏覽器開啟以上 php script 便可以看到 MySQL 版本。 另一個做法是登入 phpMyAdmin 查看, 登入 phpMyAdmin 後, 右邊可以如下圖看到 MySQL 版本: <img src="/wp-content/uploads/phpmyadmin-get-mysql-version.png" alt="" class="aligncenter size-full wp-image-2549" width="398" height="193"> |