Connect MySQL database behind firewall - php

There is a server I wish to connect to. It has multiple VMs running on it each VM has a mysql DB. I can currently connect to this server using ssh and then connect to any of the databases from each VM using mysql -u user -h host -p password. Now I want to connect to the same MySQL DBs using MySQL workbench from my local machine. However there is firewall, currently I use putty to get passed the firewall with public private key authentication and I can access any machine I want. I have seen here that I must install a MySQL server locally ( I've done this I am using mysql workbench) and use the loop-back address, in that way you don't need to access an external server. Could anyone point in the right direction on how to do this?

You need to use ssh tunnelling.
In putty under the options go to Connection->SSH->Tunnels. Add a tunnel from source port 13306 to Destination localhost:3306.
You can do this in Putty either before or after you connect. It's best to do beforehand and save the session configuration otherwise it gets tedious having to re-enter the settings.
In MySQL workbench connect to localhost port 13306.
There is a good guide with screen shots here: Setting up an SSH tunnel with PuTTY
An SSH tunnel makes a TCP port on your SSH client machine and directs any traffic to whatever the destination is set to. You can add multiple tunnels, but each one must listen on a different source port number.

You can forward the port via SSH.
ssh -NL is your friend like so:
ssh -NL 3306:localhost:3306 <yourserver>
Then you can point your workbench at localhost.

You don't need any additional software for this task. MySQL Workbench can create SSH tunnels on its own. Watch my tutorial on Youtube how to create connections: https://www.youtube.com/watch?v=DCgRF4KOYIY.
It essentially comes down to creating the right connection type. There is a drop down that allows you to select an SSH connection. Enter the parameters which you used to connect via Putty.

Related

Cant connect to mysql server (hosted by strato) get error 10060

Hi I am trying to connect to my MySQL DB which is hosted by strato. On their site I can create a DB and I did. Now I am trying to connect to the database via NaviCat but I keep getting error 10060.
A screenshot of the strato website: screenshot strato webportal
A screenshot of my trying to connect to the database in NaviCat: screenshot NaviCat
And last but not least a screenshot of their website with an tutorial on how to connect to the DB: link to page
Maybe you're wondering why I don't contect the host, it takes ages for them to reply...
What am I doing wrong why cant I connect how can I fix it?
EDIT/UPDATE
I now setup a SSH tunnel but when I am trying to connect it still gives me this errorlost connection to mysql server at 'reading initial communication packet' system error 0
I am able to connect via PuTTy like shown in this link. And a found the port, hostname etc as you can see
But once I fill that into NaviCat, like this
and this
but still no luck :S now gettings this error:
If anyone can help me i would rlly appreciate it!
My guess is that Strato is blocking outside access to your database. Which is 100% good. Allowing internet access to a database is generally a bad idea.
You can connect to the database by SSH'ing to the server and then using mysql CLI. Instructions are provided in the link you shared in the SSH-access to the MySQL database section.
Using SSH you can also port tunnel to allow your remote connection with your client. This is a slightly more advanced technique where you link up a port on your local computer (localhost) to a port on the remote machine to which you are ssh'ing.
In PuTTy put in the server name like their instructions suggest:
Then go to SSH>>Tunnel in the left-hand menu. Fill out your Source Port (the port your local computer will be listening on) and your Destination (The server:port on the REMOTE computer that you are forwarding traffic to through the tunnel):
I'm using local port 66306, you may use whatever port you want as long as it isn't be used on your computer. Click "Add" and then Open the connection and put in your username/password when prompted. Refer to that Strato help doc if you get stuck.
NOW... in your mysql client (Navicat) you are going to connect your database. Because you have a tunnel open forwarding traffic from YOUR computer's 63306 port (or whatever port you chose) to the remote computers 3306 port you will specify in Navicat:
Connection Name: Whatever
Hostname/IpAddress: localhost
Port: 63306
Username: strato db username
Password: strato db password
Now it should connect. Strato sees your traffic as if it's coming from their server because of the tunnel and it will allow you through.

Vb db connection in xampp using LAN

Good day,
I have a VB application which i need to connect its database in xampp/mysql..
But mysql/xampp is installed to other computer which is networked at my computer.. What will I do?
The MySql server with XAMPP is no different to any other MySql server , with the exception of the interface; it looks a little bit different. If you want to be able to connect to the server, you need to know the server's internal IP address (you can find it with CMD > ipconfig). The port will generally be assigned to 3306, so you shouldn't have any issues there.
If you want to grant access to the server from your computer, open up the XAMPP control panel (from the other computer) and click Shell. Type in MySql and you'll be able to execute commands, from there (which you can use to grant remote access).

AWS RDS: How to access/connect to RDS MySql DB From localhost

I am very new to Amazon Web Services, I have created Mysql DB on RDS and stored some data.
Now i want to connect to RDS db from localhost(which is in running on my desktop) ,Tried as fallow in my PHP connection.
$con = mysql_connect("XXXX.XXXXX.XX-XX-X.rds.amazonaws.com:3306", "XXX", "XXX");
But getting error as fallows
Could not connect: Can't connect to MySQL server on 'awsniti.XXXX.rds.amazonaws.com'
Also tried giving my local IP address to Inbounds of Security Group. But couldn't connect.
googled a lot, but not able to find right answer.
Please help me with this issue.
Adding the internet IP of your local network/machine on the security group associated with your RDS database should work. But I prefer to create a SSH tunnel through a server that I already gave access to the database. This way you don't have to care about the security group configuration every time you need to connect from a different IP address.
If you are on Linux or OSX you can run locally
ssh -f user#your-web-server.com -L 3306:XXXX.XXXXX.XX-XX-X.rds.amazonaws.com:3306 -N and then connect localhost:3306 from PHP to access the RDS database. If you are on Windows it's also possible to create a tunnel using Putty (http://bit.ly/1GQmaYo)

How to access Openshift mysql via locally installed wamp phpMyAdmin?

i am using openshift free tier (3 gears). My scalable app uses PHP and MySQL. But unavailability of phpMyAdmin credentials for 3 gears scalable app it's difficult for me to access Mysql table entries. My question is can port forward feature of Openshift is used to access openshift Mysql via locally installed wamp phpMyAdmin.
Yes, it is possible to use port forwarding to access your OpenShift database from your locally installed PhpMyAdmin.
First, make sure you have the Redhat Client Tools (RHC) installed on your computer. If you haven't, download them here: https://www.openshift.com/developers/rhc-client-tools-install .
In order to connect via SSH, you will need a public/private key pair. Again RHC can automate most of this for you when you run rhc setup. The application will ask for your credentials, optionally create an SSH key for you and upload it to your cartridges. Make sure to protect your SSH key with a secure password. This process is described in more detail at https://www.openshift.com/developers/remote-access .
You will need a SSH client. OpenShift recommends Putty for Windows users; detailed setup instructions can be found at https://www.openshift.com/page/install-and-setup-putty-ssh-client-for-windows . In addition I would recommend to install OpenSSH from Cygwin, as this makes it easier to forward the port to your database later on.
Use Putty and your SSH key to connect to your server via SSH. Once you are at the shell, type env to view a list of environment variables on the server. Look for the variables that end with _DB_HOST, _DB_PORT, _DB_USERNAME and _DB_PASSWORD and make a note of their values on your Windows machine. The names and meanings of all of these environment variables are described at https://access.redhat.com/site/documentation/en-US/OpenShift_Online/2.0/html/User_Guide/Database_Environment_Variables.html .
To forward the port, use Cygwin's ssh command. For example:
ssh -f user#my-app.openshift.com -L 3307:DB_HOST:3306 -N
You will have to replace user with your OpenShift username, my-app.openshift.com with your public OpenShift hostname and DB_HOST with the IP address from the ..._DB_HOST environment variable that you looked up above. If this command succeeds, you should now have a tunnel from your local port 3307 to the MySQL server at OpenShift. Thus, you can create a new database connection in PhpMyAdmin's configuration with 127.0.0.1 as the server, 3307 as the port and your credentials, which you got when running the env command via SSH.
Before you open the session with Putty, go to the Connection-->SSH-->Tunneling.
There add a port, for example, 3333. And set as destination the url of your remote mysql server and port, for example: 324324343455435435-yourservices.rhcloud.com:44351. Click on the "Add" button. Save your session and connect.
Once connected you can use whatever the client and connect to localhost on the port 3333 with the user, password and database name given by the env vars as the other guys said.
I connect with Toad for Mysql with no problems.
You can use the rhc port-forward command, similar to what i described here: OpenShift: How to connect to postgresql from my PC
instead of phpmyadmin.SQLyog from webyog has ssh tunneling option. which work fine for remote accessing openshift mysql
You can add this cartridge to have phpMyAdmin support in scalable apps:
https://github.com/arielscarpinelli/openshift-scalable-phpmyadmin

How to connect to remote mysql database with php?

I have a website and a database on a host. But I want the administrator panel on my laptop? Is it possible connect remotely? How can I do this? Thank you very much!
If I've understood correctly your question, you're looking for a GUI front-end for a remote MySQL database. There's many MySQL front-ends out there, but two I would recommend are the official MySQL Workbench if you're running Windows or Linux, and Sequel Pro if you're running Mac (MySQL Workbench can also run on Mac, but I personally prefer Sequel Pro). Both are free.
The first thing you should try is simply connecting to the remote MySQL server by the command line.
$ mysql -u your_user -h remote.host.name -p
Depending on the output will determine what you need to do next.
Error 1
ERROR 2003 (HY000): Can't connect to MySQL server on 'remote.host.name' (113)
This means that the port is not even open for an external machine to connect to it, so you will need to add whatever port MySQL is running on to your firewall to accept incoming connections.
Error 2
ERROR 1045 (28000): Access denied for user 'your_user'#'your.host.name' (using password: YES)
Assuming that your login credentials are correct, this means that you need to grant permissions from within MySQL. Connecting locally from the remote server, grant permissions like this:
GRANT ALL ON your_database.* TO your_user#'your.host.name' IDENTIFIED BY 'your_password';
Obviously substitute all of the relevant things to what they should be.
When you can connect by command line, connecting by PHP is as simple as using the hostname, username and password information that you used in the mysql command above.
You can use a piece of software called Chive to do this, however it's possible that your server doesn't accept connections remotely.
You can either install Chive locally on your machine and connect to the remote computer, or install Chive remotely and connect to it via HTTP (though I strongly recommend HTTPS).
http://www.chive-project.com/
Wow, just like you connect to the site, you should only change the authentication data if necessary, and external IP mysql.

Categories