node-mysql2
node-mysql2 copied to clipboard
Can't get the database name after use db command
Consider the following code:
const dbPool = mysql2.createPool({
host: process.env.MYSQL_HOST,
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
});
await dbPool.query("create database test3");
await dbPool.query("use test3");
console.log((await dbPool.getConnection()).config.database);
await dbPool.query("create table student(id int, name varchar(100))"); //always undefined
await dbPool.query("drop database test3");
`console.log((await dbPool.getConnection()).config.database); ` is undefined but all further queries properly work which means pool is aware of the database. But, then why config.database is undefined. How can I get that value?