This should be dead simple, but I cannot get it to tướng work for the life of bầm.
I'm just trying to tướng connect remotely to tướng 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 tướng connect to tướng 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 to tướng proceed. Any ideas are welcome.
miken32
42.7k16 gold badges121 silver badges171 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 to tướng have a user with this kind of access open to tướng 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 to tướng insert a new entry with Host='%' and User='some_user', thinking that this allows you to tướng 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 to tướng the new entry when connecting from localhost! The correct procedure is to tướng insert a second entry with Host='localhost' and User='some_user', or to tướng delete the entry with Host='localhost' and User=''. After deleting the entry, remember to tướng issue a FLUSH PRIVILEGES statement to tướng 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 to tướng 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 to tướng connect to tướng this MySQL server' even though I was using root. Here's how to tướng 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 to tướng open to tướng 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 to tướng change permissions on database 'dataentry'. Remember to tướng change the IP Address, Port, and database name to tướng your settings)mysql -u root -p Enter password:
mysql>GRANT ALL ON *.* to tướng 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 tướng remote connect to tướng 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 to tướng 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 to tướng grant access to tướng 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 *.* to tướng '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 to tướng connect to tướng this MySQL server
is a reply from the MySQL server to tướng the MySQL client. Notice how its returning the IP address and not the hostname.
If you're trying to tướng connect with mysql -h
and it returns this message with the IP address, then the MySQL server isn't able to tướng bởi a reverse lookup on the client. This is critical because thats how it maps the MySQL client to tướng 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 to tướng the line that begins with the bind-address directive. It should look lượt thích this:
bind-address = 0.0.0.0
Login to tướng 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 to tướng connect to tướng the database remotely with the following command.
sudo ufw allow from remote_IP_address to tướng 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 to tướng tell the server to tướng reload the grant tables.
PS: I wouldn't recommend to tướng allow any host to tướng 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 size with username, host matching (% means every host) and the password
Click on "Apply" on the lower right
After this you are good to tướng go. Then, if you want to tướng refine your configuration, you can use the "Administrative Roles" tab to tướng phối the command that can be used by the user (SELECT, ALTER etc etc) and the "Schema privileges" tab to tướng restrict the user interaction to tướng 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 to tướng 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 to tướng bởi this. If you simply want to tướng 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 to tướng grant administrative privileges to tướng 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 to tướng your SQL server from a terminal
mysql -u root -p
-- root password
GRANT ALL ON *.* to tướng 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 to tướng login to tướng 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
user889030user889030
4,7344 gold badges58 silver badges54 bronze badges
1
You need to tướng allow users from other locations(x.x.x.x in your case) as well from where you are going to tướng connect to tướng the database.
All the above answers bởi seem correct in the wildcard(%) declaration for allowing hosts from all locations but that opens it to tướng all hosts and hence opening a security risk. Its better to tướng 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 to tướng 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 badges112 silver badges198 bronze badges
Just find a better way to tướng bởi that from your hosting control panel (I'm using DirectAdmin here)
simply go to tướng 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 to tướng 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 to tướng connect database of server B from server A. Go to tướng 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 to tướng be running on Windows; A simple solution is to tướng 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
JanJan
3294 silver badges12 bronze badges
1. From a terminal, connect you to tướng your MySQL running container
docker exec -it your_container_name_or_id bash
2. In your container, connect you to tướng the MySQL database
mysql -u your_user -p
enter your password to tướng connect to tướng database.
3. execute this SQL script to tướng 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 to tướng the root , and this Maybe occurred with you when you trying to tướng 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 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
AdrianAdrian
2,2915 gold badges42 silver badges79 bronze badges