【MySQL】有关登录连接的几个参数(max_connections等)及其相关错误

【MySQL】有关登录连接的几个参数(max_connections、max_user_connections、max_connect_errors、Max_used_connections等)及其相关错误





 

真题1、在登录MySQL时遇到“ERROR 1040 (00000): Too many connections”错误,如何解决?

答案:该错误表示连接数过多,不能正常登录数据库。主要原因是max_connections参数设置过小,该参数表示允许客户端并发连接的最大数量,默认值是151,可以根据业务需求将该参数设置为500-2000,最小值为1,最大值为100000。需要注意的是,其实MySQL允许的最大连接数为:max_connections+1,因为这超出的一个用户其实是作为超级管理员来使用的。所以,若max_connections的值设置为1,则第3个客户端登录才会报“Too many connections”的错误。

示例如下所示:

mysql> show variables like '%max_connection%';

+-----------------+-------+

| Variable_name   | Value |

+-----------------+-------+

| max_connections | 151   |

+-----------------+-------+

1 row in set (0.00 sec)

 

mysql>  show processlist;

+----+------+-----------+------+---------+------+----------+------------------+

| Id | User | Host      | db   | Command | Time | State    | Info             |

+----+------+-----------+------+---------+------+----------+------------------+

|  7 | root | localhost | NULL | Query   |    0 | starting | show processlist |

+----+------+-----------+------+---------+------+----------+------------------+

1 row in set (0.00 sec)

 

mysql> set global max_connections=1;

Query OK, 0 rows affected (0.00 sec)

 

mysql> system mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 26

Server version: 5.7.19 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2017, 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.

 

mysql>  show processlist;

+----+------+-----------+------+---------+------+----------+------------------+

| Id | User | Host      | db   | Command | Time | State    | Info             |

+----+------+-----------+------+---------+------+----------+------------------+

|  7 | root | localhost | NULL | Sleep   |   34 |          | NULL             |

| 26 | root | localhost | NULL | Query   |    0 | starting | show processlist |

+----+------+-----------+------+---------+------+----------+------------------+

2 rows in set (0.00 sec)

 

mysql> system mysql

ERROR 1040 (HY000): Too many connections

 

mysql> system mysql -h 192.168.59.159 -uroot -plhr

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 1040 (HY000): Too many connections

 

mysql> set global max_connections=151;

Query OK, 0 rows affected (0.00 sec)

 

mysql>  system mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 27

Server version: 5.7.19 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2017, 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.

 

mysql> system mysql -h 192.168.59.159 -uroot -plhr

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 29

Server version: 5.7.19 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2017, 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.

 

mysql>  show processlist;

+----+------+-------------+------+---------+------+----------+------------------+

| Id | User | Host        | db   | Command | Time | State    | Info             |

+----+------+-------------+------+---------+------+----------+------------------+

|  7 | root | localhost   | NULL | Sleep   |  334 |          | NULL             |

| 26 | root | localhost   | NULL | Sleep   |  274 |          | NULL             |

| 27 | root | localhost   | NULL | Sleep   |  267 |          | NULL             |

| 28 | root | LHRDB:47236 | NULL | Query   |    0 | starting | show processlist |

+----+------+-------------+------+---------+------+----------+------------------+

4 rows in set (0.00 sec)

 

真题2、“ERROR 1203 (42000): User root already has more than 'max_user_connections' active connections”如何解决?

答案:与错误“ERROR 1040 (00000): Too many connections”类似的还有“ERROR 1203 (42000): User root already has more than 'max_user_connections' active connections”。该错误表示,某个用户的连接数超过了max_user_connections的值。参数max_user_connections表示每个用户的最大连接数,默认为0,表示没有限制。需要注意的是,此处的用户是以“用户名+主机名”为单位进行区分,如下所示:

mysql> show variables like 'max_user_connections';

+----------------------+-------+

| Variable_name        | Value |

+----------------------+-------+

| max_user_connections | 0     |

+----------------------+-------+

1 row in set (0.00 sec)

 

mysql> set global max_user_connections=1;

Query OK, 0 rows affected (0.00 sec)

 

mysql> show processlist;

+----+------+-----------+------+---------+------+----------+------------------+

| Id | User | Host      | db   | Command | Time | State    | Info             |

+----+------+-----------+------+---------+------+----------+------------------+

|  7 | root | localhost | NULL | Query   |    0 | starting | show processlist |

