How to config Yii framework to connect MySQL over SSH? - mysql

I have local MySql server and want Yii to connect to it over SSH. I have try to config config/main.php but failed. How can I do that?

You need to forward port 3306 from the remote server to your local machine and then set Yii to connect to the forwarded port on localhost.

As stated by hd1: This is something you need to do outside of PHP.
The best way is to create an SSH tunnel so that you have a port on the local server to talk to, that connects to your actual database server. There was a discussion on the Yii forum about exactly this, you can find it here
You might want to take a look at AutoSSH as well.

Related

How to Connect to Dockerized MySQL Database running on EC2 from Flask Web App

I am attempting to connect to a MySQL Database that is dockerized and stored in EC2 from a Flask Application. In order to get to the database manually, you have to ssh in with a pem file and then exec into the docker image to get to the database. How would I go about connecting to this from the application itself. I have tried using both sql alchemy or mysql but if I try and use the ip address to the ec2 instance it just times out. My guess is I need to do something with a Dockerfile within the Flask app maybe? I am fairly new to Flask and Docker so I am not sure what the best course of action is and could not find a lot of information online.
In short, if you are able to connect to the MySQL server with one of MySQL client tools, then you'll be able to connect to it with Flask.
The process is not that simple, I can't give you commands to execute without any additional info, but overall logic is the following.
MySQL has a server inside the docker container working on 3306 port. First, that port should be exposed to the server and probably bind to the server's 3306 port, this may be done on the docker run command.
You need to run something like docker run -p 3306:3306. See more details here
Second, if you want to connect to the instance from remote, you need to make sure the port is accessible from wherever you want, docker will automatically add an iptable record for you, but make sure if there is not a firewall blocking the port.
Given you are receiving a time-out, most probably the issue is that Flask is not able to connect through that port.

Connect to MySQL local database via PHPMyAdmin

I have two servers running on Ubuntu. Server 1 only has MySQL installed and acts as an database. Server 2 is a Apache web server. The database is internal and so as the Apache server and they can ping each other but the database server is not accessible via the internet. I can telnet into the database server from the Apache but I can not connect to the database via PHPMyAdmin.
So the question is how I can configure this to work. I also don't want to allow access to the whole server (databases), access only via user name and password specified.
Thanks!
Define your user as user#[hostip-of-Php-myadmin-server] and you should be set?
It was a BIND issue, it's all fixed now.

Pentaho Data Integration - MySQL Database connect with SSH

I'm trying to connect to a remote MySQL database with Pentaho Data Integration (JDBC Driver).
Therefore I need to build up a SSH connection.
Is it possible to do this inside/with the tool?
Guess I solved it:
I just had to build up a SSH Port Forwarding:
ssh -L 3306:localhost:3306 remote.url
There's no way to do this that I know of in PDI. But you wouldn't really want to. I would take the approach of configuring your MySQL client to use an encrypted connection, and then connect your JDBC driver to that.
Sorry, I don't do MySQL, so I don't know how to do that off the top of my head.
Brian

How to use HeidiSQL (or similar MySQL managers) with hosted databases

I'm using HeidiSQL ( http://www.heidisql.com/ ) to manage my databases at work (I prefer this over phpMyAdmin).
Now, I want to use HeidiSQL with my personnal host plan, but when I connect to MySQL with my host, I connect with "localhost" in PHP but at work, I connect to databases with something like "supersqlserver.foo.net"...
Is there a way to connect to my hosted database with HeidiSQL? Is it common practice with hosts to allow the use of software like this?
BTW, the host where I want HeidiSQL to work is HostGator.
When you can't connect to the MySQL server directly, for example a firewall blocks the access from all network protocols, except HTTP protocol, you can use HTTP tunneling.
Here an example of connecting to MySQl through Httptunnel using HeidiSQL.
Ask your HostGator support. They should be able to help you. Maybe they only listen on localhost, and then you can't connect from the outside. It's rather common to not listen for external MySQL connections due to security policies, but some hosts allow it.

mysql proxy socks

Plain and simple, can anyone explain me how to connect to a mysql server through a proxy (socks4/5). Preferable via the mysql command line (although there are no options for that in the client).
If it's not possible through the mysql command line than ANY other method will work.
All you need is to install and configure tsocks (transparent socks). It's available in most if not all linux distibutions. Afterwards you only need to prefix your command with 'tsocks', for example:
tsocks mysql -h -P .....
To my knowledge, it can't be done through the command line because the mysql command does not support proxy connections.
If both client and server are on a UNIX machine and one of them is accessible from the outside, I suggest using an SSH tunnel. It's basically a securely tunneled TCP connection that can be used for anything and the local mysql command can connect to the tunnel port easily.
If that's no option, you could write some kind of wrapper executable. For example, Java and Ruby have libraries that enable you to talk to SOCKS proxies and hook those sockets up to a MySQL or JDBC protocol implementation. What happens then depends entirely on what you have planned next.
If you've got admin access to the proxy server would there be much mileage in installing MySQL Proxy on it?