zoukankan      html  css  js  c++  java
  • CentOS中设置Mysql的最大连接数max_connections(用于解决too many connections的问题)

    一、引入

      最近一个python的定时任务系统的项目,在做定时数据统计的时候经常报错too many connections,字面意思很简单,就是数据库连接池不够用了。那么比较直接的方法就是手动设置数据库的最大连接数max_connections

    二、如何配置

    1.查询Mysql当前的最大连接数

    mysql> show variables like "max_connections";
    +-----------------+-------+
    | Variable_name   | Value |
    +-----------------+-------+
    | max_connections | 150  |
    +-----------------+-------+
    row in set

    2.在文件etc/my.cnf中设置Mysql 最大连接数

    [mysqld]
    max_connections =2000

    3.重启Mysql 命令

    $ systemctl restart  mysqld.service

    4.查询Mysql当前的最大连接数,发现最大连接数是214

    mysql> show variables like "max_connections";
    +-----------------+-------+
    | Variable_name   | Value |
    +-----------------+-------+
    | max_connections | 214  |
    +-----------------+-------+
    row in set

    5.更改 MySQL 在 Linux 的最大文件描述符限制,编辑 /usr/lib/systemd/system/mysqld.service 文件,在文件最后添加: 
    ubuntu16.04 下面位于:/lib/systemd/system/mysql.servive,可以通过find 命令查找

    LimitNOFILE=65535
    LimitNPROC=65535
    

      保存后,执行下面命令,使配置生效

    $ systemctl daemon-reload
    $ systemctl restart  mysqld.service
    

      实际连接数到 2000 了,解决

    1 mysql> show variables like "max_connections";
    2 +-----------------+-------+
    3 | Variable_name   | Value |
    4 +-----------------+-------+
    5 | max_connections | 2000  |
    6 +-----------------+-------+
    7 row in set

     三、总结

      嗯,暂时没问题了、参考博客:https://www.cnblogs.com/kingchou/p/9321803.html

      

  • 相关阅读:
    自己实现 一个 Vue框架,包含了Vue的核心原理
    Vue-Cli 3.0 中配置高德地图的两种方式
    element-ui table 点击某行高亮(修改背景色)
    input type="file"获取文件名方法
    使用 http-proxy-middleware 做转发, post 请求转发失败
    core-js@2 core-js@3报错问题
    VUE判断当前设备是PC还是移动端
    Vue函数式组件 简单实现
    清明节哀悼日网页变黑白色的CSS代码
    Vue实现递归menu
  • 原文地址:https://www.cnblogs.com/JentZhang/p/12581116.html
Copyright © 2011-2022 走看看