coant 发表于 2023-2-25 11:16:48

MySQL 查看版本的 5 种方法

MySQL 提供了几种用于查看服务器版本的方法,本文给大家做个简单的介绍。
方法一:登录 MySQL

每次通过 mysql 客户端连接服务器之后,都会显示一个欢迎信息,里面包含了服务器的版本:
mysql -uroot
Enter password: ******

Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 8.0.32 MySQL Community 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() |
+-----------+
span class="o">| 8.0.32    |
+-----------+方法四:SHOW VARIABLES 语句

SHOW VARIABLES 语句可以返回 MySQL 系统变量。通过添加 WHERE 条件,我们可以获取服务器的版本信息:
SHOW VARIABLES
WHERE variable_name LIKE 'version%';

+--------------------------+-----------------------------+
| Variable_name            | Value                     |
+--------------------------+-----------------------------+
| version                  | 8.0.32                      |
| version_comment          | MySQL Community Server - GPL|
| version_compile_machine| x86_64                      |
| version_compile_os       | Win64                     |
| version_compile_zlib   | 1.2.11                      |
+--------------------------+-----------------+方法五:STATUS 命令

连接到 MySQL 服务器之后,输入 STATUS 命令可以返回版本和其他信息:
STATUS;返回结果示例如下:
--------------
C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exeVer 8.0.32 for Win64 on x86_64 (MySQL Community 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 Community 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: 2Questions: 443Slow queries: 0Opens: 350Flush tables: 3Open tables: 251Queries per second avg: 0.000
--------------
页: [1]
查看完整版本: MySQL 查看版本的 5 种方法