+----+------+-----------+------+---------+------+----------+------------------+

1 row in set (0.00 sec)

 

mysql> system mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 21

Server version: 5.7.19 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2017, 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.

 

mysql> show processlist;

+----+------+-----------+------+---------+------+----------+------------------+

| Id | User | Host      | db   | Command | Time | State    | Info             |

+----+------+-----------+------+---------+------+----------+------------------+

|  7 | root | localhost | NULL | Sleep   |   16 |          | NULL             |

| 21 | root | localhost | NULL | Query   |    0 | starting | show processlist |

+----+------+-----------+------+---------+------+----------+------------------+

2 rows in set (0.00 sec)

 

mysql>  system mysql

ERROR 1203 (42000): User root already has more than 'max_user_connections' active connections

mysql>

mysql> system mysql -h 192.168.59.159 -uroot -plhr

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 23

Server version: 5.7.19 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2017, 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.

 

mysql>  show processlist;

+----+------+-------------+------+---------+------+----------+------------------+

| Id | User | Host        | db   | Command | Time | State    | Info             |

+----+------+-------------+------+---------+------+----------+------------------+

|  7 | root | localhost   | NULL | Sleep   |   52 |          | NULL             |

| 21 | root | localhost   | NULL | Sleep   |   36 |          | NULL             |

| 23 | root | LHRDB:47232 | NULL | Query   |    0 | starting | show processlist |

+----+------+-------------+------+---------+------+----------+------------------+

3 rows in set (0.00 sec)

 

mysql> system mysql -h 192.168.59.159 -uroot -plhr

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 1203 (42000): User root already has more than 'max_user_connections' active connections

mysql>

 

真题3、max_connect_errors参数的作用是什么?

答案:max_connect_errors参数表示如果MySQL服务器连续接收到了来自于同一个主机的请求,且这些连续的请求全部都没有成功的建立连接就被断开了,当这些连续的请求的累计值大于 max_connect_errors的设定值时,MySQL服务器就会阻止这台主机后续的所有请求。相关的登录错误信息会记录到performance_schema.host_cache表中。遇到这种情况,可以清空host cache来解决,具体的清空方法是执行flush hosts或者在MySQL服务器的shell里执行mysqladmin flush-hosts操作,其实就是清空performance_schema.host_cache表中的记录。参数max_connect_errors从MySQL 5.6.6开始默认值为100,小于该版本时默认值为10。当这一客户端成功连接一次MySQL服务器后,针对此客户端的max_connect_errors会清零。

若max_connect_errors的设置过小,则网页可能提示无法连接数据库服务器;而通过SSH的mysql命令连接数据库,则会返回类似于下面的错误:

ERROR 1129 (00000): Host 'gateway' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'

一般来说建议数据库服务器不监听来自网络的连接,仅仅通过sock连接,这样可以防止绝大多数针对MySQL的攻击;如果必须要开启MySQL的网络连接,则最好设置此值,以防止穷举密码的攻击手段。

 

真题4、状态变量Max_used_connections的作用是什么?

答案:系统状态变量Max_used_connections是指从这次MySQL服务启动到现在,同一时刻并行连接数的最大值。它不是指当前的连接情况,而是一个比较值。如果在过去某一个时刻,MySQL服务同时有1000个请求连接过来,而之后再也没有出现这么大的并发请求时,那么Max_used_connections=1000。









Too many connections(连接数过多,导致连接不上数据库,业务无法正常进行)

问题还原

mysql> show variables like '%max_connection%';
| Variable_name   | Value |
max_connections | 151   | 
mysql> set global max_connections=1;Query OK, 0 rows affected (0.00 sec)
[root@node4 ~]# mysql -uzs -p123456 -h 192.168.56.132
ERROR 1040 (00000): Too many connections


解决问题的思路:    

1、首先先要考虑在我们 MySQL 数据库参数文件里面,对应的 max_connections 这个参数值是不是设置的太小了,导致客户端连接数超过了数据库所承受的最大值。

● 该值默认大小是151,我们可以根据实际情况进行调整。

● 对应解决办法:set global max_connections=500


但这样调整会有隐患,因为我们无法确认数据库是否可以承担这么大的连接压力,就好比原来一个人只能吃一个馒头,但现在却非要让他吃 10 个,他肯定接受不了。反应到服务器上面,就有可能会出现宕机的可能。


所以这又反应出了,我们在新上线一个业务系统的时候,要做好压力测试。保证后期对数据库进行优化调整。


