This should be dead simple, but I cannot get it lớn work for the life of má.
I'm just trying lớn connect remotely lớn 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 lớn connect lớn 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' over and have no idea how lớn proceed. Any ideas are welcome.

miken32

42.7k16 gold badges121 silver badges170 bronze badges

asked Oct 13, 2009 at 12:40

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 lớn have a user with this kind of access open lớn 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.

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 lớn insert a new entry with Host='%' and User='some_user', thinking that this allows you lớn specify localhost to connect from the same machine. The reason that this does not work is that the mặc định privileges include an entry with Host='localhost' and User=''. Because that entry has a Host value 'localhost' that is more specific phàn nàn '%', it is used in preference lớn the new entry when connecting from localhost! The correct procedure is lớn insert a second entry with Host='localhost' and User='some_user', or lớn delete the entry with Host='localhost' and User=''. After deleting the entry, remember lớn issue a FLUSH PRIVILEGES statement lớn reload the grant tables. See also Section 5.4.4, “Access Control, Stage 1: Connection Verification”.

Dharman

33.1k27 gold badges99 silver badges146 bronze badges

answered Oct 13, 2009 at 12:47

10

One has lớn 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

answered Sep 16, 2013 at 5:56

8

My error message was similar and said 'Host XXX is not allowed lớn connect lớn this MySQL server' even though I was using root. Here's how lớn make sure that root has the correct permissions.

My setup:

  • Ubuntu 14.04 LTS
  • MySQL v5.5.37

Solution

  1. Open up the tệp tin under etc/mysql/my.cnf

  2. Check for:

    • port (by mặc định this is port = 3306)
    • bind-address (by mặc định this is bind-address = 127.0.0.1; if you want lớn open lớn 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 lớn change permissions on database 'dataentry'. Remember lớn change the IP Address, Port, and database name lớn your settings)

    mysql -u root -p
    Enter password: 
    mysql>GRANT ALL ON *.* lớn 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 lớn remote connect lớn your database. For example, I'm using MySQL Workbench and putting in 'Hostname:10.1.1.7', 'Port:3306', 'Username:root'

Manuel Jordan

16.2k25 gold badges105 silver badges182 bronze badges

answered Jun 11, năm trước at 19:31

6

Just perform the following steps:

  1. Connect lớn MySQL (via localhost)

    mysql -uroot -p
    
    • 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;
    

answered Mar 24, năm trước at 9:27

6

You need lớn grant access lớn the user from any hostname.

This is how you add new privilege from phpmyadmin

Goto Privileges > Add a new User

enter image mô tả tìm kiếm here

Select Any Host for the desired username

enter image mô tả tìm kiếm here

answered Jun 21, 2013 at 11:42

1

Simple way:

Grant All Privileges ON *.* lớn 'USER_NAME'@'%' Identified By 'YOUR_PASSWORD'; 

then

FLUSH PRIVILEGES;

done!

answered Nov 24, 2018 at 8:05

4

The message *Host ''xxx.xx.xxx.xxx'' is not allowed lớn connect lớn this MySQL server is a reply from the MySQL server lớn the MySQL client. Notice how its returning the IP address and not the hostname.

If you're trying lớn connect with mysql -h -u -p and it returns this message with the IP address, then the MySQL server isn't able lớn tự a reverse lookup on the client. This is critical because thats how it maps the MySQL client lớn the grants.

Make sure you can tự an nslookup FROM the MySQL server. If that doesn't work, then there's no entry in the DNS server. Alternatively, you can put an entry in the MySQL server's HOSTS tệp tin ( <- The order here might matter).

An entry in my server's host tệp tin allowing a reverse lookup of the MySQL client solved this very problem.

answered Mar 13, 2012 at 13:37

1

This working for any future remote mysql connection !

    sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Navigate lớn the line that begins with the bind-address directive. It should look lượt thích this:

    bind-address            = 0.0.0.0

Login lớn your mysql as root terminal

    mysql -u root -p
    -- root password

    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;

    EXIT;

finally Grant that machine exclusive permission lớn connect lớn the database remotely with the following command.

    sudo ufw allow from remote_IP_address lớn any port 3306

answered Jun 3, 2020 at 13:14

1

If you modify the grant tables manually (using INSERT, UPDATE, etc.), you should execute a FLUSH PRIVILEGES statement lớn tell the server lớn reload the grant tables.

PS: I wouldn't recommend lớn allow any host lớn connect for any user (especially not the root use). If you are using mysql for a client/server application, prefer a subnet address. If you are using mysql with a trang web server or application server, use specific IPs.

answered Oct 13, 2009 at 12:56

