How to run command "mysqladmin flush-hosts" on Amazon RDS database server instance?
Asked Answered
G

11

62

I got a database server failure, says host is blocked because of many connection errors. It ask me to unblock with mysqladmin flush-hosts.

How and where should I run this command to our Amazon RDS database server?

Gilli answered 4/11, 2011 at 18:52 Comment(0)
L
87

For normal MySQL, just connect as the 'root' administrative super user, and issue the command:

FLUSH HOSTS

Even in the case of too many connections, MySQL should be keeping a connection in reserve so that a super user can connect.

The mysqladmin client generally connects as root anyway and issues the above SQL.

Lifeordeath answered 5/11, 2011 at 0:44 Comment(5)
liThanks, this is exactly what I needed: a little context. fwiw mysqladmin will work with RDS too (as long as you're using a user with permission to do so (ie, root) - I wasn't).Glassworker
This is a great answer but not applicable to AWS.Nitroglycerin
Why not? Can you not run FLUSH HOSTS on AWS?Lifeordeath
This worked well for me, but do take into account that in RDS the admin user is rarely called root. When you create the instance you are asked to enter an account name, and that account is the administrator account.Coan
In addition to this, I also ran the following to make sure any corruption was dealt with : mysqlcheck --auto-repair --all-databases -h HOST -u USER -pOrmolu
D
31

Login to any other EC2 instance you have that has access to the RDS instance in question and has mysqladmin installed and run

mysqladmin -h <RDS ENDPOINT URL> -P 3306 -u <USER> -p flush-hosts

you will be prompted for your password

Dayton answered 12/3, 2013 at 17:24 Comment(3)
It need not be from any EC2 instance. It can be done from a local machine as well. Where ever mysql is installed.Rumpf
This does not work from a beanstalk EC2 instance to an RDS mysql host. Using the mysqladmin command to connect to the host produces an error: mysqladmin: connect to server at 'challengefinder-rds.crstas8123.us-west-1.rds.amazonaws.com' failed error: 'Host 'ip-10-170-12-12.us-west-1.compute.internal' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts''Nitroglycerin
You can use another computer - just add your IP address to the security group for that RDS instance and then you can use mysqladmin from your workstation.Coan
F
16

When an Amazon RDS instance is blocked because the value of max_connect_errors has been exceeded, you cannot use the host that generated the connection errors to issue the "flush hosts" command, as the MySQL Server running on the instance is at that point blocking connections from that host.

You therefore need to issue the "flush hosts" command from another EC2 instance or remote server that has access to that RDS instance.

mysqladmin -h [YOUR RDS END POINT URL] -P 3306 -u [DB USER] -p flush-hosts

If this involved launching a new instance, or creating/modifying security groups to permit external access, it may be quicker to simply login to the RDS user interface and reboot the RDS instance that is blocked.

Foetus answered 18/3, 2014 at 13:41 Comment(1)
Rebooting the instance was the easiest for me.Myrna
S
11

I fixed this error on my RDS instance by rebooting it from the AWS management console. HTH

[edit: lol downvotes]

Softhearted answered 11/10, 2012 at 21:12 Comment(1)
Thank you so much. I tried the solution above but I could not log with mysqladmin either because of the same error!Navarre
Q
5

On Amazon RDS FLUSH HOSTS; can be executed from default user ("Master Username" in RDS info), and it helps.

Quiberon answered 11/6, 2012 at 17:51 Comment(0)
P
5

Since the hosts is blocked. try connect it from other host and execute the mysqladmin flush-hosts command.

mysqladmin -h <RDS ENDPOINT URL> -P <PORT> -u <USER> -p flush-hosts
Pecksniffian answered 28/8, 2013 at 1:8 Comment(0)
C
2

You will have to connect your RDS through a computer which as mysql installed on it I used one of my hosting VPS using SSH

After i was logged in my VPS ( i used putty ) It was simple, in the prompt i entered the following command:

mysqladmin -h [YOUR RDS END POINT URL] -P 3306 -u [DB USER] -p flush-hosts
Countryandwestern answered 9/10, 2012 at 8:51 Comment(0)
F
1

You can restart the database on RDS Admin.

Funderburk answered 15/1, 2014 at 18:19 Comment(0)
G
0

You can flush hosts local MySQL using following command:

mysqladmin -u [username] -p flush-hosts
**** [MySQL password]

or

mysqladmin flush-hosts -u [username] -p
**** [MySQL password]

Though Amazon RDS database server is on network then use the following command as like as flush network MySQL server:

mysqladmin -h <RDS ENDPOINT URL> -P <PORT> -u <USER> -p flush-hosts
mysqladmin -h [YOUR RDS END POINT URL] -P 3306 -u [DB USER] -p flush-hosts 

In additional suggestion you can permanently solve blocked of many connections error problem by editing my.ini file[Mysql configuration file]

change variables max_connections = 10000;

or

login into MySQL using command line -

mysql -u [username] -p
**** [MySQL password]

put the below command into MySQL window

SET GLOBAL max_connect_errors=10000;
set global max_connections = 200;

check veritable using command-

show variables like "max_connections";
show variables like "max_connect_errors";
Geodesy answered 18/1, 2016 at 8:55 Comment(2)
On RDS, it's not possible to run any commands locally, because you can't login to the database host. Over the network also doesn't work, because mysqladmin also can't connect, for the same reason. ("error: 'Host 'your.client.ip.address' is blocked because of many connection errors")Mewl
You can reboot the rds server (take a snapshot if needed as well) and then the problem will be solved.Guck
L
0

I faced a similar issue where i was getting "Host 'xx.xx.xx.xx' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'" while connecting to mysql RDS production server using dbeaver from my local.

I resolved it by running below commands from an EC2 in production subnet

First i installed mysql client on ec2

sudo yum install mysql

Then i executed below command to flush host

mysql -h <host-name> -P <port> -u <username> --database=<database-name> -p -e "FLUSH HOSTS;"

After that i was able to connect to mysql RDS from dbeaver successfully.

Lodging answered 9/12, 2023 at 7:2 Comment(0)
G
-1

got this error today on a customer rds while they were using Heidi Sql client.

We simply used 'mysqlroot' on the ec2 that talks to the rds in question to connect, followed by issuing the 'flush hosts;' cmd.

Gironde answered 23/9, 2021 at 23:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.