mysql 提供了几种用于查看服务器版本的方法,本文给大家做个简单的介绍。
方法一:登录 Mysql
每次通过 mysql 客户端连接服务器之后,都会显示一个欢迎信息,里面包含了服务器的版本:
mysql -uroot
Enter password: ******
Wel***e to the MySQL monitor. ***mands end with ; or \g.
Your MySQL connection id is 21
Server version: 8.0.32 MySQL ***munity Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
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.
方法二:@@version 变量
MySQL 全局变量 @@version 存储了服务器的版本号,我们可以利用一个简单的 SELECT 语句查询其中的信息。例如:
SELECT @@version;
查询结果示例如下:
+-----------+
| @@version |
+-----------+
| 8.0.32 |
+-----------+
方法三:VERSION() 函数
系统函数 VERSION() 也可以返回 MySQL 服务器的版本信息,例如:
SELECT VERSION();
+-----------+
| VERSION() |
+-----------+
| 8.0.32 |
+-----------+
方法四:SHOW VARIABLES 语句
SHOW VARIABLES 语句可以返回 MySQL 系统变量。通过添加 WHERE 条件,我们可以获取服务器的版本信息:
SHOW VARIABLES
WHERE variable_name LIKE 'version%';
+--------------------------+-----------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------+
| version | 8.0.32 |
| version_***ment | MySQL ***munity Server - GPL|
| version_***pile_machine | x86_64 |
| version_***pile_os | Win64 |
| version_***pile_zlib | 1.2.11 |
+--------------------------+-----------------+
方法五:STATUS 命令
连接到 MySQL 服务器之后,输入 STATUS 命令可以返回版本和其他信息:
STATUS;
返回结果示例如下:
--------------
C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe Ver 8.0.32 for Win64 on x86_64 (MySQL ***munity Server - GPL)
Connection id: 21
Current database:
Current user: root@localhost
SSL: Cipher in use is TLS_AES_256_GCM_SHA384
Using delimiter: ;
Server version: 8.0.32 MySQL ***munity Server - GPL
Protocol version: 10
Connection: localhost via TCP/IP
Server characterset: utf8mb4
Db characterset: utf8mb4
Client characterset: gbk
Conn. characterset: gbk
TCP port: 3306
Binary data as: Hexadecimal
Uptime: 12 days 10 hours 10 min 48 sec
Threads: 2 Questions: 443 Slow queries: 0 Opens: 350 Flush tables: 3 Open tables: 251 Queries per second avg: 0.000
--------------