If you are using MySQL WorkBench, you can achieve this easily:

  1. From the thực đơn, select Server -> Users And Privileges

  2. On the lower left, click on "Add account"

  3. Fill the sườn with username, host matching (% means every host) and the password

  4. Click on "Apply" on the lower right

After this you are good lớn go. Then, if you want lớn refine your configuration, you can use the "Administrative Roles" tab lớn phối the command that can be used by the user (SELECT, ALTER etc etc) and the "Schema privileges" tab lớn restrict the user interaction lớn specific schemas.

answered Mar 23, 2021 at 17:32

Just use the interface provided by MySql's GUI Tool (SQLyog):

Click on User manager:

Now, if you want lớn grant access FOR ANY OTHER REMOTE PC, just make sure that, just lượt thích in the underneath picture, the Host field value is % (which is the wildcard)

answered Sep 27, 2017 at 13:09

Most of the answers here show you creating users with two host values: one for localhost, and one for %.

Please note that except for a built-in localhost user lượt thích root, you don't need lớn tự this. If you simply want lớn make a new user that can log in from anywhere, you can use

CREATE USER 'myuser'@'%' IDENTIFIED BY 'mypassword';
GRANT  ON  TO myuser;

and it will work just fine. (As others have mentioned, it's a terrible idea lớn grant administrative privileges lớn a user from any tên miền.)

answered Oct 12, 2017 at 21:49

Well, nothing of the above answer worked for má. After a lot of research, I found a solution. Though I may be late this may help others in future.

Login lớn your SQL server from a terminal

 mysql -u root -p
 -- root password
GRANT ALL ON *.* lớn root@'XX.XXX.XXX.XX' IDENTIFIED BY 'password';

This should solve the permission issue.

Happy coding!!

answered Nov 21, 2019 at 18:29

simple way is lớn login lớn phpmyadmin with root trương mục , there goto mysql database and select user table , there edit root trương mục and in host field add % wild thẻ . and then through ssh flush privileges

 FLUSH PRIVILEGES;

answered Feb 21, năm 2016 at 10:52

1

You need lớn allow users from other locations(x.x.x.x in your case) as well from where you are going lớn connect lớn the database.

All the above answers tự seem correct in the wildcard(%) declaration for allowing hosts from all locations but that opens it lớn all hosts and hence opening a security risk. Its better lớn explicitly specify the host as follows:

CREATE USER 'username'@'x.x.x.x' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'x.x.x.x' WITH GRANT OPTION;

FLUSH PRIVILEGES;

Replace x.x.x.x with the host ip that you are connecting from.

answered Oct 18, 2023 at 8:00

If this is a recent mysql install, then before changing anything else, try simply lớn execute this command and then try again:

flush privileges;

This alone fixes the issue for má on Ubuntu 16.04, mysql 5.7.20. YMMV.

answered Nov 22, 2017 at 5:54

Just find a better way lớn tự that from your hosting control panel (I'm using DirectAdmin here)

simply go lớn the target server DB in your control panel, in my case: MySQL management -> select your DB -> you will find: "Access Hosts", simply add your remote host here and its working now!

I guess there is a similar option on other C.panels lượt thích plesk, etc..

I'm hope it was helpful lớn you too.

answered May 19, 2018 at 6:35

I was also facing same issue, It resolved in 2 min for má i just white list ip through cpanel

Suppose you are trying lớn connect database of server B from server A. Go lớn Server B Cpanel->Remote MySQL-> enter Server A IP Address and That's it.

answered Dec 4, năm trước at 22:37

If you happen lớn be running on Windows; A simple solution is lớn run rẩy the MySQL server instance configuration wizard. It is in your MYSQL group in the start thực đơn. On the second from last screen click the box that says "allow root access from remote machines".

answered Jun 22, năm 2016 at 14:18

1. From a terminal, connect you lớn your MySQL running container

docker exec -it your_container_name_or_id bash

2. In your container, connect you lớn the MySQL database

mysql -u your_user -p

enter your password lớn connect lớn database.

3. execute this SQL script lớn list all existing database users:

SELECT host, user FROM mysql.user;

The result will be some thing lượt thích below:

host user
127.0.0.1 root
::1 root
localhost mysql.sys
localhost root

you should add a new row:

CREATE USER 'username'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' WITH GRANT OPTION;

answered Jul 21, 2022 at 13:28

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;

this error because no password lớn the root , and this Maybe occurred with you when you trying lớn connect from outside .

answered Mar trăng tròn, 2019 at 21:20

If you have WAMP Server + Windows 10 and you are using it for development phàn nàn Right Click on Wamp Icon => Wamp Settings => Check Allow Virtual Hosts other phàn nàn 127*

answered May 8, 2020 at 9:59