LINUX文件设置:

ulimit -n <num>  ----> [/etc/profile,/.bashrc] ---->/etc/security/limits.conf [* soft|hard  nofile  <num>  ] ------>/proc/sys/fs/nr_open-----> /proc/sys/fs/file-max ----->/etc/sysctl.conf

LINUX 连接设置:

ulimit -u  <num>  ------->[/etc/profile,/.bashrc]--------->/etc/security/limits.conf[* soft|hard  nproc <num>]

 mysql 应用程连接设置:my.cnf

[mysqld]
max_connections=4
max_connect_errors=

最大用户连接:

max_user_connections     3    //针对同一用户的链接

所有用户连接之和:

max_connections         4    //所有用户连接的和

实验:

会话1

[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28-debug-log Source distribution Copyright (c) 2000, 2015, 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. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

会话2

[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28-debug-log Source distribution Copyright (c) 2000, 2015, 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. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

会话3

[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28-debug-log Source distribution Copyright (c) 2000, 2015, 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. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

会话4:

[root@localhost ~]# mysql -uroot -p                           //root 用户 more than 'max_user_connections'
Enter password: ERROR  (): User root already has more than 'max_user_connections' active connections

[root@localhost ~]# mysql -umysql -p                          //mysql用户可登陆
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6.-debug-log Source distribution Copyright (c) , , 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. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

会话5:

Last login: Thu Jul   ::  from 192.168.1.152
[root@localhost ~]# mysql -umysql -p
Enter password:
ERROR (): Too many connections 已超过最大连接数
[root@localhost ~]#
max_connect_errors:
mysql的这个参数指的是网络错误  

密码错误并不算在内,尝试用for循环尝试密码的用户host并不会block

以下是mysql非常出名的分支percona的cto关于max_connect_errors的评论

There seems to be confusion around that variable.

It does not really block hosts for repeated invalid passwords but for aborted connections due to network errors.
模拟网络错误:max_connect_errors=1
http://www.cnblogs.com/ivictor/p/5311607.html
[root@localhost ~]# telnet 192.168.1.26 3306
Trying 192.168.1.26...
Connected to 192.168.1.26 (192.168.1.26).
Escape character is '^]'.
jHost '192.168.1.26' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'Connection closed by foreign host.

[root@localhost ~]# mysql -h192.168.1.26 -p -uroot
Enter password:
ERROR 1129 (HY000): Host '192.168.1.26' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' [root@localhost ~]# mysql -h192.168.1.26 -p -uroot
Enter password:
ERROR 1129 (HY000): Host '192.168.1.26' is blocked because of many connection errors; unblock with 'mysqladmin flush-host'
一、程序运行一段时间后,tomcat启动后,连接池不能使用,拿不到数据库连接,查看catalina.out发现如下错误:
[http-80-35] ERROR sls.database.DBConn - org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create Poola
bleConnectionFactory (null, message from server: Host localhost is blocked because of many connection errors; unblock with mysqladmin flush-hosts) 二、出现的原因:
数据库的错误链接处达到最大,数据库服务器拒绝连接。
由于出现某台host连接错误次数等于max_connect_errors(默认10) ,主机'host_name'再次尝试时被屏蔽。可有效反的防止dos攻击,使用'mysqladmin flush-hosts'解除屏蔽。 【连接次数失败过多,并超过max_connect_erros的值后,服务器会直接拒绝来源机器的所有连接,只要把 mysql server默认 max_connect_errors = 10
把这个值设置大点就好了,记得一定要执行mysqladmin flush-hosts命令来解锁,原来的主机才可以恢复正常连接的.】

三、解决方案:
1.查看数据库允许的错误链接数:
show status 看那个abort_client.
2.运行:
mysqladmin flush-hosts命令,解除数据库的连接屏蔽,重新允许数据库被访问。 3.也可以重启mysql数据库,这样,也可以将错误链接数清零。 4.修改my.inf或者:my.cnf修改max_connect_errors的值,可以适当大些。
配置文件中,如果没有此键值,请在[mysqld]内增加该值。
# Maximum amount of errors allowed per host. If this limit is reached,
# the host will be blocked from connecting to the MySQL server until
# "FLUSH HOSTS" has been run or the server was restarted. Invalid
# passwords and other errors during the connect phase result in
# increasing this value. See the "Aborted_connects" status variable for
# global counter.
max_connect_errors = 8000

[mysqld]
max_connections=xx
max_connect_errors=xx
max_user_connections=xx

max_user_connections 与 max_connections,max_connect_errors, nr_open, file-max的更多相关文章

  1. mysql实例的连接数max_user_connections 和max_connections 配置的那些事

    今天在查线上问题时,通过phpMyAdmin来进行DML操作,发现比平时慢多了,就各种进原因. 项目的场景是一个mysql实例中创建了多个数据库,猜想可能是相互影响所致. 然后,查询线上Mysql数据 ...

  2. MySQL二进制包安装及启动问题排查

    环境部署:VMware10.0+CentOS6.9(64位)+MySQL5.7.19(64位)一.操作系统调整 # 更改时区 .先查看时区 [root@localhost ~]# date -R Tu ...

  3. MySQL的max_user_connections拒绝连接的一次踩雷经验

    近期线上的数据遇到一个问题,最终原因为max_user_connections和max_connections的一个bug导致,具体过程如下 现象 前端页面不断的出现错误页面. 排查处理过程 按照数据 ...

  4. php使用file函数、fseek函数读取大文件效率分析

    php读取大文件可以使用file函数和fseek函数,但是二者之间效率可能存在差异,本文章向大家介绍php file函数与fseek函数实现大文件读取效率对比分析,需要的朋友可以参考一下. 1. 直接 ...

  5. NR_OPEN 与 NR_FILE 的区别

    NR_OPEN 与 NR_FILE 的区别 阅读0.11版的内核源码时,在linux-0.11/fs/pipe.c中,函数sys_pipe()里面出现了2个宏定义,NR_OPEN 与 NR_FILE. ...

  6. I/O————File对象

    File文件对象 文件和文件夹都是用File代表 创建一个文件对象,(并不会有真正的文件或文件夹被创建) File f1 = new File("d:/lolfilder"); S ...

  7. LNMP一键安装脚本

    #!/bin/bash #LNMP(Fastcgi) #CentOS + MySQL 5.5 #-- iptables -F iptables -X iptables -Z iptables -A I ...

  8. LNMP搭建(CentOS 6.3+Nginx 1.2.0+PHP 5.3.15(fpm)+ MySQL 5.5.35)

    Nginx (“engine x”) 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器. Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 ...

  9. MYSQL汇总

    一.1.1 MYSQL 一.1.1.1 基础特性 1)性能卓越,服务稳定,很少出现异常宕机: 2)开放源代码且无版权制约,自主性强,使用成本低: 3)历史悠久,社区及用户非常活跃,遇到问题,可快速获得 ...

