先看常规的,使用mysql连接数据库的写法
(async () => {
const mysql = require('mysql2/promise')
// 链接设置
const cfg = {
host: 'localhost',
user: 'root',
password: 'password',
database: 'testdb1'
}
const connection = await mysql.createConnection(cfg)
let ret = await connection.execute(`
CREATE TABLE IF NOT EXISTS test (
id INT NOT NULL AUTO_INCREMENT,
message VARCHAR(45) NULL,
PRIMARY KEY (id))
`)
console.log('create:', ret)
ret = await connection