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. Java [leetcode 10] Regular Expression Matching

    问题描述: Implement regular expression matching with support for '.' and '*'. '.' Matches any single cha ...

  2. e2e 自动化集成测试 架构 实例 WebStorm Node.js Mocha WebDriverIO Selenium Step by step (二) 图片验证码的识别

    上一篇文章讲了“e2e 自动化集成测试 架构 京东 商品搜索 实例 WebStorm Node.js Mocha WebDriverIO Selenium Step by step 一 京东 商品搜索 ...

  3. H5制作1--母亲节快乐

    H5作品现在很流行额. 早上起的很早.就自己试着去了解了一下.感觉很easy. 用了百度的H5在线制作工具.感觉很easy.顺便给百度做下推广吧.h5.baidu.com 于是就有了自己的第一个dem ...

  4. MVC 实现计算页面执行时间

    使用 ActionFilterAttribute 来实现: public class PerformanceActionAttribute:ActionFilterAttribute { public ...

  5. 【DOM】1.DOM优化

    1.JS include :DOM BOM ECMA 2.Browser 分别独立实现dom & JS as if two isolated islands 3.JS操作DOM from th ...

  6. CCF 认证4

    题意:求强联通分量 Tarjan算法 #include<iostream> #include<stdio.h> #include<stdlib.h> #includ ...

  7. OpenCV - Operations on Arrays 对数组(矩阵)的一些操作

    Function (函数名) Use (函数用处) add 矩阵加法,A+B的更高级形式,支持mask scaleAdd 矩阵加法,一个带有缩放因子dst(I) = scale * src1(I) + ...

  8. Android权威编程指南读书笔记(1-2章)

    第一章 Android应用初体验 1.4用户界面设计 <?xml version="1.0" encoding="utf-8"?> ADT21开发版 ...

  9. python 递归函数

    在函数内部,可以调用其他函数.如果一个函数在内部调用自身本身,这个函数就是递归函数. 举个例子,我们来计算阶乘n! = 1 x 2 x 3 x ... x n,用函数fact(n)表示,可以看出: f ...

  10. MYSQL- 存储过程示例

    最近需要用到MYSQL,没耐心从头到尾,慢慢了解了,需要什么直接百度,直接了解,从实战中学习. 看一下MYSQL存储过程的示例: CREATE PROCEDURE plogin ( p_usernam ...