zoukankan      html  css  js  c++  java
  • MYSQL服务器系统变量

    一:查看服务所有变量

      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.
    View Code

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

    二:设置变量

      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'; 

      

      

  • 相关阅读:
    2009中国IT界名人
    jQuery简介
    Spring下载地址
    ContextLoaderListener
    MyBatisUtil类
    SSM事务
    后台管理中心跳转问题解决
    mybatis返回boolean值时数据库返回null
    yarn作业提交过程
    Hadoop集群运行wordcount jar包出错
  • 原文地址:https://www.cnblogs.com/jinliang374003909/p/10566310.html
Copyright © 2011-2022 走看看