Failed to connect to the database

Connect to the database in the framework automatically generated by express

connect.js Code

const mysql = require("mysql");

const db = mysql.createConnection({
  host: "localhost",
  port: 3306,
  user: "root",
  database: "ningxia"
})

db.connect((error) => {
  if (error) {
    console.log(error)
    console.log("")
  } else {
    console.log("")
  }
})

module.exports = db

introduce the connect.js file into the Index.js of api, and the small blackboard indicates that the connection failed

Jun.17,2022
Does the

database have a password?


should be port number 3306 is occupied, another MySQL is opened and another wampserver, port is occupied. After I turn off wampserver, I can link successfully

Menu