Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server

1,815,195

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

  1. Open up the file under 'etc/mysql/my.cnf'
  2. 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)
  3. 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
    
  4. sudo service mysqld restart

  5. 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
  1. Create user

    CREATE USER 'user'@'%' IDENTIFIED BY 'password';

  2. Grant permissions

    GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;

  3. 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

enter image description here

Select Any Host for the desired username

enter image description here

Share:
1,815,195
concept47
Author by

concept47

Ruby/Rails/jQuery hacker. Elasticsearch enthusiast.

Updated on July 08, 2022

Comments

  • concept47
    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
    Corey Ballou over 14 years
    Good catch Yannick, however I would not recommend him granting all privileges to a non-root user. Perhaps a reduced set?
  • Yannick Motton
    Yannick Motton over 14 years
    Well, 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
    Yannick Motton over 14 years
    I 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
    Devanshu Mevada over 14 years
    That'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
    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
    axon over 10 years
    This 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
    Kishan Bheemajiyani over 10 years
    But this is address which will allow all the Host to get connected to the server na?
  • Kishan Bheemajiyani
    Kishan Bheemajiyani over 10 years
    But 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
    Gustavo Guevara almost 10 years
    I 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
    jazzy about 9 years
    You can skip the use dataentry line (since most people won't have that database created).
  • tollbooth
    tollbooth almost 9 years
    Had to restart mysql after completing the above steps for this to work for me.
  • ryantuck
    ryantuck over 8 years
    i was able to do this without restarting the mysql service at the end
  • Gank
    Gank over 8 years
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwoYES)Y
  • sgarg
    sgarg about 8 years
    Should \*.\* be *.* ?
  • Adam B
    Adam B about 8 years
    FLUSH PRIVILEGES should allow you to not need to restart.
  • Sorin Postelnicu
    Sorin Postelnicu over 7 years
    Do 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
    Bratchley about 7 years
    yeah 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
    Lanklaas almost 7 years
    This helped me combined with this: GRANT ALL PRIVILEGES ON . TO 'root'@'%' WITH GRANT OPTION;
  • hellowahab
    hellowahab over 6 years
    Thanks. Using GRANT ALL PRIVILEGES ON . TO 'root'@'%' helped me resolve the error
  • Erica Kane
    Erica Kane over 6 years
    This 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
    dataviews over 5 years
    what does the % signify?
  • devugur
    devugur over 5 years
    it's like everything. You can thing like example: WHERE CustomerName LIKE 'a%' - Finds any values that start with "a"
  • Muhammad Nayab
    Muhammad Nayab over 5 years
    as a beginner it really helped me
  • Alliswell
    Alliswell over 5 years
    Don't forget FLUSH PRIVILEGES; to apply changes
  • FreeText
    FreeText over 5 years
    This 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
    Zulqarnain about 5 years
    thank 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
    Gabriel Augusto over 4 years
    What can I do if I cannot even get into mysql with the command mysql -u root -p? or even phpmyadmin (using xampp)
  • Henno
    Henno over 4 years
    I 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
    Shashikant Soni over 4 years
    You 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
    Moeez about 4 years
    not working in my case. see my question stackoverflow.com/questions/62097919/…
  • AndiAna
    AndiAna almost 4 years
    i 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
    Nicholas Saunders almost 4 years
    would this also work for similar problems with docker? devops.stackexchange.com/q/12449/23443
  • phagento
    phagento about 3 years
    Read the question properly first before answering. Your answer is unrelated and does not help at all!
  • Always Sunny
    Always Sunny about 3 years
    How to do with mysql docker container?
  • Lancer.Yan
    Lancer.Yan over 2 years
    Sir ! Thank you very much for your answer, it worked for me; simple and fast!
  • vr_driver
    vr_driver over 2 years
    This needs to be added to the MAMP for Mac help file I think. Still works in 2021
  • HPWD
    HPWD about 2 years
    How 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
    Sushil about 2 years
    gives SQL syntax error