2、其次可以限制 Innodb 的并发处理数量,如果 innodb_thread_concurrency = 0(这种代表不受限制) 可以先改成 16或是64 看服务器压力。如果非常大,可以先改的小一点让服务器的压力下来之后,然后再慢慢增大,根据自己的业务而定。个人建议可以先调整为 16 即可。


MySQL 随着连接数的增加性能是会下降的,可以让开发配合设置 thread pool,连接复用。在MySQL商业版中加入了thread pool这项功能


另外对于有的监控程序会读取 information_schema 下面的表,可以考虑关闭下面的参数
innodb_stats_on_metadata=0
set global innodb_stats_on_metadata=0



mysql查看最大连接数
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 1000  |
+-----------------+-------+

查看当前连接数
mysql> show status like 'Threads%';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_cached    | 58    |
| Threads_connected | 57    |   ###这个数值指的是打开的连接数
| Threads_created   | 3676  |
| Threads_running   | 4     |   ###这个数值指的是激活的连接数,这个数值一般远低于connected数值
+-------------------+-------+

当超过最大max_user_connections,会提示max_user_connections限制数时会提示 User big already has more than 'max_user_connections
当超过max_connections,会提示too many connection

调整max_connections和max_user_connections值
max_connections #整个mysql服务器的最大连接数,如果服务器的并发连接请求量比较大,建议调高此值
max_user_connections #每个数据库用户的最大连接,注意是以用户+主机为单位
interactive_timeout=60 #服务器关闭交互式连接前等待活动的秒数
wait_timeout=60 #服务器关闭非交互连接之前等待活动的秒数

注意:
1、响应连接数占上限连接数的85%左右,如果发现比例在10%以下,mysql服务器连接上线就设置得过高了
Max_used_connections / max_connections * 100% ≈ 85%
2、连接数据库不要用root帐号,且只有root有super权限,免得连接数过多root帐号都登录不了

对于连接数的设置,show variables里有三个参数可以对它进行控制,max_connections与max_user_connections以及max_connect_errors。下面对这三个参数相关描述。

max_connections:针对所有的账号所有的客户端并行连接到MYSQL服务的最大并行连接数。简单说是指MYSQL服务能够同时接受的最大并行连接数。

max_user_connections : 针对某一个账号的所有客户端并行连接到MYSQL服务的最大并行连接数。简单说是指同一个账号能够同时连接到mysql服务的最大连接数。设置为0表示不限制。

max_connect_errors:针对某一个IP主机连接中断与mysql服务连接的次数,如果超过这个值,这个IP主机将会阻止从这个IP主机发送出去的连接请求。遇到这种情况,需执行flush hosts。

在 show global 里有个系统状态Max_used_connections,它是指从这次mysql服务启动到现在,同一时刻并行连接数的最大值。它不是指当前的连接情况,而是一个比较值。如果在过去某一个时刻,MYSQL服务同时有1000个请求连接过来,而之后再也没有出现这么大的并发请求时,则Max_used_connections=1000.请注意与show variables 里的max_user_connections的区别。

mysql 的max_connections和max_user_connections 的区别

首先产看该全局变量的值

mysql> select @@max_user_connections;
+------------------------+
| @@max_user_connections |
+------------------------+
|                      0 |
+------------------------+

1 row in set (0.00 sec)

默认情况系是为0的

为0是什么意思呢?它是说不限制用户资源的。

在这里我改变一下它的值,并在查询,注意这改变在服务器重启后无效,想一直保存的话就放在选项文件里面!

mysql> set  @@global.max_user_connections=1;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@max_user_connections;
+------------------------+
| @@max_user_connections |
+------------------------+
|                      1 |
+------------------------+
1 row in set (0.00 sec)


现在我重新开启一个连接
C:\Windows\System32>mysql -uroot -pweb
ERROR 1203 (42000): User root already has more than 'max_user_connections' activ
e connections

意思是这个用户已经达到最大的连接数,不能再连接拥有资源!

该参数只能对整体限制资源,不能对某个用户进行限制,如果需要对某个用户限制的话,你可以在权限表里面看到

        max_questions: 0
          max_updates: 0
      max_connections: 0
 max_user_connections: 0

这几个参数可以对某个用户进行限制。



max_connections 的意思是对整个服务器的用户限制!



参数max_connect_errors

时间: 2016-12-23 20:00:06        阅读: 114        评论: 0        收藏: 0          [点我收藏+]

