很多时候,我们想看下服务器里运行的Mysql是多少版本,我们可能习惯用mysql -V或mysql –help的常规命令方式查看,其实这种方式是错误的,这两个命令查看的是mysql客户端工具版本,而不是真正的mysql服务端版本,要想全面、准确的掌握运行中的Mysql版本,可以通过以下几个方式实现。
方式一:通过外在表象确定
### 查已安装rpm包情况 # rpm -qa |grep mysql mysql-community-server-8.0.27-1.el7.x86_64 mysql80-community-release-el7-4.noarch mysql-community-libs-8.0.27-1.el7.x86_64 rh-php72-php-mysqlnd-7.2.24-1.el7.x86_64 zabbix-web-mysql-scl-5.0.9-1.el7.noarch mysql-community-common-8.0.27-1.el7.x86_64 mysql-community-client-plugins-8.0.27-1.el7.x86_64 mysql-community-client-8.0.27-1.el7.x86_64 从上面返回的信息来看,这台机器安装了mysql社区版8.0.27。当然操作系统安装了rpm包的mysql,并不代表它运行的是已安装的mysql,这个情况下,需要用ps aux|grep mysql查确认一下。 # ps aux |grep mysql mysql 2156 0.9 6.1 12855852 2006856 ? Ssl Sep27 1176:03 /usr/sbin/mysqld root 23169 0.0 0.0 112816 980 pts/5 S+ 10:35 0:00 grep --color=auto mysql # ll /usr/sbin/mysqld -rwxr-xr-x 1 root root 1062412952 Sep 28 2021 /usr/sbin/mysqld 看正在运行的mysql进程,如果主mysqld文件在/usr/sbin/mysqld目录下,并且这个文件不是链接文件,基本上可以认为是rpm包方式安装,并运行的。 还有一些情况,有些mysql是编译安装的,或直接解压二进制安装的,文件可能存放在/usr/local目录或/opt下的某个目录,或/data下的某个目录下,这个情况可以直接用ls之类的命令看看,如以下命令就可以查看是安装了mysql-8.0.35,但有没有启动这个,还需要结合ps aux |grep mysql看进程信息。 # ll /usr/local/ total 4 drwxr-xr-x. 2 root root 6 Mar 25 2022 bin drwxr-xr-x. 2 root root 6 Mar 25 2022 etc drwxr-xr-x. 2 root root 6 Mar 25 2022 games drwxr-xr-x. 2 root root 6 Mar 25 2022 include drwxr-xr-x. 2 root root 6 Mar 25 2022 lib drwxr-xr-x. 3 root root 17 Nov 13 16:49 lib64 drwxr-xr-x. 2 root root 6 Mar 25 2022 libexec drwxr-xr-x. 9 mysql mysql 129 Nov 14 15:17 mysql-8.0.35 drwxr-xr-x. 2 root root 6 Mar 25 2022 sbin drwxr-xr-x. 5 root root 49 Nov 13 16:49 share drwxr-xr-x. 2 root root 6 Mar 25 2022 src
方式二:通过sql查询
### 当Mysql正在运行,并且可以登录Mysql情况下,可以通过写sql语句查询,命令为:select version()。 mysql> select version(); +-----------+ | version() | +-----------+ | 8.0.27 | +-----------+ 1 row in set (0.00 sec)
方式三:通过cli命令行
### 当我们用mysql客户端连接服务时,输入正确的用户名/密码,成功登录mysql服务器,就会看到版本信息,如以下信息为mysql 9.0.27版本,并且是mysql官方社区版Community Server。 # mysql -uroot -p -S /var/lib/mysql/mysql.sock Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 68435 Server version: 8.0.27 MySQL Community Server - GPL Copyright (c) 2000, 2023, 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. mysql> ### 命令行模式下,还可以输入status命令,查看版本及更多信息,如字符集编码 mysql> status; -------------- mysql Ver 8.0.35 for Linux on x86_64 (MySQL Community Server - GPL) Connection id: 68435 Current database: Current user: root@localhost SSL: Not in use Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 8.0.27 MySQL Community Server - GPL Protocol version: 10 Connection: Localhost via UNIX socket Server characterset: utf8mb4 Db characterset: utf8mb4 Client characterset: utf8mb4 Conn. characterset: utf8mb4 UNIX socket: /var/lib/mysql/mysql.sock Binary data as: Hexadecimal Uptime: 84 days 13 min 21 sec Threads: 2 Questions: 29357883 Slow queries: 0 Opens: 20343 Flush tables: 3 Open tables: 3939 Queries per second avg: 4.044 -------------- mysql> ### 通过查询数据库全局变量也可以看到信息,如我们查询version有关的变量值,也会返回mysql的版本信息,并且还可以看到tls版本信息(mysql客户端通过ssl证书模式连接Mysql服务器) mysql> SHOW GLOBAL VARIABLES LIKE '%version%'; +--------------------------+------------------------------+ | Variable_name | Value | +--------------------------+------------------------------+ | admin_tls_version | TLSv1,TLSv1.1,TLSv1.2 | | innodb_version | 8.0.27 | | protocol_version | 10 | | replica_type_conversions | | | slave_type_conversions | | | tls_version | TLSv1,TLSv1.1,TLSv1.2 | | version | 8.0.27 | | version_comment | MySQL Community Server - GPL | | version_compile_machine | x86_64 | | version_compile_os | Linux | | version_compile_zlib | 1.2.11 | +--------------------------+------------------------------+ 11 rows in set (0.00 sec)
声明:欢迎大家光临本站,学习IT运维技术,转载本站内容,请注明内容出处”来源刘国华教育“。如若本站内容侵犯了原著者的合法权益,请联系我们进行处理。