This should be dead simple, but I cannot get it đồ sộ work for the life of u.
I'm just trying đồ sộ connect remotely đồ sộ 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 đồ sộ connect đồ sộ 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' kết thúc and have no idea how đồ sộ 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 đồ sộ have a user with this kind of access open đồ sộ 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 đồ sộ insert a new entry with Host='%' and User='some_user', thinking that this allows you đồ sộ 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 than vãn '%', it is used in preference đồ sộ the new entry when connecting from localhost! The correct procedure is đồ sộ insert a second entry with Host='localhost' and User='some_user', or đồ sộ delete the entry with Host='localhost' and User=''. After deleting the entry, remember đồ sộ issue a FLUSH PRIVILEGES statement đồ sộ 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 đồ sộ 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 đồ sộ connect đồ sộ this MySQL server' even though I was using root. Here's how đồ sộ 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 đồ sộ open đồ sộ 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 đồ sộ change permissions on database 'dataentry'. Remember đồ sộ change the IP Address, Port, and database name đồ sộ your settings)

    mysql -u root -p
    Enter password: 
    mysql>GRANT ALL ON *.* đồ sộ 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 đồ sộ remote connect đồ sộ 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 đồ sộ 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 đồ sộ grant access đồ sộ 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 *.* đồ sộ '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 đồ sộ connect đồ sộ this MySQL server is a reply from the MySQL server đồ sộ the MySQL client. Notice how its returning the IP address and not the hostname.

If you're trying đồ sộ connect with mysql -h -u -p and it returns this message with the IP address, then the MySQL server isn't able đồ sộ vì thế a reverse lookup on the client. This is critical because thats how it maps the MySQL client đồ sộ the grants.

Make sure you can vì thế 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 đồ sộ the line that begins with the bind-address directive. It should look lượt thích this:

    bind-address            = 0.0.0.0

Login đồ sộ 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 đồ sộ connect đồ sộ the database remotely with the following command.

    sudo ufw allow from remote_IP_address đồ sộ 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 đồ sộ tell the server đồ sộ reload the grant tables.

PS: I wouldn't recommend đồ sộ allow any host đồ sộ 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 size with username, host matching (% means every host) and the password

  4. Click on "Apply" on the lower right

After this you are good đồ sộ go. Then, if you want đồ sộ refine your configuration, you can use the "Administrative Roles" tab đồ sộ mix the command that can be used by the user (SELECT, ALTER etc etc) and the "Schema privileges" tab đồ sộ restrict the user interaction đồ sộ 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 đồ sộ 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 đồ sộ vì thế this. If you simply want đồ sộ 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 đồ sộ grant administrative privileges đồ sộ a user from any domain name.)

answered Oct 12, 2017 at 21:49

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

Login đồ sộ your SQL server from a terminal

 mysql -u root -p
 -- root password
GRANT ALL ON *.* đồ sộ 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 đồ sộ login đồ sộ phpmyadmin with root tài khoản , there goto mysql database and select user table , there edit root tài khoản 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 đồ sộ allow users from other locations(x.x.x.x in your case) as well from where you are going đồ sộ connect đồ sộ the database.

All the above answers vì thế seem correct in the wildcard(%) declaration for allowing hosts from all locations but that opens it đồ sộ all hosts and hence opening a security risk. Its better đồ sộ 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 đồ sộ execute this command and then try again:

flush privileges;

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

answered Nov 22, 2017 at 5:54

Just find a better way đồ sộ vì thế that from your hosting control panel (I'm using DirectAdmin here)

simply go đồ sộ 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 đồ sộ you too.

answered May 19, 2018 at 6:35

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

Suppose you are trying đồ sộ connect database of server B from server A. Go đồ sộ 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 đồ sộ be running on Windows; A simple solution is đồ sộ lập cập 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 đồ sộ your MySQL running container

docker exec -it your_container_name_or_id bash

2. In your container, connect you đồ sộ the MySQL database

mysql -u your_user -p

enter your password đồ sộ connect đồ sộ database.

3. execute this SQL script đồ sộ 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 đồ sộ the root , and this Maybe occurred with you when you trying đồ sộ connect from outside .

answered Mar đôi mươi, 2019 at 21:20

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

answered May 8, 2020 at 9:59