首页 技术 正文
技术 2022年11月20日
0 收藏 807 点赞 2,893 浏览 2264 个字

一:查看服务所有变量

  MySQL服务器维护许多配置其操作的系统变量。每个系统变量都有一个默认值。可以使用命令行或选项文件中的选项在服务器启动时设置系统变量。其中大多数都可以在运行时使用动态更改 SET 语句,这使您可以修改服务器的操作,而无需停止并重新启动它。您还可以在表达式中使用系统变量值。

  mysqld –verbose –help

[root@qywxdb /]# mysqld --verbose --help
mysqld Ver 5.7.22 for Linux on x86_64 (MySQL Community Server (GPL))
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Starts the MySQL database server.Usage: mysqld [OPTIONS]Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
The following groups are read: mysqld server mysqld-5.7
The following options may be given as the first argument:
--print-defaults Print the program argument list and exit.
--no-defaults Don't read default options from any option file,
except for login file.
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=#
Also read groups with concat(group, suffix)
--login-path=# Read this path from the login file.

备注:该命令可查看服务器版本,和读取配置文件顺序

二:设置变量

  SET variable = expr [, variable = expr] …

                variable: { user_var_name | param_name | local_var_name | {GLOBAL | @@GLOBAL.} system_var_name | [SESSION | @@SESSION. | @@] system_var_name }

有些情况时我们需要修改服务器变量的默认值,例如我们修改sql_mode的值(已支持不严格的group by),此时我们可以使用set语句来修改系统变量。同时我们可以使用set定义一些其他的变量(用户变量,该变量是session级别的)。

2.1 设置全局变量

  SET GLOBAL max_connections = 1000;

  SET @@GLOBAL.max_connections = 1000;

2.2  设置session变量

SET SESSION sql_mode = ‘TRADITIONAL’;

   SET LOCAL sql_mode = ‘TRADITIONAL’;

SET @@SESSION.sql_mode = ‘TRADITIONAL’;

SET @@LOCAL.sql_mode = ‘TRADITIONAL’;

SET @@sql_mode = ‘TRADITIONAL’;

SET sql_mode = ‘TRADITIONAL’;

2.3 定义新变量

  mysql> set @name=’woshiwo’; //新增环境变量

  mysql> select @name;       //查询定义的环境变量
  | @name |
  | woshiwo |

三 :查看变量(show)

  SHOW [GLOBAL | SESSION] VARIABLES [LIKE ‘pattern‘ | WHERE expr]

*  服务器变量维护在 GLOBAL_VARIABLES 与 SESSION_VARIABLES 表。//不可直接查看

*  如果不存在修饰符,则默认为 SESSION

*  使用GLOBAL修饰符,语句显示全局系统变量值。这些是用于初始化与MySQL的新连接的相应会话变量的值。如果变量没有全局值,则不显示任何值。

*  使用SESSION修饰符,语句将显示对当前连接有效的系统变量值。如果变量没有会话值,则显示全局值。LOCAL是…的同义词SESSION

3.1 通过like查询

SHOW VARIABLES LIKE ‘max_join_size’;

 SHOW VARIABLES LIKE ‘%size%’;   //模糊查询

SHOW SESSION VARIABLES LIKE ‘max_join_size’;

SHOW GLOBAL VARIABLES LIKE ‘%size%’;

3.2 通过where 查询

show variables where Variable_name like ‘log%’ and value=’ON’;

  

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,105
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,582
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,429
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,836
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,919