Find the answer to your Linux question:
Results 1 to 7 of 7
I am stumped by this. Unfortunately, there seems to be no way to access a mysql database with a mysql client through an http proxy. When I am at home ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,753

    Connect mysql client to mysql server through a http proxy


    I am stumped by this. Unfortunately, there seems to be no way to access a mysql database with a mysql client through an http proxy. When I am at home or on an open wifi network, I can connect just fine. When I am in the office, the outbound firewall blocks port 3306. I would need to connect via the http proxy that we use for such purposes.

    If ANYONE out there knows how to do that - connect mysql client to a mysql server that is outside of the firewall via an http proxy host - I would be more than grateful!
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,441
    I also couldnt find information about proxy options in the mysql client documentation.
    However, if there is an open port then there is a way.
    The tool to do this is socat

    A modified (but untested) example from socat might fit your usecase
    Code:
    socat TCP4-LISTEN:3306,reuseaddr,fork PROXY:proxy:www.domain.org:3306,proxyport=3128,proxyauth=rubberman:pass
    
        starts a forwarder that accepts connections on port 3306, and directs them through the proxy daemon listening on port 3128 (proxyport)
        on host proxy, using the CONNECT method, where they are authenticated as "rubberman" with "pass" (proxyauth).
        The proxy should establish connections to host www.domain.org on port 3306 then.
    Some notes:
    - If I read your post correct, then this mysql server is reachable from the internet. This is a bad idea because of possible security/dos issues.
    - If a http proxy is the only way from your office to the internet, then be sure that you dont break any company policies. Maybe this proxy is used to limit outside access. By using socat you will circumvent this.
    - The proxy needs to support the CONNECT method, so that socat can work. Depending on the admin and/or security requirements, this may or may not be given.
    - A proxied connection is not optimal for a DB connection. At the very least you introduce latency, but also network issues such as disconnects or bandwidth concerns can happen.
    You must always face the curtain with a bow.

  3. #3
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    1,659
    If the word alpha doesn't scare you too much you might try this: MySQL :: Download MySQL Proxy

    Update: Irithori pm'd me and pointed out that it looks like this proxy is just a pass through proxy - you can change the port but not wrap the protocol.
    Last edited by gregm; 02-17-2014 at 11:34 PM.

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,753
    Thanks Irithori. Our mysql servers are only accessible from company networks, such as our QA and production systems, and we don't need proxies for them, but to access the servers from our business connections, ie, our office systems, we need to go through an http proxy. I can to that via programmatic processes, such as using http from php or Java/C/C++, but the mysql client doesn't support http proxy connections. I could add that to the mysql source, but that is a project I don't have time to deal with right now. I understand everything you are saying, but I'm not interested in an optimized connection - just something to access data and run reports, etc.

    @gregm
    Thanks for the suggestion. I have been reading about the MySQL Proxy, but I'm not sure it can also be used to connect via another proxy server. If I am wrong about that, I'd love to know how to do it. Honestly, I just started working on this today, so I can't say I've read everything related to the service. Right now, I can create an ssh tunnel and access the database via mysql that way, but it is clunky and a PITA to set up.

    BTW Irithori, I'll look into socat. I'm not familiar with it, though I've heard of it. I may give it a try tomorrow after I shovel out my driveway from today's snow storm!
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,753
    So far the only solutions I have been able to make work is to either create an ssh tunnel that maps something like port 13306 in localhost to port 3306 in the target system, or to use a VPN tunnel, such as OpenVPN, to get directly to the remote system running the mysql server. I'm actually considering altering the source code of the mysql client to allow proxy connections... Unfortunately, I don't have time for that right now.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  7. #6
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    1,659
    The ssh solution seems to be how folks are going about this. If you can do what you need to do using Workbench it seems to have built in ssh access. MySQL :: MySQL Workbench :: 8.1.4 Standard TCP/IP over SSH Connection

  8. #7
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,753
    @gregm
    Yes, I know about that, and have MySQL Workbench, but that is not my only issue. I also need scripted MySQL access as well as access to the MySQL server from php web apps. I can probably use php http connect requests through the proxy to access the database, and from what I read that is not too difficult, but as mentioned, I do need direct shell access to the database without tunneling if possible.

    FWIW, I have been using SQL since the early 1980's, and have been a teacher of relational database theory and SQL programming for the professional training division of Carnegie Mellon University in the past. I have also been an Oracle/Sybase/Ingres/Informix DBA, and have written thousands of lines of production code in PL/SQL, TransactSQL, etc over the years. This is NOT a domain that I am a "noob" in. My current job has me handling multi-petabyte hadoop clusters and helping teach our PhD analytics team how to build/run mapreduce jobs against those databases.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •