How to unblock with mysqladmin flush hosts - mysql

I have gone through similar cases listed here but it doesn't seem to work.
I was using MySQL Workbench to establish a connection with my database which is hosted on another server. Tried a few times and unable to connect followed by this error. I am confused as to where I should even do this flush. On PhpMyadmin under the SQL query? Cos when I tried to input the following command, it returns as syntax error. I am using a windows OS thus no shell shell scripting for me to input this information either. I am accessing the database temporarily via Cpanel/ phpmyadmin now.
Please help to tell where I should input this data and if my syntax is wrong. Thanks for help.
mysqladmin flush-hosts;
or
mysqladmin -umyname -pmypassword flush-hosts;
My error message as follows:
Failed to connect to MYSql at 192...* with user myName
Host 'host-92...*.as13285.net' is blocked because of many connection
errors; unblock with 'mysqladmin flush-hosts'

mysqladmin is not a SQL statement. It's a little helper utility program you'll find on your MySQL server... and "flush-hosts" is one of the things it can do. ("status" and "shutdown" are a couple of other things that come to mind).
You type that command from a shell prompt.
Alternately, from your query browser (such as phpMyAdmin), the SQL statement you're looking for is simply this:
FLUSH HOSTS;
http://dev.mysql.com/doc/refman/5.6/en/flush.html
http://dev.mysql.com/doc/refman/5.6/en/mysqladmin.html

You should put it into command line in windows.
mysqladmin -u [username] -p flush-hosts
**** [MySQL password]
or
mysqladmin flush-hosts -u [username] -p
**** [MySQL password]
For network login use the following command:
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
you can permanently solution your 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";

You can easily restart your MySql service. This kicks the error off.

Related

mysqldump via cmd syntax for dumping remote database

I have Mysql installed on my local PC and want to use mysqldump on my local pc to dump a remote database. So I open CMD and run the following command:
mysqldump -P 3306 -h 12.43.33.43 -u admin -p myDatabase > mydb.sql
So in the next line it should ask for my password? but instead i get the response 'Access is denied'. Am i missing something here?
ps.
If I try the following:
mysqldump -P 3306 -h 12.43.33.43 -u admin -p myDatabase
it will successfully ask for my password and start printing the dump in cmd, but this is no good as i need the response saved in a file.
I only wanted to know if you could connect.
The command is
mysqldump -P 3306 -h 12.43.33.43 -u admin -p --databases myDatabase --result-file=mydb.sql
As the connection is not secure, you send your credentials like a postcard, so that every one can read it.
Besides that having your server exposed to the internet, is very dangerous and can come to a disaster, so reconsider your security strategy and allow only access via ssh.

Mysql ERROR : not connected

I am trying to connect to MySQL database from MySQL shell on windows.
No matter what I type in MySQL shell, it keeps giving me error : 'Not connected'.
Query eg 1 : mysql --host=localhost --port=3306 --user=root -p;
Query eg 2 : mysql -u root -p
O/P : ERROR: Not connected
I have MySQL server installed on my machine. Also MySQL service is running in the background.
Also, I was able to connect from MySQL workbench.
ERROR MESSAGE
MySQL Workbench Connection
My temporary workaround is that I make use of ssl protocol to connect to MySQL server :
MySQL> \connect root#localhost
MySQL localhost:33060+ ssl SQL > show databases;
The first step is that you need to check if you are in the MYSQL Shell SQL mode or JS mode.
Then if you are in SQL mode then you are good to go else you need to switch to SQL mode by this command
\sql
The next step is to connect using this command
\connect root#localhost
In your case, you might have given the privilege as the IP address so you need to check your localhost IP which can be done by this command in your command prompt.
ipconfig and then just check the IP address and put it in place of localhost in the previous command. If this still doesn't works then put 127.0.0.1:3306.
After this, it will prompt to add or save the password , enter a unique password there.
After this you are good to go and check the user and localhost after this by this command
SELECT user, host FROM mysql.user;
Try mysql -u root -p
I haven't used MySQL shell, I typically use gitbash and it works just fine
I had faced the same issue on my Windows 10 machine with MySQL 5.7 and the following commands helped me:
mysqlsh.exe - to open mysql shell; then
\sql - to start working with SQL;
finally:
\connect root#127.0.0.1:3306
You can use:
mysql -uroot -hlocalhost -P3306 -p
or
mysql -uroot -h127.0.0.1 -P3306 -p
or
mysql -uroot -p

MySQL treats password in script as database

I am new to Bash scripting. I want to create a script that logs in to MySQL for me:
PASSWORD="MyPassword"
sudo service mysql start
mysql -u root -p $PASSWORD
However, it throws an error telling me that my password ($PASSWORD) is not a database.
Is there any way to do it?
Thanks and sorry if I am asking something RTFM or UTFM.
From man mysql:
If you use the short option form (-p), you cannot have a space between the option and the password.
So either
mysql -u root -p"$PASSWORD"
or
mysql -u root --password "$PASSWORD"
It is insecure to use password on the command line.
From the mysql user guide:
This is convenient but insecure. On some systems, your password becomes visible to system status programs such as ps that may be invoked by other users to display command lines.
I would suggest You to use the mysql_config_editor utility, to store your db credentials.
mysql_config_editor set --login-path=YOUR_LOGIN_PATH --host=YOUR_HOST --user=YOUR_DB_USER --password
Then it will ask for password interactively
After that you can connect to your db:
mysql --login-path=YOUR_LOGIN_PATH YOUR_DB
Example (set credentials):
mysql_config_editor set --login-path=root --host=localhost --user=root --password
Example (connect to db in your script):
mysql --login-path=root YOUR_DB

How to do "mysqladmin flush-hosts" on server?

I have a hosting account, on database section i have "MySQL® Databases",
"MySQL® Database Wizard","phpMyAdmin" and "Remote MySQL" Options
Error i am getting is
Database ErrorHost 'adonis.havehost.com' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
Write a server application that sends the query:
FLUSH HOSTS
to MySQL.
If you have shell access to the server, you can login and do:
mysql -u root -p -e 'flush hosts'
This must solve your issue.
mysql -u root -p -e 'flush hosts'
mysql -u root -p -e 'flush hosts'
And you can even contract your server provider
In MySql,run the following query:
FLUSH HOSTS;
Using mysqladmin you can execute this command:
mysqladmin flush-hosts;
and
mysqladmin flush-status;
This will remove the error shown by your MySQL server.
log in to your server by putty SSH, and just type this command
mysql -u root -p -e 'flush hosts'
and enter your root password after that your host name will be flushed , with out showing any massage in Shell.

how to run command "mysqladmin flush-hosts" on Amazon RDS database Server instance?

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?
thank you
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.
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
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.
I fixed this error on my RDS instance by rebooting it from the AWS management console. HTH
[edit: lol downvotes]
On Amazon RDS FLUSH HOSTS; can be executed from default user ("Master Username" in RDS info), and it helps.
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
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
You can restart the database on RDS Admin.
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";
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.