其实很简单,利用MySQL在windows下面是大小写不敏感而在Linux下面大小写敏感的特性来判断。
在windows下执行:
mysql> create database webSec; Query OK, 1 row affected (0.01 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | | websec | +--------------------+ 5 rows in set (0.00 sec) mysql> create database websec; ERROR 1007 (HY000): Can't create database 'websec'; database exists
可以看出,在windows下是大小写不敏感的。
在Linux下执行:
mysql> create database websec; Query OK, 1 row affected (0.01 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | websec | +--------------------+ 4 rows in set (0.00 sec) mysql> create database Websec; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | Websec | | mysql | | performance_schema | | websec | +--------------------+ 5 rows in set (0.01 sec)
发现对大小写敏感。
通过这个手段就可以判断目标操作系统。当然,其实还有更简单的方式:
mysql> select @@version_compile_os; +----------------------+ | @@version_compile_os | +----------------------+ | Win64 | +----------------------+ 1 row in set (0.00 sec)
mysql> select @@version_compile_os; +----------------------+ | @@version_compile_os | +----------------------+ | debian-linux-gnu | +----------------------+ 1 row in set (0.38 sec)