标签:mysql   数据库   参数   

max_connect_errors 这个参数控制登陆失败尝试次数,也就是你可以有多少次机会重试登陆;


可以通过status中查看下面两个参数:


Aborted_clients 表示已经成功建立连接的登陆,然后超时断开,或者kill掉的次数;

Aborted_connects 表示失败尝试连接的次数;


例:


session1:


mysql>show global variables like ‘%max_connect_errors%‘;

+--------------------+-------+

| Variable_name      | Value |

+--------------------+-------+

| max_connect_errors | 5     |

+--------------------+-------+


开始演示前的数据库原始数据:

mysql>show global status like ‘%abort%‘;

+------------------+-------+

| Variable_name    | Value |

+------------------+-------+

| Aborted_clients  | 0     |

| Aborted_connects | 0     |

+------------------+-------+


session2:


mysql>show processlist;

+----+------+-----------+------+---------+------+----------+------------------+

| Id | User | Host      | db   | Command | Time | State    | Info             |

+----+------+-----------+------+---------+------+----------+------------------+

|  2 | root | localhost | NULL | Sleep   |    8 |          | NULL             |

|  3 | root | localhost | NULL | Query   |    0 | starting | show processlist |

+----+------+-----------+------+---------+------+----------+------------------+


干掉现在的连接:

mysql>kill 3;


session1:


可以看到aborted_client变成1,表示原来的一次成功登陆又断开连接了:


mysql>show global status like ‘%abort%‘;       

+------------------+-------+

| Variable_name    | Value |

+------------------+-------+

| Aborted_clients  | 1     |

| Aborted_connects | 0     |

+------------------+-------+


session2:


重复这个命令8次:


[root@Darren1 ~]# mysql -uroot -p111

mysql: [Warning] Using a password on the command line interface can be insecure.

ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)


session1:


再回来看aborted_connects变成8 ,表示尝试了8次错误密码登陆


mysql>show global status like ‘%abort%‘;       

+------------------+-------+

| Variable_name    | Value |

+------------------+-------+

| Aborted_clients  | 2     |

| Aborted_connects | 8     |

+------------------+-------+


这里有个问题:前面尝试了8次错误密码登陆,为什么 还可以继续尝试登陆呢,为什么max_connetc_errors=5没有生效呢?


这是因为通过mysql -uroot -p111这种本地客户端的网络方式尝试连接,只会提示密码错误,没有失败登陆限制,max_connect_errors这个参数对其他连接方式有限制。


例:


在cmd中:


连续执行6次,会报错,意思就是说尝试次数超过max_connect_errors限制,要想重新登陆,必须执行flush hosts;


C:\Users\cdh>telnet 192.168.91.16 3306

ERROR 1129 (00000):Host ‘192.168.91.1‘ is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts‘


mysql>flush hosts;

Query OK, 0 rows affected (0.01 sec)


或者用:


[root@Darren1 ~]# mysqladmin -uroot -p147258 flush-hosts;



分类: MySQL


max_connect_errors是一个MySQL中与安全有关的计数器值,它负责阻止过多尝试失败的客户端以防止暴力破解密码的情况。max_connect_errors的值与性能并无太大关系。

默认情况下,my.cnf文件中可能没有此行,如果需要设置此数值,手动添加即可。

 

参数格式

       max_connect_errors = 10

修改方法

如果系统是CentOS、Debian等,则配置文件可能位于 /etc/my.cnf 。打开此文件

            # vi /etc/my.cnf

然后在[mysqld]配置节中加入上述语句即可。

 

配置说明

当此值设置为10时,意味着如果某一客户端尝试连接此MySQL服务器,但是失败(如密码错误等等)10次,则MySQL会无条件强制阻止此客户端连接。

如果希望重置此计数器的值,则必须重启MySQL服务器或者执行

            Mysql> FLUSH HOSTS;

命令。

当这一客户端成功连接一次MySQL服务器后,针对此客户端的max_connect_errors会清零。

 

影响与错误形式

如果max_connect_errors的设置过小,则网页可能提示无法连接数据库服务器;而通过SSH的mysql命令连接数据库,则会返回

ERROR 1129 (00000): Host ‘gateway’ is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’

错误。

 

功能与作用

一般来说建议数据库服务器不监听来自网络的连接,仅仅通过sock连接,这样可以防止绝大多数针对mysql的攻击;如果必须要开启mysql的网络连接,则最好设置此值,以防止穷举密码的攻击手段。




