• mysql配置my.cnf文件,以及参数优化提升性能


    系统centos7
    mariadb通过yum安装
    mysql配置文件位于/etc/my.cnf

    常用参数:

    1)max_connections设置最大连接(用户)数,其默认值为100,设置太小会出现too many connections错误。例如,max_connections=1000

      其修改方法有两种,即时生效,查看当前max_connections值,select &&MAX_CONNECTIONS AS 'Max Connections';

      临时设置: set global max_connections=2000;

      编辑my.conf:添加参数max_connections=200,不过需要重启mysql才能生效

    2)安全参数

      max_connect_errors这个参数负责阻止客户端尝试暴力破解密码,当某台主机错误连接次数达到该值时,该主机无法再尝试登陆。解决方法是重启mysql,或者把该值改大一点

    3)设置数据包大小

      max_allowed_packet设置server运行通信的最大数据包大小,如果该参数过小,可能导致比较大的insert或update执行失败

    常用命令

    1)参看当前mysql连接情况

      show status where variable_name like '%Thread%';

    mysqld]
    log-slow-queries=zhao                   #开启慢查询日志
    long_query_time=5                       #语句查询时间查过这个值将会被记录到慢查询日志中
    log=abp                                 #通用查询日志
    log-bin=mysql-bin                       #二进制日志
    character_set_server=utf8               #字符
    collation-server=utf8_general_ci
    init_connect='SET NAMES utf8'           #设置utf8字符
    #binlog_format=row
    #skip-grant                             #忘记密码时可以去掉这行的注释,从而免验证进入数据库
    datadir=/var/lib/mysql                  #数据目录,类似于win系统上的data目录
    socket=/var/lib/mysql/mysql.sock        #sock文件路径
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    # Settings user and group are ignored when systemd is used.
    # If you need to run mysqld under a different user or group,
    # customize your systemd unit file for mariadb according to the
    # instructions in http://fedoraproject.org/wiki/Systemd
    
    [mysqld_safe]
    log-error=/var/log/mariadb/mariadb.log          #错误日志
    pid-file=/var/run/mariadb/mariadb.pid           #pid文件路径
    
    #
    # include all files from the config directory
    #
    !includedir /etc/my.cnf.d
    

    另外还有几个主要参数
    (1)innodb_buffer_pool_size 缓存数据和索引的内存缓冲区大小,理论上该至越高,访问数据需要的磁盘i/o就越少,建议设置为物理内存大小的70%~80%。该参数写在my.cnf的[mysqld]里。修改之后重启mysql生效,使用select @@innodb_buffer_pool_size/1024/1024查看(除以1024是因为要转换为M)
    (2)innodb_log_file_size 日志文件大小 值越大越节约磁盘I/O,但在崩溃回复时越慢。建议将日志文件大小设置为256MB或更大。该参数也是放在my.cnf的[mysqld]下。修改之后可能会无法启动mysql,解决方法是,停止mysql,然后删除mysql的日志文件,执行rm -f /var/lib/mysql/ib_logfile*。重启mysql,使用select查看,修改成功
    (3)innodb_flush_log_at_trx_commit这个值我还暂时搞不懂,建议设置为2。
    (4)sync_binlog 建议设置为0

  • 相关阅读:
    js template实现方法
    linux su和sudo命令的区别
    使用u盘安装os x系统
    单个APP页面支持屏幕旋转
    iOS 抓取 HTML ,CSS XPath 解析数据
    Oslo 相机 App
    App 开发步骤
    iOS 自动布局框架 – Masonry 详解
    细聊 Cocoapods 与 Xcode 工程配置
    2017网页设计趋势
  • 原文地址:https://www.cnblogs.com/biaopei/p/7730498.html
Copyright © 2020-2023  润新知