Recall & Review
beginner
What is the purpose of the
mysql2 package in Node.js?The
mysql2 package allows Node.js applications to connect and interact with MySQL databases using modern, fast, and promise-based APIs.Click to reveal answer
beginner
How do you create a connection to a MySQL database using
mysql2?Use
mysql2.createConnection(config) where config includes host, user, password, and database name.Click to reveal answer
intermediate
What is the difference between
createConnection and createPool in mysql2?createConnection creates a single connection. createPool manages multiple connections for better performance in apps with many queries.Click to reveal answer
intermediate
How can you use promises with
mysql2 to handle queries?Use <code>mysql2/promise</code> import and then call <code>connection.query(sql)</code> to get a promise that resolves with query results.Click to reveal answer
beginner
Why is it important to handle connection errors in
mysql2?Handling errors prevents app crashes and allows graceful recovery or user feedback when the database is unreachable or queries fail.
Click to reveal answer
Which method creates a single MySQL connection in
mysql2?✗ Incorrect
createConnection creates a single connection to the MySQL database.How do you import the promise-based API from
mysql2?✗ Incorrect
The promise API is imported with
require('mysql2/promise').What is a benefit of using a connection pool with
mysql2?✗ Incorrect
Connection pools manage multiple connections to improve performance in apps with many queries.
Which config option is NOT required when creating a MySQL connection?
✗ Incorrect
The
font option is not related to MySQL connection configuration.What happens if you don't handle errors in
mysql2 connections?✗ Incorrect
Not handling errors can cause the app to crash or behave unexpectedly.
Explain how to set up a basic MySQL connection using the mysql2 package in Node.js.
Think about the steps from importing the package to connecting and error handling.
You got /4 concepts.
Describe the advantages of using the promise-based API in mysql2 for database queries.
Focus on how promises improve code readability and error management.
You got /4 concepts.