Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6074777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:25:12+00:00 2026-05-23T10:25:12+00:00

We have a node.js app that uses node_msyql , a great little library for

  • 0

We have a node.js app that uses node_msyql, a great little library for accessing MySQL databases.

Unfortunately, if our connection is not used for maybe 8-10 hours, the next time we try to run a query, we get a "No database selected" error back from the server. We need to add a "USE db" somewhere, but I can’t figure out where.

Now, it makes sense to me that connections would go stale, and it seems as though node_mysql is refreshing those stale connections, but there doesn’t seem to be a way to make sure that the right db is connected. I was looking for a .connected() callback or event or something that would let me make sure the correct DB was alway USE‘d, but no luck so far.

Any suggestions how to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:25:13+00:00Added an answer on May 23, 2026 at 10:25 am

    Ys, client tries to reconnect. You can try to query ‘use db’ on reconnect using code like this:

    client._connection.on('connect', function() { client.query('use db'); })
    

    This is where reconnection happen in the node-mysql (‘end’ handler):
    https://github.com/felixge/node-mysql/blob/master/lib/mysql/client.js

    var connection = self._connection = new Stream(),
        parser = self._parser = new Parser();
    
    connection
      .on('error', function(err) {
        var connectionError = err.code && err.code.match(/ECONNREFUSED|ENOTFOUND/);
        if (connectionError) {
          if (cb) {
            cb(err);
            return;
          }
        }
    
        self.emit('error', err);
      })
      .on('data', function(b) {
        parser.write(b);
      })
      .on('end', function() {
        if (self.ending) {
          self.connected = false;
          self.ending = false;
          return;
        }
    
        if (!self.connected) {
          return;
        }
    
        self.connected = false;
        self._prequeue(connect);
      });
    connection.connect(self.port, self.host);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Node.js Express app that I'm hosting on Nodejitsu. I'm already using
I have a basic Node.js app that I am trying to get off the
I have an app that uses a JFace TreeViewer . I have it hooked
I have a Rails app that sends requests to a Node.js app. The node.js
i have tree node in my app that was created by dynamically.when right click
I have a Node.js/Rails3 app that I'm hosting on Heroku. The rails portion seamlessly
I have a Node.js app using Express that stores data in a mongoDB (locally).
I have a little Node.js application that I'd like to hit a remote API
I have an app that loads records from a binary log file and displays
I have a Rails app that allows users to build up a network structure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.