MySQL用很多常用的内置变量,掌握这些内置变量后对于我们快速获取当前MySQL的配置有很大帮助,下面就来列举几个常用的变量。
- 查看当前MySQL版本号信息。
show variables like 'version';
MariaDB [(none)]> show variables like 'version';
+---------------+----------------+
| Variable_name | Value |
+---------------+----------------+
| version | 5.5.60-MariaDB |
+---------------+----------------+
1 row in set (0.00 sec)
- 查看当前MySQL服务监听的端口号信息。
show variables like 'port';
MariaDB [(none)]> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.00 sec)
- 查看当前MySQL数据的默认存储路径信息。
show variables like 'datadir';
MariaDB [(none)]> show variables like 'datadir';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| datadir | /var/lib/mysql/ |
+---------------+-----------------+
1 row in set (0.00 sec)
- 查看当前MySQL使用的引擎信息。
show variables like 'storage_engine';
MariaDB [(none)]> show variables like 'storage_engine';
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| storage_engine | InnoDB |
+----------------+--------+
1 row in set (0.01 sec)
- 查看当前MySQL的最大连接数信息。
show variables like 'max_connections';
MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 151 |
+-----------------+-------+
1 row in set (0.00 sec)
修改max_connectionis变量值:
MariaDB [(none)]> set global max_connections=65535;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 65535 |
+-----------------+-------+
1 row in set (0.00 sec)
掌握一些必要的变量后发现在使用过程中修改,是不用重启MySQL服务的,这样我们可以先进入MySQL将最大连接数进行修改,后续加入到配置文件中,选择维护时间将MySQL重启,配置就可以永久生效了。