被我误解的max_connect_errors

第一节  什么是max_connect_errors

一开始接触这个参数的时候,感觉他和max_connections的含义差不多,字面意思简单明了,这个参数的含义是最大连接错误数,翻翻mysql的文档中的解释是If more than this many successive connection requests from a host are interrupted without a successful connection, the server blocks that host from further connections,大意是:如果mysql服务器连续接收到了来自于同一个主机的请求,且这些连续的请求全部都没有成功的建立连接就被断开了,当这些连续的请求的累计值大于max_connect_errors的设定值时,mysql服务器就会阻止这台主机后续的所有请求without a successful connection”那太好办了,故意输错密码不就行了,并且网上搜索了下该参数的说明,大量的文章充斥着 防止暴力破解密码的内容,于是兴高采烈的去做了测试。

第二节  测试max_connect_errors

1,创建账号:

b984add34b00bee3d562d96d25fa07ccb8145a7a

2,设置max_connect_errors3

4776ffe81ccffb4de40ab1daacd8220f5be822d2

3,故意输错密码3次,第四次使用正确密码登录进行验证:

f376ff16b8b381fcf71f4b79893db1fd11246e51

4,结论是第四次依然可以登录,即密码不对(认证失败)不属于 without a successful connection”的范畴,网上的 防止暴力破解密码也不成立了。

6cd06be24be4b24af171a2710d5f5e790f977cb3

第三节 继续分析max_connect_errors

再继续看文档,发现还有以下说明:

 You can unblock blocked hosts by flushing the host cache. To do so, issue a FLUSH HOSTS statement or execute a mysqladmin flush-hosts command.

大意是:

当你遇到主机被阻止的时候,你可以清空host cache来解决,具体的清空方法是执行flush hosts或者在mysql服务器的shell里执行 mysqladmin flush-hosts操作

既然清空host cache可以解决主机被阻止访问的问题,那应该与host cache有些关系,看看host cache的介绍可能会有些眉目,关于host cache,文档解释如下:

The MySQL server maintains a host cache in memory that contains information about clients: IP address, host name, and error information. The server uses this cache for nonlocal TCP connections. It does not use the cache for TCP connections established using a loopback interface address (127.0.0.1 or ::1), or for connections established using a Unix socket file, named pipe, or shared memory.

大意是:

Mysql服务器会在内存里管理一个host cachehost cache里保存了一些客户端的ip地址,主机名,以及这个客户端在与server建立连接时遇到的一些错误信息,host cache对不是本地的TCP连接才有效,所以host cache127.0.0.1 或者::1是无效的,并且对于Unix socket filenamed pipe以及 shared memory方式建立的连接也是无效的。并且通过了解,host cache的内容可以通过performance_schema.host_cache来查看,通过performance_schema.host_cache表里的几个列的描述信息,对之前的测试不成立的原因有些了解了,部分相关列如下:

·        IP

The IP address of the client that connected to the server, expressed as a string.

连接到mysql server的主机的连接地址

·        HOST

The resolved DNS host name for that client IP, or NULL if the name is unknown.

通过dns解析IP地址获取到的该IP地址对应的mysql client的主机名

 

·        SUM_CONNECT_ERRORS

The number of connection errors that are deemed “blocking” (assessed against the max_connect_errors system variable).Only protocol handshake errors are counted, and only for hosts that passed validation (HOST_VALIDATED = YES).

 

·        COUNT_HANDSHAKE_ERRORS

The number of errors detected at the wire protocol level.

通过SUM_CONNECT_ERRORS(连接错误计数)描述,重点是红色部分:只计算协议握手过程的错误(Only protocol handshake errors are counted),也就是说max_connect_errors 可能记录的是协议(不确定是tcp协议还是应用协议,通过抓包以及COUNT_HANDSHAKE_ERRORS的 the wire protocol level说明可能是指应用协议)的握手过程中出现的错误 ,也就是可以说网络不好(无法顺利握手)会导致该问题。

第四节 继续测试max_connect_errors

通过之前的说明,需要模拟应用协议握手失败的情况,最后考虑使用telnet一些来做测试

1,创建账号

b984add34b00bee3d562d96d25fa07ccb8145a7a

2,设置max_connect_errors3

4776ffe81ccffb4de40ab1daacd8220f5be822d2