随机推荐

  1. GitHub进一步了解

    为什么要引入Git: 1)用简单一点的例子来讲: 一个公司有几个甚至十几个人共同合作开发一款项目的时候,公司对项目代码有明确规范,不可能再像学校做的小项目一样,你觉得哪个同学的代码写的不好,或者和你的 ...

  2. WCF配置文件详解(一)

    <?xml version="1.0" encoding="utf-8" ?><configuration>    <!-- &l ...

  3. [转] “无法注册程序集***dll- 拒绝访问。请确保您正在以管理员身份运行应用程序。对注册表项”***“的访问被拒绝

    原文 Win8下Visual Studio编译报“无法注册程序集***dll- 拒绝访问.请确保您正在以管理员身份运行应用程序.对注册表项”***“的访问被拒绝.”问题修正 原来在Win7下Visua ...

  4. Python环境变量设置

    在Windows环境下安装了python后,为了方便运行.py文件,可以设置环境变量如下: 环境变量位置 添加值 添加后效果 系统变量中的PATH python.exe所在目录,比如D:\Python ...

  5. 浅谈Javascript中默认参数值的设置

    第一种: 1: function test(a,b){ 2: var a = arguments[0] ? arguments[0] : 1;//设置参数a的默认值为1 3: var b = argu ...

  6. Python【基础第一篇】

    一.Python3新特性 编码统一为unicode Python3不支持Twisted,暂时只支持73% 1/2=0.5 print "hello World" 变成 print ...

  7. leetcode@ [91] Decode Ways (Dynamic Programming)

    https://leetcode.com/problems/decode-ways/ A message containing letters from A-Z is being encoded to ...

  8. STL学习系列一:STL(标准模板库)理论基础

    STL(Standard Template Library,标准模板库)是惠普实验室开发的一系列软件的统称.现然主要出现在C++中,但在被引入C++之前该技术就已经存在了很长的一段时间. STL的从广 ...

  9. KVC, KVO实现原理剖析

    iPhone程序开发 KVO/KVC实现机理分析是本文要介绍的内容,不多说,直接进入话题.我们来看详细内容. Objective-C里面的Key-Value Observing (KVO)机制,非常不 ...

  10. MYSQL- 分页存储过程

    工作需要,用到MYSQL的分页功能,在网上找到一个不错的分页存储过程,代码整理了一下! 存储过程代码 CREATE PROCEDURE `sp_hj_splitpage`( in _pagecurre ...