由于各个 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"> |