I have a database server and an application server and trying to connect my application server the remote database server using PHP.
As usual I used the following way to it in the following manner.
<?php
mysql_connect("remotedb.com", "mysqladmin", "mysqlpassword") or die(mysql_error());
echo "Connected to MySQL<br />";
?>
But when I am trying to run this test I am getting the following error.
Warning: mysql_connect() [function.mysql-connect]: Host 'gator418.hostgator.com' is not allowed to connect to this MySQL server in /home/username/public_html/testmysql.php on line 2
Host 'gator418.hostgator.com' is not allowed to connect to this MySQL server
I have added the domain as %www.myappserver.com% to the remote server's cpanel "Remote MySQL" but still the issue persists. Can anyone tell me why am I getting this error?
Remote database username is not allowed to connect using your host. Most probably it is set to only be able to connect from "localhost", so check the details of your username on your mysql server and see the list of allowed hosts
Try this first from your local machine
$ mysql -h gator418.hostgator.com -u root -p
Enter password:
ERROR 1130: Host '192.168.1.4' is not allowed to connect to this MySQL server
If you are getting above error do the below codes
Do this in your server.
$ mysql -u root -p
Enter password:
mysql> use mysql
mysql> GRANT ALL ON *.* to mysqladmin#'gator418.hostgator.com' IDENTIFIED BY 'mysqlpassword';
mysql> FLUSH PRIVILEGES;
Also, update firewall rules to make sure port# 3306 is open on the server that is running the mysql database.
After the above changes, when you try to connect to the mysql database from a remote client, you’ll not get the “Host is not allowed to connect to this MySQL server” error message anymore.
This can be achievable from Cpanel also. Grant all permission to the user you have created. (For the particular database you want)
Related
MySQL newbie here,
I've installed MySQL on my Windows 10 machine and can connect using MySQL Workbench with the root username and everything works as promised.
However, now I want to create another user to connect with and give that user access to just one database on the server.
I've created the user with these commands:
CREATE USER 'user'#'localhost' IDENTIFIED BY 'f^rest_of_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'user'#'localhost';
FLUSH PRIVILEGES;
I've created the database with this command:
CREATE DATABASE wordpress
SO, now I tried to create a connection in MySQL Workbench using that user and the password and it fails.
The error message says:
Cannot Connect to Database Server
Your connection attempt failed for user 'user' to the MySQL server at localhost:3306
Please:
1 Check that MySQL is running on address localhost
2 Check that MySQL is reachable on port 3306 (note: 3306 is the default, but this can be changed)
3 Check the user user has rights to connect to loclahost from your address (MySQL rights define what clients can connect to the server and from which machines)
4 Make sure you are both providing a password if needed and using the correct password for loclahost connecting from the host address you're connecting from
What is my next move?
Thanks,
Owen
As soon as I post a question....
Turns out I needed to specify the "Installation Type" of custom,
the "Configuration File Section" of mysqld
and the "Windows Service Name" of MySQL80
(Ended up copying the working root connection and changing the username and password).
I have a strange issue on a web server (Windows Server 2012) with MySQL 5.7.16.
I can't connect anymore to mysql server, I don't know why.
If I type mysql -uroot -ppassword appear an error
ERROR 1130 <HY000>: Host '::1' is not allowed to connect to this MySQL server or
ERROR 1130 <HY000>: Host '127.0.0.1' is not allowed to connect to this MySQL server
I tried to use another user with all privileges and I've seen that in host there is only localhost (not 127.0.0.1 or ::1)
How can I login with root#localhost and not with root#127.0.0.1?
It's very frustrating...
Every account trying to use #127.0.0.1 or #::1 but there exist only localhost in host and I can't change it.
If I type mysql -uroot -ppassword I see
ERROR 1130 <HY000>: Host '127.0.0.1' is not allowed to connect to this MySQL server
Same if I type mysql -uroot -ppassword -h localhost or anything else
Ok i Fixed...
I've comment "skip_name_resolve" in my.ini and everything is back to work.. i really don't know why because this record was in my.ini also yesterday..last week.. last month..
The variable skip_name_resolve gives better performance because the server does not try to resolve the names of the connecting clients or look for them every time in the host name cache (even localhost is resolved/searched), but the manual states that config also limits the #localhost connections. The solution is to copy the #localhost users with #127.0.0.1, like this:
CREATE USER 'root'#'127.0.0.1' IDENTIFIED BY 'root-password';
CREATE USER 'root'#'::1' IDENTIFIED BY 'root-password';
FLUSH PRIVILEGES;
where ::1 is localhost for IPv6 addressing. This way we keep the root and local accounts limited to the local server. Using '%' open the potential clients to the world, and we don't want that. Disabling skip_name_resolve also requires the server having an accesible and fast DNS resolver to minimize latency.
I noted that I can connect with a local phpmyadmin even if the user has #localhost; this is because phpmyadmin connects thru a local unix socket, a special type of file used to communicate between processes, and does not need networking.
EDIT: As #Francisco R noted, the new root users also should have full access to all databases by issuing the following commands:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'127.0.0.1'
GRANT ALL PRIVILEGES ON *.* TO 'root'#'::1'
FLUSH PRIVILEGES
I had the same message after a fresh installation with the no-install zip and solved it as follows. Perhaps this could have been a solution for your problem too:
Stop the MySQL server or service.
Open a Command Prompt window with administrative rights and go to the bin folder in the MySQL install directory.
Start MySQL with skip-grants-table and don't forget your config file:
mysqld --defaults-file=[filename] --skip-grant-tables
Open another Command Prompt window and go to the bin folder again.
Now you can login:
mysql -u root -p
Show the users with:
SELECT user, host FROM mysql.user;
Verify there is one 'root' with host 'localhost'.
Change the host:
UPDATE mysql.user SET host='%' WHERE user='root';
Exit the mysql program and close the Command Prompt window.
Type Ctrl-C in the other Command Prompt window to stop the server, then close the Command Prompt Window.
Start MySQL as you normally would and verify that you can login.
Make sure that when you created the user you have specified % as the hostname, otherwise the user will only be able to connect from the localhost.
I came here looking for a solution using Local by flywheel for wordpress development to the same problem, BUT, in a linux machine.
Just if someone faces the same problem, the solution listed here works.
Just comment skip_name_resolve in the file conf/mysql/my.cnf.hbs under the file tree created by Local
Thanks!
Looks that you need to modify your hosts file. C:\Windows\System32\Drivers\etc\hosts
just add the line and save it, (to be able to edit and save you may need to open it as administrator)
127.0.0.1 localhost
I searched a lot but not able to solve that problem.
i am able to access MySQL server running on different windows machine. steps i have taken are
changing my.ini file bind address to 0.0.0.0
creating user and granting permission by GRANT ALL PRIVILEGES ON DATABASE.* TO user#'%' IDENTIFIED BY 'password';
from command line to windows MySQL server mysql -h windows server ip -u user -p
it works fine and from MySQL workbench i am able to connect for windows MySQL server from my machine. BUT when in Linux virtual machine i have done the same thing
changing my.cnf file and change bind address to 0.0.0.0.
creating user and granting permission by GRANT ALL PRIVILEGES ON DATABASE.* TO user#'%' IDENTIFIED BY 'password';
From command line to LINUX MySQL server mysql -h linux server ip -u user -p
but for that i am getting following error after giving password ERROR 2003 (HY000): Can't connect to MySQL server on 'linux server ip' (10060) also when connecting from c# by following connection string <add name="MySqlConnection" connectionString="Server=LINUX_VM_SERVER_IP;Database=database;Uid=user;Pwd=password" providerName="MySql.Data.MySqlClient" />
i am getting Error : Unable to find and specified mysql host
i have checked in LINUX_VM that 0.0.0.0:3306 is in listening status.
if i try to telnet LINUX_VM MYSQL Server service using />telnet
LINUX_VM_IP 3306 i got the ERROR : Connecting To
LINUX_VM_IP...Could not open connection to the host, on port 3306:
First, try to connect to the database on the VM hosting the database. If the connection is successful, then the configuration of the database is correct. Otherwise, please check the configuration of your database.
Second, if you are able to connect to database on the VM, then the most possible cause of this issue is firewall. Please check if the local firewall (iptables) allows inbound connection on port 3306. For test purpose, you may disable the firewall temporarily. Also, please check if the NSG has been configured properly to allow the inbound traffic on port 3306.
Besides, if the VNET has been associated with a NSG, then we need to allow the inbound traffic in the NSG too.
I am running MySQL on an Amazon AWS Instance. I was able to previously connect to the MySQL Database via MySQL Query Browser. Now I am traveling outside the U.S. and I am having trouble connecting via the Query Browser. I am able to use Terminal to create an ssh connection and then login to MySQL, so it does not appear to be a larger issue with the MySQL Database.
Has anyone else had a similar problem? Any ideas how I can fix this?
This is the error I get from the MySQL Browser
Your connection attempt
failed for user 'admin' from your host to server at
ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com:3306: Can't connect to
MySQL server on 'ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com' (4)
Please: 1 Check that mysql is running on server
ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com
2 Check that mysql is
running on port 3306 (note: 3306 is the default, but this can be
changed)
3 Check the admin has rights to connect to
ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com from your address (mysql
rights define what clients can connect to the server and from which
machines)
4 Make sure you are both providing a password if needed and
using the correct password for
ec2-XXX-XXX-XXX-XXX.compute-1.amazonaws.com connecting from the host
address you're connecting from
The only possible problem I see could be #4, but I ran and re-ran this command via Terminal:
grant all privileges on *.* to 'admin'#'%' identified by '<pass>' with grant option;
I am trying to connect to my mysql database on a remote server (via ssh) through the command:
mysql -u me -h mydomain.com -p
But it fails with a ERROR 1045 (28000): Access denied for user.. error
While
mysql -u me -h localhost -p
Works
Now this isn't just because I have not setup permissions, because the permissions to this database are set for % or any host for the me user.
This is proved by the fact that I can connect correctly from my local machine to the server, using the same user. i.e. running the following command from my local machine works:
mysql -u me -h mydomain.com -p
So my question why does this happen and how can I fix it? Why can I not connect to my mysql server from my server when I use the domain name instead of localhost, even though the permissions are setup to accept connections from any host.
This happens because of the way MySQL handles permission grants.
When you connect from a remote host (or from the local host via an external IP), it will match the me#% entry (if there is no specific grant for the particular host you're using!). But when you connect via the loopback interface (the "localhost" IP) or a socket, it will use the me#localhost grant. So you must have two GRANT PRIVILEGES; one for me#localhost and one for me#%.