Tuesday, May 5, 2009

Unblock with 'mysqladmin flush-hosts' Mysql 5 and greater

Many times we get this error due to

wrong authentication (username or password incorrect)
too many connections from same machine.

easiest way for this, is ..

clear with flush-hosts command. See http://dev.mysql.com/doc/refman/5.1/en/flush.html

STEPS for Linux

open terminal window type

mysqladmin -uroot -ppassword flush-hosts;

[Remember -uroot is your root name with a "-u" before it, and same for password "-p" before password]

You are done.


Another tip 1
------------------------------------------
Restarting MySQLd solves the problem. FLUSH HOSTS also wipes the internal DNS cache, so be careful with its use - a flood of reverse DNS lookups can severely limit your server’s speed!

open the terminal and type (for Linux)

/etc/init.d/mysql restart


Another tip 2 allow many connections
------------------------------------------
To increase the maximum connections that mysql allows, you must edit the file /etc/my.cnf. Log into the server as root and type

nano /etc/MYSQL/my.cnf

it will open the config file (depending upon your cnf file location change the path) and uncomment (remove #) to the following line with the allowed no of connections e.g.
max_connections=10000 
Now press CTRL+X and Yes (Y) to exit from terminal window. Now Type

/etc/init.d/mysql restart 
you will see on the terminal screen
Stopping MySQL database server mysqld: [ OK ]
Starting MySQL database server mysqld: [ OK ]
You are done.

CHECK THE SETTING IS PROPER OR NOT...

If you'd like to check to see if this setting was successfully applied, you may check using one of the following methods:
  1. login to mysql
    mysql -uadmin -ppassword
    or through mysql administrator tool (Go to tools->MySQL text Console), you will be at the "mysql>" prompt.

  2. Then give the command
    show variables like 'max_connections'; 

    make sure you put the semi-colon on the end. To exit mysql, use the "quit" command






7 comments:

  1. I have been making search for three hours 30 minutes for this solution without any intervals so far. I couldn't find any information like yours. I want o use and share this also in Turkish Php Support Site : PhpBBTurkey.Com = http://www.phpbbturkey.com/forums/viewtopic.php?f=20&t=18982 Thanx very much for your useful explanations..

    ReplyDelete
  2. thanks @Ademx33 .. i just wrote it because i wasted too much time to find a solution..!!

    ReplyDelete
  3. Many thanks~~
    And I think it is better to adjust 'max_connect_errors' to 10000 according to http://dev.mysql.com/doc/refman/5.0/en/blocked-host.html

    ReplyDelete
  4. @above

    well depends on your need.

    ReplyDelete
  5. Increasing max_connection to 10000 is kinda... in sane IMO. The amount of memory required by MySQL will be directly multiplied by number of max connection.

    From http://www.mysqlcalculator.com/, if you put 10000 as max connection, leaving all other parameter as default, you will required 27GB of memory for mysql alone. Let alone any other optimization that you might need. The value should be profiled as per usage using any monitoring tools like Cacti/Zabbix/Munin, and set appropriately.

    For this problem, setting max_connect_errors is more suitable.

    ReplyDelete
  6. Hi, I am using Windows 7. I have been accessing a website to attend a series of online tests. But when i tried to access today morning the following message came up.
    "Host '192.168.255.1' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"

    I am just a normal layman user, what should I do?
    Please help!

    ReplyDelete