0

PS G:\boot> node hello.js Example app listening at http://localhost:3000 G:\boot\node_modules\mysql\lib\protocol\Parser.js:437 throw err; // Rethrow non-MySQL errors ^

Error: ER_BAD_DB_ERROR: Unknown database 'boot' at Handshake.Sequence._packetToError (G:\boot\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14) at Handshake.ErrorPacket (G:\boot\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18) at Protocol._parsePacket (G:\boot\node_modules\mysql\lib\protocol\Protocol.js:291:23) at Parser._parsePacket (G:\boot\node_modules\mysql\lib\protocol\Parser.js:433:10) at Parser.write (G:\boot\node_modules\mysql\lib\protocol\Parser.js:43:10) at Protocol.write (G:\boot\node_modules\mysql\lib\protocol\Protocol.js:38:16) at Socket. (G:\boot\node_modules\mysql\lib\Connection.js:88:28) at Socket. (G:\boot\node_modules\mysql\lib\Connection.js:526:10) at Socket.emit (events.js:376:20) at addChunk (internal/streams/readable.js:309:12) -------------------- at Protocol._enqueue (G:\boot\node_modules\mysql\lib\protocol\Protocol.js:144:48) at Protocol.handshake (G:\boot\node_modules\mysql\lib\protocol\Protocol.js:51:23) at Connection.connect (G:\boot\node_modules\mysql\lib\Connection.js:116:18) at Object. (G:\boot\hello.js:22:12) at Module._compile (internal/modules/cjs/loader.js:1068:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10) at Module.load (internal/modules/cjs/loader.js:933:32) at Function.Module._load (internal/modules/cjs/loader.js:774:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) at internal/main/run_main_module.js:17:47 { code: 'ER_BAD_DB_ERROR', errno: 1049, sqlMessage: "Unknown database 'boot'", sqlState: '42000', fatal: true }

code is

const express = require('express')
var mysql = require('mysql')
const bodyParser = require('body-parser')
const app = express()
const port = 3000
// app.use(express.static('css'))

app.use(bodyParser.urlencoded({ extended: false }))
app.set('view engine', 'pug')

app.get('/', function (req, res) {
  res.sendFile('signup.html', { root: __dirname })
});

var connection = mysql.createConnection({
  host: 'localhost',
  user: 'root',
  password: '',
  database: 'boot'
});

connection.connect(function (err) {
  if (err) throw err;

  console.log('Connected.........')
})

connection.end();

app.post('/submit', function (req, res) {
  console.log(req.body);
  res.render('index', {
    title: 'Data saved',
    message: 'Data saved successfully'
  })
})

app.listen(port, () =>
  console.log(`Example app listening at http://localhost:${port}`)
)
2
  • The sqlMessage is exactly what it says. There is no boot database. Commented Jun 1, 2021 at 12:22
  • @danblack There is boot database in phpmyadmin. Under this created a table. Commented Jun 1, 2021 at 12:35

2 Answers 2

2

The ER_BAD_DB_ERROR: Unknown database 'boot error is returned from your MySQL server. This means your MySQL server that you host in your local does not have a database with name boot, or the root user does not have access to the database.

Recommend you to double check that you have initiated the database with the boot name before rerunning your app

Sign up to request clarification or add additional context in comments.

4 Comments

It's showing same error for other previously created databases. Also the username root is correct
can you try to remove the database parameter and see whats the new errors?
can you also try to add the port in the options, you probably not using the default port for your db connection
Now I know the problem. I'm using wampp , so in wampp i have 2 server i.e., MySql and MariaDB. The connection is done to mariaDB instead of Mysql. If you see the code, it is var connection = mysql.createConnection not MariaDB. Still it connects to MariaDB. Help me with this
0

This was the solution for me

In mac I navigated to /Applications/MAMP/bin/phpMyAdmin/config.inc.php

And found that my username was "root" and password was also "root"

$cfg['Servers'][$i]['user']          = 'root';      
$cfg['Servers'][$i]['password']      = 'root';

https://stackoverflow.com/a/78066825/12228079

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.