Spring Fresh Sale! - Up To 67% OFF BDIX Hosting + Free Domain
Node.js

How to Connect a Webuzo Node.js App to MySQL

To connect a Node.js app to MySQL on Webuzo, you create the database and user in the Webuzo panel, then connect from your app on localhost using a driver like mysql2 with a connection pool. Since MySQL runs on the same server, the connection is local and fast.

Step 1: Create the database and user

In the Webuzo panel, use the MySQL Databases tool to create a database and a database user, and grant the user access to the database. Note the exact names and the password.

Step 2: Install the driver

In your app over SSH, install the MySQL driver:

npm install mysql2

Step 3: Connect with a pool

Use a connection pool, with credentials pulled from environment variables:

const pool = mysql.createPool({ host: 'localhost', user: process.env.DB_USER, password: process.env.DB_PASSWORD, database: process.env.DB_NAME });

Use localhost because MySQL runs on the same Webuzo server as your app.

Step 4: Query safely

Always use parameterised queries to prevent SQL injection:

const [rows] = await pool.query('SELECT * FROM products WHERE id = ?', [id]);

Frequently asked questions

What host do I connect to?

Use localhost, since the MySQL server runs on the same Webuzo server. This keeps the connection local and avoids exposing the database externally.

I get an access-denied error.

Confirm the database user is granted access to that database and that the username, database name and password match exactly what you set in the Webuzo panel.

Should I use a pool or single connection?

A pool — it reuses connections and handles concurrency much better under load. See the connection pooling guide for how to size and manage it.

Was this article helpful?