I am trying to use a Thrift client on JRuby 1.7.3. The error message is always
Could not connect to ::1:55674: Connection refused - Connection refused
I can always connect successfully on ruby-1.9.3. After much Googling, it appears that the Thrift client had an issue with JRuby, but it's supposed to be fixed in 1.6.7.
How should I fix this? Is this a known issue?
Found it!
I was creating my Thrift::ServerSocket using ::1. MRI clients will work with this (doesn't matter if host is set to localhost, ::1, or 127.0.0.1. JRuby clients will not, and will complain about refused connections.
Next, I was creating my Thrift::Client using ::1. Again, JRuby doesn't like it.
Changing every thing to localhost fixed it. I don't really understand what is going on, but java is clearly using IPv6.
>lsof -i :56990
COMMAND PID USER FD TYPE SIZE/OFF NODE NAME
java 4441 codex 31u IPv6 0t0 TCP localhost:56990 (LISTEN)
java 4441 codex 36u IPv6 0t0 TCP localhost:56990->localhost:50439 (ESTABLISHED)
java 4875 codex 31u IPv6 0t0 TCP localhost:50439->localhost:56990 (ESTABLISHED)
Related
I am currently trying to work through a guide to build an automated phone system using twilio and integrate it into MySQL database (https://www.twilio.com/blog/connect-local-database-twilio-functions). The issue I am having is that I am unable to connect to the MySQL server after tunneling with ngrok.
Here is the command I am running:
mysql --protocol=tcp --host=0.tcp.ngrok.io --port 18477 --user=root -p
When I press run, the terminal sits in idle for several minutes and then outputs:
ERROR 2003 (HY000): Can't connect to MySQL server on '0.tcp.ngrok.io' (110)
Here is a screenshot of ngrok:
I have followed the steps in https://linuxize.com/post/mysql-remote-access/ to further my knowledge on setting up remote access to mysql. At the bottom of the article, it says that this error typically means 'the port 3306 is not open, or the MySQL server is not listening on the IP address." I then followed the links provided and checked both of those. The second image looked at the listening aspect.
Upon encountering this error, I tried to do some research to see if I can track down the issue. I have zero networking experience, so I do not understand anything beyond client and server basics and such. I came across the mysql documentation (https://dev.mysql.com/doc/refman/8.0/en/can-not-connect-to-server.html).
It says, "if the server was started with skip_networking system variable, it will not accept TCP/IP connections at all." Furthermore, it goes on to say, "If the server was started with bind_address system variable set to 127.0.0.1, it will listen for TCP/IP connections only locally on loopback interface and will not accept remote connections."
I have already made the modifications that I have seen across various documentation and articles. Here are some images to show what I have set-up:
The image below is a screenshot from MySQL Workbench. My bind address is open to all and is not restricted to local connections (bind_address in etc/mysql/mysql.conf.d is commented out). Furthermore, port is set to 3306. Lastly, skip-networking is not checked so TCP/IP can occur.
To confirm that MySQL is listening on port 3306, I ran this lsof command with iTCP:3306. I believe this tells me that mysql is listening on 3306. I am not sure if USER refers to the user mysqld is running on, but if it is, I am not sure what this means in the context of root and other users.
I wish this seemed trivial, but with little networking knowledge, I can easily overlook something simple. Any additional information can be provided.
When you connect to MySql via the hostname set up by ngrok, don't use port 3306. Instead, use the port allocated for you by ngrok. In your example it's 18447.
NOTE. operation system is ubuntu 14.*
I am breaking my head over my connection on my MYSQL server. I try to connect to my MYSQL server internal through my public ip. But i am unable to connect. While i am able to connect when i connect to localhost and when i connect externally.
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
I commented the bind-adress out and this should bind the addres to 0.0.0.0. I also tried to setup the bind-adres to 0.0.0.0. This also doesnt work.
My hosts file is setup up as follows:
127.0.0.1 MY-IP
When i telnet on port 80 to my public ip there is no problem.
telnet MY-IP 80
I get:
Trying MY-IP...
Connected to MY-IP.
Escape character is '^]'.
But when i try this on port 3306 it keeps on:
Trying MY-IP...
I also granted all the right permissions to my MYSQL users. And i am possible to connect externaly and internaly. But it is not possible for me to connect internaly with my public ip.
Also i tried to find a solution with netstat.
netstat -tln
give mes
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
EDIT: Just disabled UFW. It still doesnt work.
ufw status
Status: inactive
EDIT2: Is it possible that mysql is ignoring the /etc/hosts file?
Could somebody help me a bit further with some great ideas where the problem might be.
You should change the bind address to 0.0.0.0 then restart the mysqld. Also make sure there is no firewall enabled:
iptables -n -L
if there are rules, blocking port 3306, delete them, or just disable the firwall with
iptables -F
also use netstat to check if the server is listening on the external ip:
netstat -tupan |grep :3306
This may be hugely a dumb question, but I*m a novice to MySQL, and I just discovered that MySQL has different ip i.e. 127.0.0.1 and its hostname (localhost) than the machine ip which is 192.168.1.3 and machine hostname is ceres, why is it so ?
I connected to MySQL running on different machine using MySQL workbench :
and it shows it logged me to mysql root user to 127.0.0.1 on pi#192.168.1.3
then
I wanted to insert data to db remotely using arduino MCU and i can definitely not write 127.0.0.1
Every server is IP 127.0.0.1 to itself. If you want to connect to MySQL installed in a machine where you are logged in, you will use IP 127.0.0.1 or localhost but if you want to connect to MySQL on that machine via another machine, you will have to identify its IP so that you can connect via this IP. That's why remotely you will connect to your MySQL server via IP 192.168.1.3 and not on 127.0.0.1. localhost is still IP 127.0.0.1
127.0.0.1 is the loopback interface, and is used when you try to connect to the mysql service locally (on the same server where the mysql service is running).
If you need to connect to the mysql service from another machine, you will need its IP address for it. You can use ifconfig to see what IP address is assigned to the server.
You need to understand a bit about TCP/IP to follow what is going on here. Every TCP/IP stack (implementation) has the internal loopback interface under the address 127.0.0.1 (for IPv4) or ::1 (for IPv6). This makes it easy to access the stack on the local machine without knowning it's TCP/IP address (or even if it has got none).
Then each machine participating in a TCP/IP network needs an address under which it is known in this network (in your case 192.168.1.3). When you work on your local machine then it doesn't matter if you use it's public IP address or it's loopback interface. A third option is the name localhost which resolves to the loopback interface. But watch out: it depends on the OS if that ends up at the IPv4 or the IPv6 variant.
As you know you can specify a host for a user, which decides from which it can connect. And here user#localhost and user#127.0.0.1 (or user#::1) are not the same host. The MySQL terminal implicitly treats localhost and loopback IP address as the same, for the user's convenience, but other clients do not. The bind address mentioned here is usually not involved at all. This is for special scenarios not relevant here. In over 10 years I never had to set a bind address for MySQL.
Update: I hope that downvoters comment on their action to show if something needs to be improved in my answer or they are just ignorant.
I want to connect to my database with the tool SquirreL in ssh.
Is it possible?
Sadly I have no other options for this server, so I ll have to change of tool if it is not working.
There's no way to do it directly through Squirrel, but it's ridiculously easy (when you know how) to set up the ssh tunnel that Squirrel can use.
I'd forgotten how, and came here looking for something to refresh my memory... but I had no luck on StackOverflow, so I did the research and I'm leaving the solution here for future-me... and hopefully it'll help someone else, too.
Create the ssh tunnel:
$ ssh -v -N -L3307:localhost:3306 remotehostname
I chose to use port 3307, since I also have MySQL running locally on port 3306.
Details (or you can just skip to step 2):
3307 is the port you want to use locally to refer to the remote system.
I believe that localhost here is referring to the remote system, from its own point of view, so localhost:3306 references the the standard MySQL port on the remote system.
-v is optional; it just makes ssh's output more verbose, which can help with troubleshooting. You're not going to be using the window running ssh for anything else, so might as well let it be chatty.
-N says you're not interested in actually opening a shell on the remote host. We're here for a database connection only.
If you have the verbose option turned on, you should see a message like this:
debug1: Local connections to LOCALHOST:3307 forwarded to remote address localhost:3306
If you don't have verbose output turned on, you'll only see something like Authenticated to 10.0.1.234 (via proxy).
Set up an "alias" in Squirrel that looks something like this:
Click Test and then Connect to test your connection.
If you ran ssh with the -v option, you can watch the window while you attempt to connect via Squirrel. You should see something like this for a successful connection:
debug1: Connection to port 3307 forwarding to localhost port 3306 requested.
debug1: channel 2: new [direct-tcpip]
debug1: channel 2: free: direct-tcpip: listening port 3307 for localhost port 3306, connect from 127.0.0.1 port 54536 to 127.0.0.1 port 3307, nchannels 3
When you're done with the database, just hit CtrlC in the ssh window to kill the tunnel (if you left off the -N option, I guess you'd have to hit CtrlD to close the shell).
Sadly squirrelSQL does not support ssh tunneling. Fortunately, MySQL Workbench does support ssh tunneling so I would recommend using that instead if you are connecting to a MySQL database.
An alternative to using a different tool is to use ssh port forwarding. Essentially you can forward port 3306 (or whatever port your MySQL DB uses) from the remote box to your local box. There are a number of guides on the web on how to do this. Once the tunnel with port forwarding is established you can use a local connection string like 'localhost:3306'. to connect to the remote db. It's good idea to put the ssh connection string in a .sh or .bat file because you'll have to run when you need to connect to the DB for the first time.
The Java application I am working with is supposed to write its resulting data to a mysql database, but whenever I run it, I get the following exception:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
With the following cause:
Caused by: java.net.ConnectException: Connection refused
Naturally, my next step was to test the port that mysql was attempting to connect on (3306).
$ telnet localhost 3306
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused
My next step was to see if port 3306 was listening at all.
$ netstat -an|grep 3306
tcp 0 0 69.164.214.18:3306 0.0.0.0:* LISTEN
So in summary, the port is listening but not accepting connections?
I must admit, I do not know a whole lot about this, but does anybody know what is going on here?
Checklist:
Firewall rule: If your server deny/not allow 3306 port, can not connect it.
Bind Address: if your bind address are 127.0.0.1 in MySQL configuration, you must change to 0.0.0.0 in [mysqld] on /etc/mysql/my.cnf
Restart Service: you have to run command 'service mysql restart'
Good Luck.
I figured it out. I needed to connect to mysql externally, but my program was trying to access it locally.