MySQL external access for localhost - mysql

I need to connect a desktop application to a MySQL server. The website connect to the database 'localhost'. What would the the full path of the localhost be?
Using CentOS 6.5/apache/zpanel
The answer is probably so obvious that nobody has ever asked it before. But I rally can't figure it out. Here is the screenshot of what I have:

It's the IP address of the server which is running mysql (the same of the webserver, if you're connecting to it as localhost)
But many hosting companies disable remote MySQL by default, you may need to ask them to enabled it, or to whitelist the IP you are connecting from.

You have to grant access to the user you are using to connect from remote, on your case the root user so:
GRANT ALL PRIVILEGES ON *.* TO 'root'#'%'
IDENTIFIED BY 'password' WITH GRANT OPTION;
After this run this other command to refresh the new privileges
FLUSH PRIVILEGES;
The '%' is the option that you allow root to connect from anywhere. You can specify also an IP address.

Related

How to set MySql grant to allow external connection to MySql?

I am not so into DB and I have the following problem.
I have installed a MySql 5.7.17 on a remote Ubuntu 16.04 server and I have to connect to this server from a client installed on my laptop.
So The first thing that I have done is that I have changed the bind-address directive values (into the /etc/mysql/mysql.conf.d/mysqld.cnf file) from:
Bind-address=127.0.0.1
to:
bind-address = 0.0.0.0
to allow also external connection.
The problem is that when I try to connect from my client (installed on my laptop) I obtain this error:
Host 'XXX.YYY.ZZ.JJ' is not allowed to connect to this MySQL server
(where **XXX.YYY.ZZ.JJ* is my laptop IP address).
From what I have understood I also have to give to the mysql user w the db permissions to connect from any host and not just from localhost.
I think that it should be something related to the grant: https://dev.mysql.com/doc/refman/5.5/en/grant.html
What exactly have I to do? I think that I have to access to MySql from my server shell (via SSH) and then perform a query that grant some privileges to the root user (the MySql user) to allow to access from outside.
But I don't know what exactly I have to do. How can I allow this external connection for the roo user?
As you mentioned, you need to login to mysql server with root access and then run following command on mysql prompt
GRANT ALL PRIVILEGES ON your_db_name.* TO 'your_db_user_name'#'%' IDENTIFIED BY 'newpassword';
you can also specify a specific IP instead of %
GRANT ALL PRIVILEGES ON your_db_name.* TO 'your_db_user_name'#'your_IP_here' IDENTIFIED BY 'newpassword';
you can also specify a for all databases
GRANT ALL PRIVILEGES ON *.* TO 'your_db_user_name'#'your_IP_here' IDENTIFIED BY 'newpassword';

how to connect to (private) IP adress MySQL Server?

I have a MySQL Server on some workplace running, now I want to connect to it from my homeplace, get the databases, etc...
I have the IPAdress of the workplace computer, but I cannot get access to it from my home MySQL Program if I enter the ip-adress in the connection string...
seems not to be accessible from publice.. is it possible to do it nevertheless? or impossible?
With MySQL you need to grant access to the IP you're trying to connect to it from..
GRANT USAGE ON *.* to root#xxx.xxx.xxx.xxx IDENTIFIED BY 'rootPassword';
GRANT ALL PRIVILEGES ON *.* TO root#xxx.xxx.xxx.xxx WITH GRANT OPTION;
Where XXX.XXX.XXX.XXX is the IP of the machine your trying to connect from, which you can find out by typing in google, "whatsmyip"
If you have a firewall enabled on your workstation, you also must permit your IP in the firewall as well.
You need also change bind-address in MySQL configuration. Default MySQL is running on localhost (127.0.0.1), you need change it to 0.0.0.0 (all interfaces).
If you don't have public address IP, you need use some VPN, read another topic: https://askubuntu.com/questions/64016/access-workstations-without-public-ip-maybe-with-vpn

Cannot connect to mysql localhost

