Reputation: 73
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}`)
)
Upvotes: 0
Views: 9462
Reputation: 965
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
Upvotes: 0
Reputation: 46
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
Upvotes: 2