I have two separate Ubuntu VMs running on VirtualBox. I am getting the error "Remote DB Error: connect ECONNREFUSED". Here is some background information:
When co-located on same VM, NodeJS to MySQL works fine together. Problem only started after moving MySQL to its own VM.
VMs set up in VirtualBox as Internal Network. They have their own static IPs, and the two VMs can ping each other's IP addresses fine.
When I first got the error, the indication was that nodeJS was trying connection on port 3306 ("Error: connect ECONNREFUSED 192.168.1.69:3306"). Then, I added the port option when creating the connection object ("port : '3306'), but this did not fix problem.
Next, I saw a thread that suggested checking to see what port mySQL is listening on by running (netstat -ln | grep mysql), and the result I got back was "unix 2 [ ACC ] STREAM LISTENING 1831 /var/run/mysqld/mysqld.sock". So, since it said it was listening on 1831, I switched my port in the connection creation code to below:
qvar connection = mysql.createConnection({
host : '192.168.1.69',
port : '1831',
user : 'root',
password : 'vinson',
database : 'pilot',
stringifyObjects: 'true'
});
, however, I was still getting the same error.
UPDATE TO MY POST:
Since my first posting of this... eh.. post, I have learned some things, and in the process made some incremental progress:
By default, MySQL only listens to localhost traffic. In order to have it listen to external traffic you have to disable the listen/bind address in it's my.cnf file. So, I did that, and then restarted MySQL.
Once I did that, I ran "netstat -tlnp", a new line dsiplayed indicating something (definitely MySQL) listening on 0.0.0.0:3306, and this was not there before I made the config change and restarted MySQL.
Then, I executed a query again from the NodeJS VM, and I got a different error (hey, I'll take this as a sign of incremental progress):
" Error: Cannot enqueue Query after fatal error."
So that is where I am now. As before, I would be grateful for any ideas as to what I might try next. Thanks for any help!
Ok, I figured out the rest of my issues. The error above (Error: Cannot enqueue Query after fatal error.) was due to the fact that I had not restarted my NodeJS server, so it had the old connection object. Once I restarted NodeJS server, I then got a new error:
ER_HOST_NOT_PRIVILEGED
The reason I was getting this error was simply because, for a given user, MySQL must know the host from which that user is connecting from (since a valid connection credential for MySQL is combination userId/password/host). Once I updated my user account for remote connections with the appropriated allowed remote hosts, everything worked fine!
Related
I am using the following DBD::mysql statement to connect to a MySQL database:
use DBI;
# Connect to the database.
my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost",
"usr", "usr's password",
{'RaiseError' => 1});
Is there a way to check if MySQL service is running, before trying to connect to the database? What if the database is running on a remote server?
If you want a solution to check if the service is running without attempting to connect to it, you could use some Perl package to check the process table (works locally only), or check that the MySQL port (3306 by default) has a process listening to it.
I'm not sure what the purpose of this check is, because even if the service is running, the next thing you'll probably want to do is open a DB connection. Opening a DB connection is a quick and easy thing to do, and it has good error reporting if it doesn't work. So your intention to check that the service is running first is just unnecessary overhead.
I would just try to connect as you are doing. This is the most direct way of checking that the service is running, and it works both locally and remotely.
If there's an error, catch the error and interpret the error message. It'll be error 2002 (for localhost) or 2003 (for TCP/IP, whether it's the same host or a remote host).
These errors are mostly reliable. But there could be red herrings, for example if the service is running on a remote host, but your client host can't reach it because of firewalls or routing issues.
If you get an error 1045 (Access Denied), at least you know the service is running and you can reach it, the problem is only that your user & password are incorrect, or you tried to access a schema you don't have privilege to use.
I have been trying to set up a new MySQL connection in PhpStorm (2016.1) for days now and cannot figure it out.
I am on a Mac OS X 10.11.4 and I have a Home Server (Ubuntu 14.04) and MySQL (5.5). I have a Firewall setup on the Server and have allowed all local connections to pass through (verified by connecting to MySQL on another computer).
I went into PhpStorm and added a new Database, entered the IP address (even tried host name) of remote (Home Server), and all credentials. When I hit "Test Connection" I get an error of
"Connection refused to host: localhost; nested exception is:
java.net.ConnectException: Connection Refused"
I have "googled" about this error and one suggestion is to uncomment the localhost line in your hosts file (it was never commented out). I then though, maybe I need to have MySQL installed on my Mac, so I installed the current MySQL. Still get the same error. I even went under the SSH tab (PhpStorm) under the database setup and tried to set up a SSH Tunnel, still the same error.
Any suggestions?
(Posted on behalf of the OP).
After talking with JetBrains they were able to help me out. For some reason an address within my /etc/hosts file (on my Mac) was messing the connection up. Once I removed it, it connected. Somehow one of the IP addresses was making it loop back to localhost.
First of all I apologize for my English is not perfect.
I'm trying to connect to mysql database remotely.
I have already done the basic steps such as, for example, comment the bind address in my.cnf.
I gave permissions to the appropriate users in MySQL.
I tried with my friend to do it connect to the database, and it worked but we were in the same room with the same router.
Now I'm home and I tried to connect my friend, but I always get error:
ERROR 2003 (HY000): Can not connect to MySQL server ....
Maybe it's a problem of my home router? I can not even do the telnet.
P.S. I've also taken steps to set the firewall.
Some reasons for that,
mysqld is not running on the local host. Check your operating
system's process list to ensure the mysqld process is present.
You're running a MySQL server on Windows with many TCP/IP connections
to it. If you're experiencing that quite often your clients get that
error, you can find a workaround here: Section B.5.2.2.1, “Connection
to MySQL Server Failing on Windows”.
Check whether the server is running on that host by executing telnet
some_host 3306 and pressing the Enter key a couple of times. (3306 is
the default MySQL port number. Change the value if your server is
listening to a different port.) If there is a MySQL server running
and listening to the port, you should get a response that includes
the server's version number. If you get an error such as telnet:
Unable to connect to remote host: Connection refused, then there is
no server running on the given port.
Look at this mySQL full documentation, it will be helpful.
I'm trying to connect mysql db in openshift from my application as below ,
new DriverManagerDataSource("jdbc:mysql://localhost/dbXXXX?autoReconnect=true", "usernameXXX", "pwdXXX");
However an error was thrown as
om.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Any idea , whats the reasonn
If this is a scaled application, then you need to also supply the port, as it won't be 3306. Otherwise try restarting the mysql cartridge, or try sshing into your gear, and use the "mysql" command to see if you can connect, also try using the environment variables for your connection instead of the actual values. Also, localhost is wrong, ssh into your gear and run "env | grep MYSQL" and you will see the values that you should use.
I am continuously getting below error while connecting to mysql-
Can\'t connect to MySQL server on /ip/address
but mysql is not generating any log for this error. I have below entries in my.cnf file
log=/var/log/mysql_err.log
log-error=/var/log/mysql/mysql_error.log
I am using correct credentials. No issue of conections.
Now how will I determine the exact issue If I'll not get any log ?
Any Idea, how to solve this ?
This is not surprising:
the server can only log an incident it is aware of. However your client does not even reach the server at all! So how should the server know some client has attempted to contact it?
The error message you get clearly indicates that you do have a connection issue.
You can easily make a test to check the most common problems: just open a telnet connection from the system trying to connect to the system the sql server runs on, connect to the mysql port: telnet <ip-of-mysql-server> mysql
On typical unixoid systems "mysql" will be substituted by the "well known port number of mysql, which is 3306. otherwise you have to specify it manually. Do you get a connection at all? I would guess not. This means either the mysql server is not listening where expected (not running or configured otherwise) or the connection is blocked on network level (firewall).