3,先使用telnet 10.26.254.217 3306连接3次,第四次使用正确的账号密码尝试登陆:

telnet前查看performance_schema.host_cache的记录为空

95e4568e7fe1b5cb44a21b30a9aa9210ef9f0a73

第一次telnet 10.26.254.217 3306

bce33a3ea7394f8e1d564c3921d3f294dcd79814

052299fb80bdd456d12855a8f84689011f13ce51

第二次 telnet 10.26.254.217 3306

9ac1875beec55c02bedc86afcee78400f63745c5

f7a6d9e971fdc753d65c5b116b95ed45572e0d55

第三次telnet 10.26.254.217 3306

aa6232eaa401e0c1bfa5cdcfc0f2168c379ec97a

09f732c6269039549da6393138a09d99cee2a878

第四次执行mysql -h10.26.254.217 -utestcon -p123 -P3306

3bba32ab58c65de19d912febc805d13f407c93b8

fe47d609cfd83b0867b5a64232d1a6aae1011505

问题复现了,出现了错误提示ERROR 1129 (HY000): Host '10.24.236.231' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'

第五节 ERROR 1129 (HY000)问题延伸

解决ERROR 1129 (HY000)的方法是执行flush host或者 mysqladmin flush-hosts,其目的是为了清空host cache里的信息,那是不是说不使用host cache就可以了?使host cache不生效的方式有如下两种:

1,设置 host_cache_size 为0/ 打开skip-host-cache

2,打开skip-name-resolve 

需要通过测试看下推测是否生效

5.1 设置 host_cache_size 为0/ 打开skip-host-cache

1,设置host_cache_size为0

f0d9b5f93d58538762288eb6be86e8edb9cd6cab

2,再次查询performance_schema.host_cache

44dd050f8f353a71d9563c3b38092d0cc0bb65a9

3,继续之前的测试:先使用telnet 10.26.254.217 3306连接3次,第四次使用正确的账号密码尝试登陆

5f889f9d574cf843a1423a12ac4a2d21b73d9f8d

更改已经生效,max_connect_errors的作用无效了

5.2 打开skip-name-resolve 

1,在cnf配置文件里设置skip-name-resolve 以此打开skip-name-resolve 

123514e6b68f10befb209f4321c1ab82894fc7d3

2,继续之前的测试:先使用telnet 10.26.254.217 3306连接3次,第四次使用正确的账号密码尝试登陆

3fe7fac36742a2b9391267ab4936372a891e2d7a

3,查询performance_schema.host_cache

4f308a50bcc5c27cb666b61228177261312cd0e0

更改已经生效,max_connect_errors的作用无效了,RDS for  mysql 的skip_name_resolve是on的状态,

所以很少会出现ERROR 1129 (HY000)的错误

 








About Me

.............................................................................................................................................

● 本文作者:小麦苗,部分内容整理自网络,若有侵权请联系小麦苗删除

● 本文在itpub(http://blog.itpub.net/26736162/abstract/1/)、博客园(http://www.cnblogs.com/lhrbest)和个人微信公众号(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/

● 本文博客园地址:http://www.cnblogs.com/lhrbest

● 本文pdf版、个人简介及小麦苗云盘地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 数据库笔试面试题库及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● DBA宝典今日头条号地址:http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826

.............................................................................................................................................

● QQ群号:230161599(满)、618766405

● 微信群:可加我微信,我拉大家进群,非诚勿扰

● 联系我请加QQ好友646634621,注明添加缘由

● 于 2017-12-01 09:00 ~ 2017-12-31 22:00 在魔都完成

● 文章内容来源于小麦苗的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解

● 版权所有,欢迎分享本文,转载请保留出处

.............................................................................................................................................

小麦苗的微店https://weidian.com/s/793741433?wfr=c&ifr=shopdetail

小麦苗出版的数据库类丛书http://blog.itpub.net/26736162/viewspace-2142121/

.............................................................................................................................................

使用微信客户端扫描下面的二维码来关注小麦苗的微信公众号(xiaomaimiaolhr)及QQ群(DBA宝典),学习最实用的数据库技术。

   小麦苗的微信公众号      小麦苗的DBA宝典QQ群2     《DBA笔试面宝典》读者群       小麦苗的微店

.............................................................................................................................................

ico_mailme_02.png
DBA笔试面试讲解群
《DBA宝典》读者群 欢迎与我联系



来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26736162/viewspace-2149444/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26736162/viewspace-2149444/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值