please i'm using expressjs in nodejs. Am actually new to nodejs.
Am trying to connect to mysql with the my usual credentials but i get the following errors.
Please help me out. Thank you.
"C:\Program Files (x86)\JetBrains\IntelliJ IDEA 15.0\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" bin\www
Tue, 08 Dec 2015 21:39:57 GMT NodeApp:server Listening on port 3306
c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Parser.js:82
throw err;
^
Error: ER_ACCESS_DENIED_ERROR: Access denied for user ''#'localhost' (using password: YES)
at Handshake.Sequence._packetToError (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\sequences\Sequence.js:48:14)
at Handshake.ErrorPacket (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\sequences\Handshake.js:101:18)
at Protocol._parsePacket (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Protocol.js:274:23)
at Parser.write (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Parser.js:77:12)
at Protocol.write (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\Connection.js:96:28)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
--------------------
at Protocol._enqueue (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Protocol.js:135:48)
at Protocol.handshake (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Protocol.js:52:41)
at Connection.connect (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\Connection.js:123:18)
at Object.<anonymous> (c:\Users\John\IdeaProjects\NodeApp\routes\about.js:16:12)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
Process finished with exit code 1
As shown in the readme you should use user instead of username:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'password',
database : 'db_name'
})
connection.connect();
for user : and password: please write them all in small letter if any of the letter of the mentioned captions( user and password) becomes uppercase it will display the error
'ER_ACCESS_DENIED_ERROR: Access denied for user ''#'localhost' (using password: YES)'
on the contrary, Host and database is not case sensitive
Host : 'localhost',
user : 'user_username',// if you create a user otherwise use 'root'
Database : 'the database',
password : 'your password',
Related
I'm creating a discord bot that pulls from a pre-established database of patch note news I have, it's my first time dealing with NodeJS and MySQL. I've got the default connection code in the file right now to test the connection and it looks like this:
require('dotenv').config();
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');
const mysql = require('mysql');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
const con = mysql.createConnection({
host: process.env.HOST,
port: process.env.PORT,
user: process.env.MYSQLUSER,
db: process.env.DATABSE,
password: process.env.MYSQLPASSWORD,
});
con.connect((err) => {
if (err) throw err;
console.log("Connected");
})
I've tried hosting the application local on my machine with a remote connection to the SQL database and on the actual server that it lives on, so far this is all I'm getting:
/home/niemer5/news-bot/node_modules/mysql/lib/protocol/Parser.js:437
throw err; // Rethrow non-MySQL errors
^
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'niemer5_discordbot'#'localhost' (using password: NO)
at Handshake.Sequence._packetToError (/home/niemer5/news-bot/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Handshake.ErrorPacket (/home/niemer5/news-bot/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
at Protocol._parsePacket (/home/niemer5/news-bot/node_modules/mysql/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (/home/niemer5/news-bot/node_modules/mysql/lib/protocol/Parser.js:433:10)
at Parser.write (/home/niemer5/news-bot/node_modules/mysql/lib/protocol/Parser.js:43:10)
at Protocol.write (/home/niemer5/news-bot/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/home/niemer5/news-bot/node_modules/mysql/lib/Connection.js:88:28)
at Socket.<anonymous> (/home/niemer5/news-bot/node_modules/mysql/lib/Connection.js:526:10)
at Socket.emit (node:events:394:28)
at addChunk (node:internal/streams/readable:315:12)
--------------------
at Protocol._enqueue (/home/niemer5/news-bot/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/home/niemer5/news-bot/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at Connection.connect (/home/niemer5/news-bot/node_modules/mysql/lib/Connection.js:116:18)
at Object.<anonymous> (/home/niemer5/news-bot/index.js:22:5)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at node:internal/main/run_main_module:17:47 {
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlMessage: "Access denied for user 'niemer5_discordbot'#'localhost' (using password: NO)",
sqlState: '28000',
fatal: true
}
The user exists, it has ALL privileges, I set everything up in cPanel and also tried granting privs in SQL CLI and so far no luck it just errors out with a 1045 access denied error and I have no clue what is happening. Looking for a little guidance here!
I am total beginner to database.
I am using localhost(127.0.0.1) with port 9090.
I successfully created mysql database, ran/used it in windows 10 command prompt and MySQL Workbench.
But when I try to run it with node.js, I fail to connect to server.
Below is index.js file I tried to run in windows command line.
var mysql = require('mysql');
var client = mysql.createConnection({
user:'root',
password:'password',
});
client.query('USE mydb');
client.query('SELECT * FROM PRODUCTS',function(error, result, fields){
if(error){
console.log(error);
} else{
console.log(result);
}
});
And it results in this error.
D:\Coding\VSCode\nodejs>node index.js
Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
--------------------
at Protocol._enqueue (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:116:18)
at Connection._implyConnect (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:454:10)
at Connection.query (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:196:8)
at Object.<anonymous> (D:\Coding\VSCode\nodejs\index.js:10:8)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true
}
I am at the stage not knowing what I am not knowing.
I tried to change port in createConnection() function like this
var client = mysql.createConnection({
user:'root',
password:'password',
port: '9090'
});
Then I get this error.
D:\Coding\VSCode\nodejs>node index.js
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by
server; consider upgrading MySQL client
at Handshake.Sequence._packetToError
(D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket
(D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:88:28)
at Socket.<anonymous> (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:309:12)
--------------------
at Protocol._enqueue (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:116:18)
at Connection._implyConnect (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:454:10)
at Connection.query (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:196:8)
at Object.<anonymous> (D:\Coding\VSCode\nodejs\index.js:10:8)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14) {
code: 'ER_NOT_SUPPORTED_AUTH_MODE',
errno: 1251,
sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading
MySQL client',
sqlState: '08004',
fatal: true
}
1.Open your windows terminal and login :
mysql -uroot -p
( then type you password )
use mysql;
update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';
4 Restart you mysql db : sudo service mysql restart
Doing this in MySQL Workbench solved the problem.
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password
BY 'YourRootPassword';
FLUSH PRIVILEGES;
I am trying to authenticate and user by connecting to mysql DB where i have information of candidate id and there passwords. As watched in demos I have created in "server.js" file, in which I am trying to create a new connection and printing if connection is established.
const connection = mysql.createConnection({
host: '51.51.x.x',
port: 3306,
user: 'intrinsic',
password: 'mypassword',
database : 'practisework'
});
connection.connect(function(err){
(err)? console.log(err): console.log(connection);
});
and when i run the code with node server command i got the following error.
code: 'ER_ACCESS_DENIED_ERROR',
at Protocol._enqueue (C:\Users\ISL Lohitha\Documents\CareerGuidance\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\ISL Lohitha\Documents\CareerGuidance\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (C:\Users\ISL Lohitha\Documents\CareerGuidance\node_modules\mysql\lib\Connection.js:116:18)
at Object.<anonymous> (C:\Users\ISL Lohitha\Documents\CareerGuidance\server.js:19:12)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlMessage: "Access denied for user 'intrinsic'#'175.101.99.33' (using password: YES)",
sqlState: '28000',
fatal: true
}
It is routing to some unknown IP because the ip that i gave is not 175.101.99.33 which not even my local ip (192.10.65.39). I tried access the server database from my PC through MySQL workbench and it had no issues. Any help required on how to connect to database.
I am writing an Alexa lambda function in Javascript to connect to my external database. I have successfully accessed that database with the same username and password. I have uploaded the mysql code from the noded_modules folder on my laptop. Here is the Javascript code:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "www.oryxtech.net",
user: "",
password: ""
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
and this is the error message from the lambda console:
2020-01-03T23:08:10.885Z 1100009f-24bf-4980-a2e1-27044988eb9d Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'oryxtech_sideE'#'ec2-3-85-146-115.compute-1.amazonaws.com' (using password: YES)
at Handshake.Sequence._packetToError (/var/task/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Handshake.ErrorPacket (/var/task/mysql/lib/protocol/sequences/Handshake.js:123:18)
at Protocol._parsePacket (/var/task/mysql/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (/var/task/mysql/lib/protocol/Parser.js:433:10)
at Parser.write (/var/task/mysql/lib/protocol/Parser.js:43:10)
at Protocol.write (/var/task/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/var/task/mysql/lib/Connection.js:91:28)
at Socket.<anonymous> (/var/task/mysql/lib/Connection.js:525:10)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
--------------------
at Protocol._enqueue (/var/task/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/var/task/mysql/lib/protocol/Protocol.js:51:23)
at Connection.connect (/var/task/mysql/lib/Connection.js:119:18)
at mysqlDB.init (/var/task/mysqlDB.js:17:13)
at getWelcomeResponse (/var/task/index.js:64:19)
at onLaunch (/var/task/index.js:263:5)
at exports.handler (/var/task/index.js:328:13)
Am I doing something wrong, or is there a step I have omitted? Thanks in advance for any help.
It looks like the user oryxtech_sideE is not granted permission to access the database from host ec2-3-85-146-115.compute-1.amazonaws.com. Please confirm the same.
You can grant the user to access the host
GRANT ALL ON *.* to 'oryxtech_sideE'#'ec2-3-85-146-115.compute-1.amazonaws.com' IDENTIFIED BY 'password';
or any host:
GRANT ALL ON *.* to 'oryxtech_sideE'#'%' IDENTIFIED BY 'password';
Reference:
Allow all remote connections, MySQL
Hope this helps.
I've read all the similar/duplicate questions, but none of them seem to help.
I am using node with the mysql npm package.
I am able to log into mysql with no problem from the terminal...
sudo mysql -u root -p
...but unable to do via node.
Here is the error.
if (error) throw error;
^
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'#'localhost' (using password: YES)
at Handshake.Sequence._packetToError (/mnt/c/ivan/lab/posto/server/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Handshake.ErrorPacket (/mnt/c/ivan/lab/posto/server/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
at Protocol._parsePacket (/mnt/c/ivan/lab/posto/server/node_modules/mysql/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (/mnt/c/ivan/lab/posto/server/node_modules/mysql/lib/protocol/Parser.js:433:10)
at Parser.write (/mnt/c/ivan/lab/posto/server/node_modules/mysql/lib/protocol/Parser.js:43:10)
at Protocol.write (/mnt/c/ivan/lab/posto/server/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/mnt/c/ivan/lab/posto/server/node_modules/mysql/lib/Connection.js:91:28)
at Socket.<anonymous> (/mnt/c/ivan/lab/posto/server/node_modules/mysql/lib/Connection.js:525:10)
at emitOne (events.js:116:13)
at Socket.emit (events.js:211:7)
--------------------
at Protocol._enqueue (/mnt/c/ivan/lab/posto/server/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/mnt/c/ivan/lab/posto/server/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at Connection.connect (/mnt/c/ivan/lab/posto/server/node_modules/mysql/lib/Connection.js:119:18)
at Object.<anonymous> (/mnt/c/ivan/lab/posto/server/database/createDatabase.js:11:12)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
The database connection.
rdbms: {
server: 'localhost',
user: 'root',
password: 'root',
port: 3306
}
The code I'm trying to execute.
let mysql = require('mysql');
let rdbms = require("../config").rdbms;
let connection = mysql.createConnection(rdbms);
connection.connect();
let query = `
DROP DATABASE IF EXISTS dbname;
CREATE DATABASE dbname;
`
connection.query(query, function (error, results, fields) {
if (error) throw error;
console.log("Database created!");
});
connection.end();