question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

how to check table is exist or not before executing any other query in connection pool

See original GitHub issue

I have tried the following … but it failed…

'use strict';
const mysql    = require('mysql');
const dbConfig = require('../../../config/index').DB;
const pool     = mysql.createPool(dbConfig);

pool.query('SHOW TABLES LIKE users', (error, results) => {
	if(error) return console.log(error);
	console.log(results)
});

pool.on('connection', function (connection) {
  console.log('%d conneted', connection.threadId)
});

pool.on('release', function (connection) {
  console.log('Connection %d released', connection.threadId);
});

module.exports = pool;

SHOW TABLES LIKE "users"; this query works fine in command line mysql client but failed in node context…

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dougwilsoncommented, Apr 19, 2017

No problem! Without quotes doesn’t even work in the command line for me:

$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73-log Source distribution

Copyright (c) 2009-2013 Percona LLC and/or its affiliates
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> SHOW TABLES LIKE users;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'users' at line 1
1reaction
dougwilsoncommented, Apr 19, 2017

Hi @shivarajnaidu I’m not 100% sure what you’re asking for, because the title and the text and the code all seem to be doing different things, so I’m not sure which is the question. Would you mind rewording it?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Efficient SQL test query or validation query that will work ...
This is the query that will be executed just before a connection is given to you from the pool to validate that the...
Read more >
SQL Server Connection Pooling - ADO.NET - Microsoft Learn
When a new connection is opened, if the connection string is not an exact match to an existing pool, a new pool is...
Read more >
17 Tuning Data Source Connection Pools - Oracle Help Center
This chapter provides information on how to properly tune the connection pool attributes in JDBC data sources in your WebLogic Server 12.1.3 domain...
Read more >
Improve database performance with connection pooling
When a new request to access data from the backend service comes in, the pool manager checks if the pool contains any unused...
Read more >
STATS (statistics) - ProxySQL
Generally, the tables from this database are populated on the fly when the SQL query against them is executed, by examining in-memory data ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found