I still cannot figure out why Im still getting this error message when trying to connect to the MYSQL Server on Node.js -
ERROR -
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'#'localhost' (using password: YES)
at Handshake.Sequence._packetToError (C:\Users\Admin\Desktop\Test Files\Hello World!\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
at Handshake.ErrorPacket (C:\Users\Admin\Desktop\Test Files\Hello World!\node_modules\mysql\lib\protocol\sequences\Handshake.js:103:18)
at Protocol._parsePacket (C:\Users\Admin\Desktop\Test Files\Hello World!\node_modules\mysql\lib\protocol\Protocol.js:279:23)
at Parser.write (C:\Users\Admin\Desktop\Test Files\Hello World!\node_modules\mysql\lib\protocol\Parser.js:76:12)
at Protocol.write (C:\Users\Admin\Desktop\Test Files\Hello World!\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (C:\Users\Admin\Desktop\Test Files\Hello World!\node_modules\mysql\lib\Connection.js:103:28)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at addChunk (_stream_readable.js:266:12)
at readableAddChunk (_stream_readable.js:253:11)
JS -
var mysql = require('mysql');
var con = mysql.createConnection({
host: 'localhost',
user: 'root',
password: '*****',
database: 'mydb'
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
There is no prolem in your node.js
node.js require only mysql installation
-> go to installation of nodejs in the command prompt and enter
npm install mysql
in Eclipse:
1) install the nodejs plugin
2) open package.json in the nodejs project and enter
"author": "Krish",
"dependencies": {
"mysql": "2.x.x"
},
3) right click on the project run -> node install
it will install the mysql and you are ready to connect the Database
ER_ACCESS_DENIED_ERROR
1) go to mysql command prompt
mysql> create user 'root'#localhost IDENTIFIED BY 'password';
2) give permission
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' WITH GRANT
OPTION;
or
mysql>SHOW GRANTS FOR 'root'#'localhost';
now you can run you JS . it will be conneced
If you hosting SQL in xampp then the root user in localhost does not have any password, so remove the password.
It worked for me.
Related
I am trying to create a connection pool using:
mysql.createPool(dbConnOptions)
My dbConnOptions object is:
var dbConnOptions = {
host: '192.168.5.11',
port: 3306,
user: 'johnDoe',
connectionLimit: 10,
charset: "utf8mb4",
database: 'myDatabase',
password: 'myPassword',
multipleStatements: true
};
I am on a Ubuntu server with /etc/hostname having an entry set to 'myHostname'
I have created a MySql user as
create user 'johnDoe'#'localhost' identified by 'myPassword';
grant all privileges on myDatabase.* to 'johnDoe'#'localhost';
The following error is reported:
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'johnDoe'#'myHostname' (using password: YES)
So I tried the following:
grant all privileges on myDatabase.* to 'johnDoe'#'%';
That was rejected with this error:
ERROR 1133 (42000): Can't find any matching row in the user table
Any suggestion would be greatly appreciated. It has been frustrating.
You have created a user johndoe#localhost but you try to access the db with johndoe#myhost and there is no user johndoe#% so you can't grant any privileges to that user.
johndoe#host1 and johndoe#host2 are two totally different users (eventhough they may share the same username) with different priviledges.
And if you want to use the privileges for #localhost you should use 127.0.0.1 or localhost as host ... Because if you are using a custom hostname or the actual IP address, you are not connecting via the loopback device and thus, are not identified as #localhost
i'm using xampp and vagrant to run my project but whenever i try to makemigration or run the server i got this error
django.db.utils.OperationalError: (1045, "Access denied for user 'root'#'localhost' (using
password: NO)")
here's my connection data
and i'm using vagrant to run my project
full error:
so what's the error?
If you're lauching it from command line, you may have to define env var in that command line (see here)
all my env variables are in replit and are correct but it gives me a access denied error when i try to connect.
var connection = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME
});
error (username and ip are hidden)
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlMessage: "Access denied for user '*******'#'********' (using password: YES)"
i saw another one for this but i dont know if that would work on replit since theybare stored in replit. if anyone can help me fix this i would be greatful. thanks!
I was trying to execute "python manage.py migrate" in my project directory made in django.
The output was:
django.db.utils.OperationalError: (1045, "Access denied for user 'root'#'localhost' (using password: YES)")
So, I thought that I was having a problem with the db password of root user, I saw toturials to change the password, then, I try to enter with "mysql -u root -p" and it tried to enter but it did not accept, it said it was invalid. I tried "sudo" and if it worked, I changed the password and everything was fine. but when I try to migrate data I still have same dilemma.
django.db.utils.OperationalError: (1045, "Access denied for user 'root'#'localhost' (using password: YES)")
I assumed that I had to see that I could only do it with "sudo", the question is that I needed to use the data for my project to make use of them
auth': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'api_db_project',
'USER': 'root',
'PASSWORD': 'PASSWORDRANDOM',
'HOST': 'localhost',
'PORT': 3306
},
I thought that I had not solved the problem so I look for more guides and I find:https: //stackoverflow.com/questions/39281594/error-1698-28000-access-denied-for-user-rootlocalhost
$ sudo mysql -u root # I had to use "sudo" since is new installation
mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> exit;
$ service mysql restart
So when I try to test it still doesn't work, I see more guides and when I try to enter mysql to test more things, I can't even enter with "sudo", no password works and I don't know what to do at this point. This prints:
mysql: [ERROR] Found option without preceding group in config file /etc/mysql/mysql.conf.d/mysql.cnf at line 6.
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
Does anyone know what happened? I am new in this :(
Here I leave some info
cat /etc/mysql/mysql.conf.d/mysql.cnf
#
# The MySQL database client configuration file
#
# Ref to https://dev.mysql.com/doc/refman/en/mysql-command-options.html
blind-address = 127.0.0.1
blind-address = *
blind-address = *
blind-address = 0.0.0.0
[mysql]
Ubuntu 20.04
mysql Ver 8.0.21-0ubuntu0.20.04.4
Django 2.2.2
I am not sure why you can't login. On a ubuntu 20.04 with MariaDB I just do
sudo mariadb
GRANT ALL ON *.* TO 'admin'#'localhost' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Maybe you can try this on yours. By default the root account is for login without password I think.
guys.
I've installed MySQL module for node.js using npm install mysql and bumped into connection error.
Here's my js code.
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'user',
password : 'userpassword',
database : 'node'
});
connection.connect();
connection.query('SELECT * FROM table', function(err, rows, fields) {
if (err) throw err;
console.log('The solution is: ' + fields);
});
connection.end();
Here's the output I get:
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'node'#'146.66.*.*' (using password: YES)
at Handshake.Sequence._packetToError (/usr/local/www/apache22/data/node/node_modules/mysql/lib/protocol/sequences/Sequence.js:48:14)
at Handshake.ErrorPacket (/usr/local/www/apache22/data/node/node_modules/mysql/lib/protocol/sequences/Handshake.js:101:18)
at Protocol._parsePacket (/usr/local/www/apache22/data/node/node_modules/mysql/lib/protocol/Protocol.js:270:23)
at Parser.write (/usr/local/www/apache22/data/node/node_modules/mysql/lib/protocol/Parser.js:77:12)
at Protocol.write (/usr/local/www/apache22/data/node/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/usr/local/www/apache22/data/node/node_modules/mysql/lib/Connection.js:82:28)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:746:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
--------------------
at Protocol._enqueue (/usr/local/www/apache22/data/node/node_modules/mysql/lib/protocol/Protocol.js:135:48)
at Protocol.handshake (/usr/local/www/apache22/data/node/node_modules/mysql/lib/protocol/Protocol.js:52:41)
at Connection.connect (/usr/local/www/apache22/data/node/node_modules/mysql/lib/Connection.js:108:18)
at Object.<anonymous> (/usr/local/www/apache22/data/node/local_db.js:9:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
The thing is that instead of connecting to MySQL via localhost (as I specified in connection options) it goes through externalIPaddress (for no obvious reason) and firewall drops connection in accordance with it's rules.
I've searched for solutions in other topics, but either error output or suitable solutions differ a lot.
I've also tried popular solutions for related problems from other questions and this is the list of options, that didn't work for me:
1. Flushing MySQL privileges table after new user creation and granting necessary privileges.
2. Modifying /etc/hosts to get proper answer from nslookup localhost and nslookup localhost.
3. Manually pointing path to MySQL socket also hasn't change anything.
4. I do not use host and server options at the same time.
5. I've tried 3306 port specifying.
After all, I still get the same error.
Thank's for your help in advance.
By default mysql binds and listens to the "everything" address at 0.0.0.0. Perhaps your node and your node.js module are doing the same thing. This would make requests and responses come over your external interface and trigger your firewall.
From your output I assume node and MySQL are on the same machine and that you are using Apache as a reverse proxy. If this is the case only httpd should be listening to ports on external addresses: node, mysql, etc. should be talking to each other over local interfaces or via sockets.
Check your configuration and make sure node and mysql-server are binding/listening to ports on the lo interface, localhost or 127.0.0.1. This could resolve your problem.
HTH, G'Cito