Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server
Solution 1
Possibly a security precaution. You could try adding a new administrator account:
mysql> CREATE USER 'monty'@'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
-> WITH GRANT OPTION;
mysql> CREATE USER 'monty'@'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'%'
-> WITH GRANT OPTION;
Although as Pascal and others have noted it's not a great idea to have a user with this kind of access open to any IP. If you need an administrative user, use root, and leave it on localhost. For any other action specify exactly the privileges you need and limit the accessibility of the user as Pascal has suggest below.
Edit:
From the MySQL FAQ:
If you cannot figure out why you get Access denied, remove from the user table all entries that have Host values containing wildcards (entries that contain '%' or '_' characters). A very common error is to insert a new entry with Host='%' and User='some_user', thinking that this allows you to specify localhost to connect from the same machine. The reason that this does not work is that the default privileges include an entry with Host='localhost' and User=''. Because that entry has a Host value 'localhost' that is more specific than '%', it is used in preference to the new entry when connecting from localhost! The correct procedure is to insert a second entry with Host='localhost' and User='some_user', or to delete the entry with Host='localhost' and User=''. After deleting the entry, remember to issue a FLUSH PRIVILEGES statement to reload the grant tables. See also Section 5.4.4, “Access Control, Stage 1: Connection Verification”.
Solution 2
One has to create a new MySQL User
and assign privileges as below in Query prompt
via phpMyAdmin or command prompt:
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' WITH GRANT OPTION;
CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Once done with all four queries, it should connect with username / password
Solution 3
My error message was similar and said 'Host XXX is not allowed to connect to this MySQL server' even though I was using root. Here's how to make sure that root has the correct permissions.
My setup:
- Ubuntu 14.04 LTS
- MySQL v5.5.37
Solution
- Open up the file under 'etc/mysql/my.cnf'
Check for:
- port (by default this is 'port = 3306')
- bind-address (by default this is 'bind-address = 127.0.0.1'; if you want to open to all then just comment out this line. For my example, I'll say the actual server is on 10.1.1.7)
Now access the MySQL Database on your actual server (say your remote address is 123.123.123.123 at port 3306 as user 'root' and I want to change permissions on database 'dataentry'. Remember to change the IP Address, Port, and database name to your settings)
mysql -u root -p Enter password: <enter password> mysql>GRANT ALL ON *.* to root@'123.123.123.123' IDENTIFIED BY 'put-your-password'; mysql>FLUSH PRIVILEGES; mysql>exit
sudo service mysqld restart
- You should now be able to remote connect to your database. For example, I'm using MySQL Workbench and putting in 'Hostname:10.1.1.7', 'Port:3306', 'Username:root'
Solution 4
Just perform the following steps:
1a) Connect to mysql (via localhost)
mysql -uroot -p
1b) If the mysql server is running in Kubernetes (K8s) and being accessed via a NodePort
kubectl exec -it [pod-name] -- /bin/bash
mysql -uroot -p
Create user
CREATE USER 'user'@'%' IDENTIFIED BY 'password';
Grant permissions
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;
Flush privileges
FLUSH PRIVILEGES;
Solution 5
You need to grant access to the user from any hostname.
This is how you add new privilege from phpmyadmin
Goto Privileges > Add a new User
Select Any Host for the desired username
Comments
-
concept47 almost 2 years
This should be dead simple, but I cannot get it to work for the life of me.
I'm just trying to connect remotely to my MySQL server.- Connecting as:
mysql -u root -h localhost -p
- works fine, but trying:
mysql -u root -h 'any ip address here' -p
- fails with the error:
ERROR 1130 (00000): Host ''xxx.xx.xxx.xxx'' is not allowed to connect to this MySQL server
In the
mysql.user
table, there is exactly the same entry for user 'root' with host 'localhost' as another with host '%'.I'm at my wits' end and have no idea how to proceed. Any ideas are welcome.
-
Corey Ballou over 14 yearsGood catch Yannick, however I would not recommend him granting all privileges to a non-root user. Perhaps a reduced set?
-
Yannick Motton over 14 yearsWell, this indeed wouldn't be a good idea, but allowing 'root' to connect from all hosts is exactly the same, since it is at the same privilege level.
-
Yannick Motton over 14 yearsI think you miss my point Pascal. The point is that the 'root' user has those rights already, and he wants to let any ip authenticate as that user. So if this is really what he wants, the default example of creating a new administrator user (which has exactly the same rights) is an alternative to what he's trying.
-
Devanshu Mevada over 14 yearsThat's right Yannick, I read to fast and will remove my comment. However, AFAIK, permissions are working fine in MySQL so: 1. maybe the OP modified the grant tables manually and then need to flush privileges. 2. maybe he didn't use the proper grant syntax for root. Adding another administrative user might be a workaround but it won't solve the real issue IMHO.
-
PJ Brunet about 11 years"is a reply from the MySQL server to the MySQL client." Thank you, I was wondering where the error was coming from, my machine or the server. I have error "ERROR 1130 (HY000):" etc.
-
axon over 10 yearsThis is related, but not the same problem. The error originally received indicates the client is connecting to the MySQL server successfully, but then failing authentication. If bind-address was set to 127.0.0.1, you would get a connection refused error instead.
-
Kishan Bheemajiyani over 10 yearsBut this is address which will allow all the Host to get connected to the server na?
-
Kishan Bheemajiyani over 10 yearsBut Granting all the permission to the user will not be wise option for that bcoz if u have client user and u are not allowed to create user with all permission then what would be the Solution.?
-
Gustavo Guevara almost 10 yearsI felt that providing access from all hosts to root was not a proper solution. Instead I created a new user and granted a reduced set of privileges, the set I used is described as 'DBManager' on MySQL Workbench. I also only allowed access from a certain group of hosts in my local network, particularly 192.168.0.%
-
jazzy about 9 yearsYou can skip the
use dataentry
line (since most people won't have that database created). -
tollbooth almost 9 yearsHad to restart mysql after completing the above steps for this to work for me.
-
ryantuck over 8 yearsi was able to do this without restarting the
mysql
service at the end -
Gank over 8 yearsERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwoYES)Y
-
sgarg about 8 yearsShould \*.\* be *.* ?
-
Adam B about 8 years
FLUSH PRIVILEGES
should allow you to not need to restart. -
Sorin Postelnicu over 7 yearsDo you have to create username@localhost? Is it not enough if you just create username@% ? I mean, if you just create username@%, will you not be able to connect with that user from localhost?
-
Bratchley about 7 yearsyeah creating a
@localhost
would make sense if the privileges were different somehow but here they're the same and it's probably going to be more confusing than anything (such as changing passwords on one not realizing the other exists and that your login might be hitting that one). -
Lanklaas almost 7 yearsThis helped me combined with this: GRANT ALL PRIVILEGES ON . TO 'root'@'%' WITH GRANT OPTION;
-
hellowahab over 6 yearsThanks. Using GRANT ALL PRIVILEGES ON . TO 'root'@'%' helped me resolve the error
-
Erica Kane over 6 yearsThis is a correct answer for root, which always has a localhost entry. However, if you are creating a brand new, non-root user, you do not need to add a localhost entry. Just issue one command creating the user with % as the hostname.
-
dataviews over 5 yearswhat does the % signify?
-
devugur over 5 yearsit's like everything. You can thing like example:
WHERE CustomerName LIKE 'a%'
- Finds any values that start with "a" -
Muhammad Nayab over 5 yearsas a beginner it really helped me
-
Alliswell over 5 yearsDon't forget
FLUSH PRIVILEGES;
to apply changes -
FreeText over 5 yearsThis worked for me for MySQL 5.5 on Windows 10 with FLUSH PRIVILEGES, without restarting the service . On Windows, the service's properties should identify the my.ini file used for configuration (Properties | General | Path to executable)
-
Zulqarnain about 5 yearsthank it solves my "SQLSTATE[HY000] [1130] Host 'DESKTOP-xxx.xx' is not allowed to connect to this MariaDB server" in containerized laravel application in windows
-
Gabriel Augusto over 4 yearsWhat can I do if I cannot even get into mysql with the command mysql -u root -p? or even phpmyadmin (using xampp)
-
Henno over 4 yearsI assumed that by specifying bind-address="0.0.0.0" it would listen on all interfaces and remote connections would work but I was wrong. Yes, netstat showed that mysql was listening on 0.0.0.0 (all interfaces) but I was getting the error in the question title. Once I removed the bind-address line completely, it started working. Weird.
-
Shashikant Soni over 4 yearsYou are my hero for the day!! Thanks a lot. I was trying to connect from a docker container to a localhost mysql and this is the only change that worked
-
Moeez about 4 yearsnot working in my case. see my question stackoverflow.com/questions/62097919/…
-
AndiAna almost 4 yearsi tried this but after doing that i get this error when i test the connection: 2059 - Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(../Frameworks/caching_sha2_password.so, 2): image not found
-
Nicholas Saunders almost 4 yearswould this also work for similar problems with docker? devops.stackexchange.com/q/12449/23443
-
phagento about 3 yearsRead the question properly first before answering. Your answer is unrelated and does not help at all!
-
Always Sunny about 3 yearsHow to do with mysql docker container?
-
Lancer.Yan over 2 yearsSir ! Thank you very much for your answer, it worked for me; simple and fast!
-
vr_driver over 2 yearsThis needs to be added to the MAMP for Mac help file I think. Still works in 2021
-
HPWD about 2 yearsHow would you remove access? For example, yesterday my IP from home was one value but I had to restart my modem and now I have a new IP. I'd like to remove the old IP and add the new one.
-
Sushil about 2 yearsgives SQL syntax error