美文网首页
mysql配置文件生效

mysql配置文件生效

作者: 大龄程序员在帝都 | 来源:发表于2016-07-30 12:30 被阅读973次

    问题:如何查看和配置mysql的配置文件,mysql中的配置文件对于调试mysql和排查错误比较有用,例如缓存设置等!

    1、如何查找mysql配置文件

    在mac或者linux上安装mysql或者mariadb的时候一般采用 homebrew install xxx
    就自动安装了,安装完成以后如何查看配置文件呢?

    执行如下命令:

    mysqld --help --verbose | more
     (查看帮助, 按空格下翻)
    你会看到开始的这一行(表示配置文件默认读取顺序)
    

    我执行如下命令:

    ss:my.cnf.d wqp$ mysqld --help --verbose | more
    2016-07-30 10:06:33 140735210475520 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/var/mysql/ is case insensitive
    2016-07-30 10:06:33 140735210475520 [Note] Plugin 'FEEDBACK' is disabled.
    mysqld  Ver 10.1.13-MariaDB for osx10.11 on x86_64 (Homebrew)
    Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
    
    Starts the MariaDB database server.
    
    Usage: mysqld [OPTIONS]
    
    Default options are read from the following files in the given order:
    /usr/local/etc/my.cnf ~/.my.cnf
    

    最后一行显示,mysql启动时会按照一下顺序读取配置文件。

    /usr/local/etc/my.cnf ~/.my.cnf
    通常这些位置是没有配置文件的, 所以要自己建一个

    2、如何自建?

    首先找到一个配置模板,或者从网上找一个典型的配置模板,这里从以下 目录copy

    ss:~ wqp$ cd /usr/local/mysql/support-files/
    ss:support-files wqp$ ls
    binary-configure    config.medium.ini   magic           my-innodb-heavy-4G.cnf  my-medium.cnf       mysql-log-rotate    mysqld_multi.server
    config.huge.ini     config.small.ini    my-huge.cnf     my-large.cnf        my-small.cnf        mysql.server        ndb-config-2-node.ini
    

    拷贝到第一个默认读取目录

    ss:support-files wqp$ cp my-medium.cnf /usr/local/etc/my.cnf
    ss:support-files wqp$ pwd
    /usr/local/mysql/support-files
    

    然后重启mysql即可:

    mysql.server start
    mysql.server stop
    

    如何查看my.inf是否生效呢???

    一个简单的办法,就是在my.cnf中修改存储引擎。
    1、首先查看当前数据库的存储引擎,以下是两种方式:

    MariaDB [prf]> show engines;
        -> //
    +--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
    | Engine             | Support | Comment                                                                                          | Transactions | XA   | Savepoints |
    +--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
    | MRG_MyISAM         | YES     | Collection of identical MyISAM tables                                                            | NO           | NO   | NO         |
    | CSV                | YES     | CSV storage engine                                                                               | NO           | NO   | NO         |
    | MEMORY             | YES     | Hash based, stored in memory, useful for temporary tables                                        | NO           | NO   | NO         |
    | MyISAM             | YES     | MyISAM storage engine                                                                            | NO           | NO   | NO         |
    | SEQUENCE           | YES     | Generated tables filled with sequential values                                                   | YES          | NO   | YES        |
    | Aria               | YES     | Crash-safe tables with MyISAM heritage                                                           | NO           | NO   | NO         |
    | PERFORMANCE_SCHEMA | YES     | Performance Schema                                                                               | NO           | NO   | NO         |
    | InnoDB             | DEFAULT | Percona-XtraDB, Supports transactions, row-level locking, foreign keys and encryption for tables | YES          | YES  | YES        |
    +--------------------+---------+--------------------------------------------------------------------------------------------------+--------------+------+------------+
    8 rows in set (0.00 sec)
    
    MariaDB [prf]> show variables like '%storage_engine%';
        -> //
    +----------------------------+--------+
    | Variable_name              | Value  |
    +----------------------------+--------+
    | default_storage_engine     | InnoDB |
    | default_tmp_storage_engine |        |
    | enforce_storage_engine     |        |
    | storage_engine             | InnoDB |
    +----------------------------+--------+
    4 rows in set (0.00 sec)
    
    
    

    以上显示,目前的默认存储引擎为innodb,现在在配置文件中修改默认存储引擎为myisam
    这里一定要注意:
    **
    在my.cnf中添加配置 default-storage-engine=MYISAM
    注意这个必须添加在my.cnf中的[mysqld]项目下,才能生效:如果随便添加到其他项目下,是不会生效的。上午我花费了大量的时间来查看为什么没有进行生效,浪费了不少时间。所以这里一定要注意,每一个配置项都会有[xxx]来标示,不要随便放置,否则会不起作用
    **

    修改完成以后:保存: 重启mysql,查看存储引擎为:

    MariaDB [(none)]> show variables  like '%storage_engin%';
    +----------------------------+--------+
    | Variable_name              | Value  |
    +----------------------------+--------+
    | default_storage_engine     | MyISAM |
    | default_tmp_storage_engine |        |
    | enforce_storage_engine     |        |
    | storage_engine             | MyISAM |
    +----------------------------+--------+
    

    如上显示,已经修改为myisam了。

    reference
    比较详细说明

    相关文章

      网友评论

          本文标题:mysql配置文件生效

          本文链接:https://www.haomeiwen.com/subject/jqxtsttx.html