30 lines
918 B
JavaScript
30 lines
918 B
JavaScript
import mysql from "mysql2/promise"; // Use promise-based API
|
|
|
|
// Create a pool instead of a single connection
|
|
const pool = mysql.createPool({
|
|
host: "db-mysql-nyc1-99306-do-user-12431193-0.b.db.ondigitalocean.com",
|
|
user: "doadmin",
|
|
password: "AVNS_tCXJPnroBpPOhL_c7bR",
|
|
database: "defaultdb",
|
|
port: "25060",
|
|
waitForConnections: true,
|
|
connectionLimit: 10, // Number of connections in the pool
|
|
queueLimit: 0, // No limit on queued connection requests
|
|
connectTimeout: 20000, // 20 seconds
|
|
ssl: {
|
|
rejectUnauthorized: false, // Required for DigitalOcean managed databases
|
|
},
|
|
});
|
|
|
|
// Test the pool connection
|
|
pool.getConnection()
|
|
.then(conn => {
|
|
console.log("Connected to the MySQL POOL database.");
|
|
conn.release(); // Release the connection back to the pool
|
|
})
|
|
.catch(err => {
|
|
console.error("MYSQL Database connection failed: " + err.stack);
|
|
});
|
|
|
|
export default pool;
|