I am a neewbie to Mac and web development.I have installed Apache and the web server is working just fine. When I type localhost, it says "It Works". Also I am able to connect to company's database via workbench.
But when I try to create a local connection using hostname: 127.0.0.1 it says: Access denied for user 'root'#'localhost' (using password: NO). I am not sure if in resolving this issue whether I changed the password or not.
Any help would be great.
Thanks
You need to configure your firewall to allow other machines to access the PC running Apache. For OSX: http://www.cnet.com/how-to/how-to-enable-web-sharing-in-os-x-mountain-lion/
You can find the IP address of your Apache machine by pressing Start, type cmd. In the command window type: ipconfig /all EDIT: just realized you mentioned you were on Mac, use this link to find your IP: http://www.wikihow.com/Find-Your-IP-Address-on-a-Mac
When you have the IP of your Apache machine and set the firewall up to allow Apache to get through on likely port 80, you can access it from other PC's or devices on your local network: http://192.168.1.123/ for example if that's your IP.
127.0.0.1 is the local-loopback IP. Specifically for OSX this would directly answer your question: https://superuser.com/questions/512786/why-does-localhost-and-127-0-0-1-resolve-to-different-locations-on-mac-osc-10-8
I'm with the same problem time ago, you need to give privileges to the users to connect to the localhost, is different localhost from apache to mysql permissions
Possibly a security precaution. You could try adding a new administrator account:
mysql> CREATE USER 'yorsh'#'localhost' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yorsh'#'localhost'
-> WITH GRANT OPTION;
mysql> CREATE USER 'yorsh'#'%' IDENTIFIED BY 'some_pass';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yorsh'#'%'
-> WITH GRANT OPTION;
FLUSH PRIVILEGES;

Cant Connect to MySQL over network

I'm in the process of setting up a MySQL server. I set up the server as localhost on port 3306. However I want to be able to access this server over the network. The server has a static IP address. How can I change it from localhost to the static IP address?
I already did this suggestion I found online, and it didn't work:
mysql> GRANT ALL ON *.* to root#'localhost' IDENTIFIED BY 'your-root-password';
mysql> FLUSH PRIVILEGES;
When I try to access it from the server or another PC, I get this error:
Failed to Connect to MySQL at XXXXXX:3306 with user root
HOST 'XXXXXXX' is not allowed to connect to this MySQL server
Thank You.
In addition to the GRANT statement you've already listed above, you also need this one to connect from somewhere other than localhost
GRANT ALL ON *.* to root#'%' IDENTIFIED BY 'your-root-password';
In MySQL land user#somehost is, in practice, a different user than user#some-other-host.

Access denied for user 'user'#'host' (using password: YES)

I have a created user in my MySQL database:
CREATE USER 'user'#'host' IDENTIFIED BY 'password';
I have granted that user full privileges:
GRANT ALL ON *.* to 'user'#'host';
Echoing the grant:
GRANT ALL PRIVILEGES ON *.* TO 'user'#'host' IDENTIFIED BY PASSWORD '*03FFC888F82E921D8CA360925A8F443CF326DE89'
I can connect from MySQL workbench using this login credential w/o any issues and execute queries. And it's running on the same machine the web application is running on. MySQL instance is running on another computer in the same local network.
However, when I try to use the same credentials from my web application running in Tomcat7 under Eclipse I receive the error. Please advise.
Note: As of last night, the web application was able to connect just fine. With nothing changing (that I am aware of - I am only one working on this), this morning I could not connect.
RESOLVED:
I added the user with grants using the IP address for the host for the local machine.
I am not sure what changed on the server, but now I am able to connect again.
Would someone possibly be able to explain this change, and with it why I am now required to use the IP address when previously the local host name was sufficient?
Make sure you are using the appropriate hostname, and you're accessing from that host, the user can't connect from another host.
To give permission you must put the password unencrypted.
Example
GRANT ALL PRIVILEGES ON test. * TO 'root' # 'localhost'
IDENTIFIED BY 'goodsecret';
Also must be the same password when you create the user.
Here How adding users to MySQL
Note: For more information on GRANT here is the documentation.
Hope this helps