This should be dead simple, but I cannot get it đồ sộ work for the life of bầm.
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
concept47concept47
31.6k12 gold badges53 silver badges78 bronze badges
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 thở '%', 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
Yannick MottonYannick Motton
35.9k4 gold badges40 silver badges55 bronze badges
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
Aditya P.. BhattAditya P.. Bhatt
22k20 gold badges87 silver badges104 bronze badges
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
Open up the tệp tin under
etc/mysql/my.cnf
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)
- port (by mặc định this is
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 sudo service mysqld restart
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
WillWill
11.5k9 gold badges70 silver badges77 bronze badges
6
Just perform the following steps:
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
Create user
CREATE USER 'user'@'%' IDENTIFIED BY 'password';
Grant permissions
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;
Flush privileges
FLUSH PRIVILEGES;
answered Mar 24, năm trước at 9:27
minhas23minhas23
9,6116 gold badges59 silver badges40 bronze badges
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
Select Any Host for the desired username
answered Jun 21, 2013 at 11:42
HimalayanCoderHimalayanCoder
9,8307 gold badges61 silver badges61 bronze badges
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
devugurdevugur
1,4991 gold badge22 silver badges26 bronze badges
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
and it returns this message with the IP address, then the MySQL server isn't able đồ sộ bởi a reverse lookup on the client. This is critical because thats how it maps the MySQL client đồ sộ the grants.
Make sure you can bởi 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
Pascal ThiventPascal Thivent
570k140 gold badges1.1k silver badges1.1k bronze badges
If you are using MySQL WorkBench, you can achieve this easily:
From the thực đơn, select Server -> Users And Privileges
On the lower left, click on "Add account"
Fill the khuông with username, host matching (% means every host) and the password
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
BabaNewBabaNew
9761 gold badge15 silver badges31 bronze badges
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
BabaNewBabaNew
9761 gold badge15 silver badges31 bronze badges
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ộ bởi 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
Erica KaneErica Kane
3,35229 silver badges38 bronze badges
Well, nothing of the above answer worked for bầm. 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
Pratap SharmaPratap Sharma
2,7432 gold badges22 silver badges36 bronze badges
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 nhâm thìn at 10:52
user889030user889030
4,7244 gold badges58 silver badges54 bronze badges
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 bởi 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 bầm on Ubuntu 16.04, mysql 5.7.20. YMMV.
answered Nov 22, 2017 at 5:54
Alex RAlex R
11.8k18 gold badges111 silver badges198 bronze badges
Just find a better way đồ sộ bởi 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
Eran LeviEran Levi
9072 gold badges14 silver badges31 bronze badges
I was also facing same issue, It resolved in 2 min for bầm 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 nhâm thìn at 14:18
JanJan
3294 silver badges12 bronze badges
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
Abd AbughazalehAbd Abughazaleh
5,4695 gold badges56 silver badges59 bronze badges
If you have WAMP Server + Windows 10 and you are using it for development than thở Right Click on Wamp Icon => Wamp Settings
=> Check Allow Virtual Hosts other than thở 127*
answered May 8, 2020 at 9:59
AdrianAdrian
2,2915 gold badges42 silver badges79 bronze badges