Gulp 4 task with node-mysql2 module causing server crash on connect - gulp

I have a need to run mysql queries within gulp to check certain fields in a table. I currently connect to a development server via ssh tunnel, which is opened via terminal so that my host is set to 'localhost'.
When I execute a connection attempt, the tunnel crashes with:
channel 4: open failed: connect failed: Connection refused
Then the server process crashes with an out of memory error.
We use node-mysql2 and a ssh tunnel to run GraphQL locally for testing, so I can't think of anything in particular in gulp that would cause what is essentially a race condition almost instantaneously from the time that the gulp command is sent.
Gulp Code:
If anyone has any insights I'd be much obliged.

Fix can be found here, thanks to the mysql2 developer for pointing me in the right direction!
More info on fix here:
https://stackoverflow.com/a/30669454/705115

Related

How to check if MySQL service is running with DBD::mysql

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.

Unable to connect to localhost:3306 (2003) for MySQL 8.0.21 on Windows

I am using MySQL workbench to connect to my local server. Everything was running fine and suddenly I jumped in a connection refused errors. I tried restarting the server again and again. Clearing temp files and also restarted my machine. I found this post from which I tried a couple of things like net stop and stopping the process from the services list but in the services list it shows as below:
I waited like for 30 mins but still, the service is not stopped.
Also, below is the screenshot for MySQL workbench when I try to start the server:
Is there anything specific which I need to do in order to resolve this error:
So, I resolved my own problem in this way. I referred the documentation for this particular error and for my error which is of 2003 type it said that look for mysqld.exe process in task manager and if you don't find any then start the server. But, in my case I found 2 mysqld.exe processes running. So, I killed those processes and restarted the server. It worked!!
Might help someone someday :)

I can't start MySQL server in NodeJs after reset MySQL password using Windows's cmd

I reset my MySQL password using cmd commands from this guide.
cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"
mysqld
--defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini"
--init-file=C:\\Users\\<username>\\resetMYSQL.txt
resetMYSQL contains a command to change password
ALTER USER 'root'#'localhost' IDENTIFIED BY '<myNewPassword>';
Now, it turned out I have to keep running the mysqld command above to start my server or else I'll get this error. If I run the command again I can flawlessly run my server until I terminate it.
This is the error. It's ECONNREFUSED.
I think my password is already reset, because apart from the command line, I also run ALTER USER in Workbench after I got access to it while the cmd is running.
Btw, before this I can just start my server using Node and Sequelize and didn't have to start server elsewhere or set anything beforehand
I'm not sure what is the problem here, so I don't know which keyword I should look up on Google. I googled the error code, but those cases seems unrelated to mine.
I'd be glad if you can explain me what's going on.
The nodejs error message you showed us, a ECONNREFUSED message with a traceback, shows the your mysql database server program was not running when your nodejs program tried to connect to it. Nodejs reaches out to MySQL via TCP/IP. TCP/IP responds "I don't know any MySQL." Specifically, it responds "ECONNREFUSED on port 3306," meaning "nothing on this machine accepts connections on MySQL's port."
nodejs does not start the mysql software for you. It connects to it and uses it.. MySQL has to be running already for that work.
Ordinarily, software like mysql runs in the form of a operating system service; a background process that runs all the time on the machine to await requests).
And, ordinarily, you don't provide init files to MySQL to do things like change passwords, except just once, if you must, to rescue something broken. In your case it looks like you forgot your MySQL password, so you needed to use an init file to rescue yourself. Once the password is reset, stop using that init file.
Explaining how to make MySQL run as a service on your machine is beyond the scope of a Stack Overflow answer. But the installers for MySQL, on almost every operating system, set it up to run as a service automatically. It's generally useless otherwise.

Web2py scheduler stopping the app from running

I cann't get the scheduler run in my ubuntu or debian linux machines. Originally I had db = DAL('sqlite://storage.sqlite') which causes a weird situation where the website becomes unavailable (the browser cannot establish a connection to the server at 127.0.0.1) but when I run the same app without scheduler (without -K appname), and check the app database, it shows that the scheduler task has been running successfully. What is causing connection to the server to break?
Second, I tried using pymysql or mysqldb instead of sqlite. but, I get this error "Error in URI 'pymysql' or database not supported" even without -K myapp option.

"MySQL server has gone away" error after few hours of inactivity

I have a Django app running on Apache with wsgi module.
After few hours of inactivity I get that error and I have to restart the Apache.
Any ideas?
Thanks
This error message mean that the database server has closed the connection to you. I guess this is caused because the connection is idle.
I believe you can get this fixed by adjusting the wait_timeout inside the configuration file of your mysql database server. The file is most commonly named "my.cnf".
This, however, is not considered as a good practice. I would like to suggest you to optimize the application you are writing to open the connection to mysql on demand - there's no point to keep it open if you are not actively using it for a long time.
If you need a quick fix, use the mysql_ping() function to check whether the connection is still alive and re-open if necessary.