<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/nodejs-mysql-select-record-sl7ytxmxc" -->

---
title: NodeJS MySQL Select Record | daily.dev
description: A beginner tutorial walks through running SELECT queries against MySQL from Node.js using the mysql npm driver. It covers selecting all columns versus specific...
canonical: https://daily.dev/posts/nodejs-mysql-select-record-sl7ytxmxc
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: NodeJS MySQL Select Record | daily.dev
og:description: A beginner tutorial walks through running SELECT queries against MySQL from Node.js using the mysql npm driver. It covers selecting all columns versus specific...
og:url: https://daily.dev/posts/nodejs-mysql-select-record-sl7ytxmxc
og:image: https://api.daily.dev/og/posts/sl7YTxmXc.png
og:image:alt: NodeJS MySQL Select Record
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# NodeJS MySQL Select Record

**[Planet MySQL](https://daily.dev/sources/planet-mysql)** · 6 min read · 0 upvotes · 0 comments

## Summary

A beginner tutorial walks through running SELECT queries against MySQL from Node.js using the mysql npm driver. It covers selecting all columns versus specific columns, reading the returned RowDataPacket array, and handling common query errors like ER_NO_SUCH_TABLE and ER_BAD_FIELD_ERROR by logging err.code and err.sqlMessage. It closes by noting that mysql2 is now the more actively developed driver, with prepared statements and SSL support, though the query() API is the same across both.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://codeforgeek.com/nodejs-mysql-select-record>

## Questions this post answers

### What does a MySQL SELECT query return when using the mysql npm package in Node.js?

It returns an array of RowDataPacket objects, one per matching row, passed as the second argument to the query() callback. Each row object carries the selected columns as properties, so selecting * gives every column while selecting specific columns like name and price returns only those properties, accessible via result[0].name style access.

_Developers wiring up Node.js database calls can compare driver behavior details like this on daily.dev._

### How do I handle a MySQL error like ER_NO_SUCH_TABLE or ER_BAD_FIELD_ERROR in a Node.js query callback?

Check err.code and err.sqlMessage inside the query callback instead of throwing the error, which keeps the process alive and prints the exact problem. A missing table produces ER_NO_SUCH_TABLE, and a typo in a column name produces ER_BAD_FIELD_ERROR with an 'Unknown column' message in err.sqlMessage.

_Track practical Node.js and MySQL error-handling patterns like this one on daily.dev while debugging queries._

### Should I use mysql or mysql2 for new Node.js projects that connect to MySQL?

For a fresh project, mysql2 is the more actively developed native-JS driver, adding prepared statements and SSL support, while the original mysql package sits at version 2 on npm with less active development. Both drivers expose the same query() method shape, so existing query code works the same way regardless of which one is chosen.

_Compare driver choices like mysql versus mysql2 alongside other developer discussions on daily.dev._

## Similar posts on daily.dev

- [Node.js MySQL Insert Record](https://daily.dev/posts/node-js-mysql-insert-record-hsrhzgs3u) · Planet MySQL · 0 upvotes · 0 comments
- [NodeJS MySQL Create Connection](https://daily.dev/posts/nodejs-mysql-create-connection-9vbhox1al) · Planet MySQL · 0 upvotes · 0 comments
- [NodeJS MySQL Create Table](https://daily.dev/posts/nodejs-mysql-create-table-d2unnfnaf) · Planet MySQL · 0 upvotes · 0 comments
- [NodeJS MySQL Select Unique](https://daily.dev/posts/nodejs-mysql-select-unique-nez7bu2oa) · Planet MySQL · 0 upvotes · 0 comments
- [Node.js tutorial: Get started with Node](https://daily.dev/posts/node-js-tutorial-get-started-with-node-orvgt2hi6) · InfoWorld · 2 upvotes · 0 comments

---

Tags: [#nodejs](https://daily.dev/tags/nodejs), [#sql](https://daily.dev/tags/sql), [#mysql](https://daily.dev/tags/mysql)

[View this post on daily.dev](https://daily.dev/posts/nodejs-mysql-select-record-sl7ytxmxc)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"NodeJS MySQL Select Record","url":"https://daily.dev/posts/nodejs-mysql-select-record-sl7ytxmxc","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/nodejs-mysql-select-record-sl7ytxmxc"},"datePublished":"2026-09-15T15:48:38.392Z","dateModified":"2026-09-15T15:49:01.043Z","description":"A beginner tutorial walks through running SELECT queries against MySQL from Node.js using the mysql npm driver. It covers selecting all columns versus specific...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4bbe75903c173610fd4b65dd5606f919?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4bbe75903c173610fd4b65dd5606f919?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Planet MySQL","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Planet MySQL","logo":"https://media.daily.dev/image/upload/s--UKAtmXTq--/f_auto,q_auto/v1780213421/logos/planet-mysql?_a=BAMAMiWQ0","url":"https://daily.dev/sources/planet-mysql"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/nodejs-mysql-select-record-sl7ytxmxc","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"nodejs,sql,mysql","timeRequired":"PT6M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Planet MySQL","item":"https://daily.dev/sources/planet-mysql"},{"@type":"ListItem","position":3,"name":"NodeJS MySQL Select Record"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/nodejs-mysql-select-record-sl7ytxmxc#faq","mainEntity":[{"@type":"Question","name":"What does a MySQL SELECT query return when using the mysql npm package in Node.js?","acceptedAnswer":{"@type":"Answer","text":"It returns an array of RowDataPacket objects, one per matching row, passed as the second argument to the query() callback. Each row object carries the selected columns as properties, so selecting * gives every column while selecting specific columns like name and price returns only those properties, accessible via result[0].name style access. Developers wiring up Node.js database calls can compare driver behavior details like this on daily.dev."}},{"@type":"Question","name":"How do I handle a MySQL error like ER_NO_SUCH_TABLE or ER_BAD_FIELD_ERROR in a Node.js query callback?","acceptedAnswer":{"@type":"Answer","text":"Check err.code and err.sqlMessage inside the query callback instead of throwing the error, which keeps the process alive and prints the exact problem. A missing table produces ER_NO_SUCH_TABLE, and a typo in a column name produces ER_BAD_FIELD_ERROR with an 'Unknown column' message in err.sqlMessage. Track practical Node.js and MySQL error-handling patterns like this one on daily.dev while debugging queries."}},{"@type":"Question","name":"Should I use mysql or mysql2 for new Node.js projects that connect to MySQL?","acceptedAnswer":{"@type":"Answer","text":"For a fresh project, mysql2 is the more actively developed native-JS driver, adding prepared statements and SSL support, while the original mysql package sits at version 2 on npm with less active development. Both drivers expose the same query() method shape, so existing query code works the same way regardless of which one is chosen. Compare driver choices like mysql versus mysql2 alongside other developer discussions on daily.dev."}}]}
```

