LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-12-2013, 02:45 PM   #1
Aigarzs
LQ Newbie
 
Registered: Jan 2008
Distribution: Slackware
Posts: 19

Rep: Reputation: 0
mysql over ssh tunel


I have made ssh tunnel from my laptop to my home pc
Code:
ssh linuxuser@homenet -L 3307:homenet:3306 -N
I can run mysql from my laptop connecting to localhost:3307
Code:
mysql -h localhost -P 3307 -u mysqluser -p
and in command prompt it works fine, I can issue commands and view outputs.

But connection over ssh tunnel is refused when I want to use it from other software:

1) MySQL client (SQLyog) connection to localhost:3307 gives
Code:
error No.2013 "Lost connection to MySQL server during query";
2) Using java
Code:
connection = DriverManager.getConnection("jdbc:mysql://localhost:3307/mydatabase",
                                   "mysqluser", "mysqlpass");
gives error message
Code:
Communications link failure
The last packet successfully received from the server was 16,139 milliseconds ago. The last packet sent successfully to the server was 16,075 milliseconds ago.
SQLErrorCode: 0
SQLState: 08S01
I can still successfully connect from SQLyog and from java directly to homenet:3306; It is not a firewall issue, since I have turned both firewalls off.
I have increased connection timeout in my.cnf
Code:
connect_timeout=15
It is permitted to user mysqluser to connect from any host
Code:
| Host     | User     |
      |    %     | mysqluser|
      |localhost | root     |
 
Old 05-12-2013, 06:23 PM   #2
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,487

Rep: Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626
That is strange indeed because you seemed to have followed the correct procedure.

First thing is to check the mysql log on the server. IIRC a client will receive a "connection error" when authentication is not correct. This disguises the real error but is perhaps done for a reason.

To grant access from all hosts, the wildcard string is 'mysqluser'@'%' Did you use that in your grant statement like that?

jlinkels
 
Old 05-13-2013, 02:52 PM   #3
Aigarzs
LQ Newbie
 
Registered: Jan 2008
Distribution: Slackware
Posts: 19

Original Poster
Rep: Reputation: 0
Thank you jlinkels for your reply.

How can I make mysql to log all refused connections and other errors?
The only log file for mysql I have found is located at /var/lib/mysql/[Hostname].err, and there is logged only mysqld_safe starting and shutdown entries, nothing else.

Running on Slackware 13.1.0.

I think that user privileges are set correctly, as I can connect with mysqluser to mysql server when not using tunnel.

Do I understand correctly, that when I use tunnel, mysql thinks that I am connecting from localhost?

How do I verify that tunnel is set up and running corectly and not broken by some rooter or something like that?
I used from server
Code:
netstat -nt
and that only shows connection to 22 port, not the tunnel to 3306 port.
 
Old 05-13-2013, 03:26 PM   #4
Aigarzs
LQ Newbie
 
Registered: Jan 2008
Distribution: Slackware
Posts: 19

Original Poster
Rep: Reputation: 0
Also I have found, that I can create tunnel and mysql connection when connecting from laptop inside home network.
Code:
 ssh 192.168.0.101 -L 3307:192.168.0.101:3306 -N
Everything works nice.

Problem stays when I am connecting from outside to my static IP.

Only difference that I see is router in between. Router have forwarded ports 22 and 3306 to my desktop PC.

Can router break or prohibit tunnel somehow? SSH connection to 22 port is working.
 
Old 05-13-2013, 09:02 PM   #5
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,487

Rep: Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626Reputation: 626
You should really get the MySQL logging active. Check the MySQL website about how to do it. It is well documented. Don't forget to turn it off after you solved the problem, some those logs can grow quickly in size.

Not sure what exactly the source IP is of a tunneled connection. Never looked at it. No, routers and firewalls should have no influence because you are tunneling. I would start a tcpdump on port 3307 or 3306 on the MySQL host to look what exactly comes in. From whom, what is answered, etc. and take it from there together with the logs.

Somehow it seems to be related with the client that you are using. When MySQL client works properly it should almost be guranteed that everything else works as well. That is so strange about this problem.

jlinkels
 
  


Reply

Tags
mysql, ssh


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can MySQL log on via SSH/bash? mysql:x:27:101:MySQL Server:/var/lib/mysql:/bin/bash Ujjain Linux - Newbie 2 04-24-2009 02:21 PM
SSH with mysql shof515 Linux - Networking 0 11-28-2005 05:54 PM
Wireless secured tunel byte-aligned Linux - Wireless Networking 5 05-12-2005 08:53 PM
tunel vpn configuration alizamani Linux - Newbie 2 09-01-2004 01:51 AM
Windows -> Linux SSH tunel to full network silence Linux - Networking 4 07-16-2004 08:22 PM


All times are GMT -5. The time now is 05:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration