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.

Why does this query return no results?

See original GitHub issue

Code:

const conn = mysql.createConnection({
    host: 'localhost',
    port: 3306,
    username: 'root',
    password: '',
    multipleStatements: true,
    timeout: 5000
});

conn.connect((err) => {
    if (err) {
        // console.log(err.code);
        // console.log(err.fatal);
        // console.log(err.sql);
        // console.log(err.sqlState);
        // console.log(err.sqlMessage);

        dialog.showErrorBox('Uh-Oh!', err.code);

        return;
    }

    const SQL = 'SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA = "' + db + '"';

    conn.query(SQL, function (err, rows, fields) {
        if (err) {
            dialog.showErrorBox('Uh-Oh!', err.code);

            return;
        }

        console.log(SQL);
        console.log(rows); // []
        console.log(fields);
    });
});

When SQL is dumped it returns:

SELECT * FROM information_schema.TABLES WHERE TABLE_SCHEMA = "survive"

However rows is always an empty array. When I run the exact query in PMA then:

I am not getting errors and I have tried connecting with debug: true too.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
sqlbotcommented, Feb 20, 2019

@Script47 FWIW you may want to SELECT * FROM mysql.user WHERE user = ''. Your server is allowing anonymous logins, and you probably want to delete those empty-username entries. Had they not been there, you would have failed to connect and the error message would likely have identified you as ''@'localhost', which might have been a tipoff.

1reaction
dougwilsoncommented, Feb 20, 2019

Probably because there is no such option as username; it’s called user: https://github.com/mysqljs/mysql#connection-options

this.conn = mysql.createConnection({
    host: this.get_host(),
    user: this.get_username(),
    password: this.get_password()
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why Query is not returning any results?
Typically, when no rows are returned from a query it is down to one of two things: Either your JOINs are resulting in...
Read more >
Getting "Query does not returns results" SQL exception
For INSERT , UPDATE or DELETE use the executeUpdate() method and for SELECT use the executeQuery() method which returns the ResultSet .
Read more >
Query does not return any results - Microsoft Q&A
Query does not return any results. Hello,. I am running the following query on SSIS on the AdventureWorks2012 database.. select
Read more >
Query not returning results
No results were found for your search query. Tips. To return expected results, you can: Reduce the number of search terms. Each term...
Read more >
Query Returning Zero Rows Unexpectedly
The hidden culprit here is the presence of NULL values in the column referenced in the subquery. We need to note that NULL...
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