The issue: I've got a Node.js program that breaks with the following error when trying to access database information:
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'user'@'localhost' (using password: YES)
The username is correct, as is the password - I have used the combination to log in to the mysql commandline interface. The user is successfully able to log in and can make queries on the same table the the Node program breaks on without erroring out, which leaves me wondering why it is erroring out like this.
Links to code are at the end of the question, as well as how to use it.
The background: The program is a student help request queue for the purpose of having a sort of digital "line" for students to wait in so that the teacher can know who has been waiting the longest and thus how to prioritize who needs help. I wrote it for my computer science teacher to use but also as an interesting project for myself.
The project uses Socket.IO, node-mysql by felixge, and promised-io by kriszyp. Socket is to allow help requests to be sent to teacher/aide computers in real time as well as to allow them to be deleted from all computers at once (aide resolves request 1, it disappears from the teacher's computer so that he/she does not try to help a student who has been helped). The MySQL plugin is to allow interfacing with a MySQL database for holding requests - not the fastest, I know, but it is what my hosting provider allows me to use. Finally, Promised-IO is used for the promises, which are passed around to make it easier to deal with results of queries after they have been made. It is also a remnant from when I simply stored requests in memory and the password hash in a text file. For now I want to get MySQL working, then I will worry about replacing it.
The code as it is now should allow for one instance to have multiple help queues, each accessed under domain.com/queue-name. This is done using a for loop, of all things. I do not care if that is working correctly either and recognize that I should use socket.io's "rooms", but mention it because it may be relevant.
Example Code
// Should have 'npm install'-ed student-queue before this.
var Queue = require("student-queue");
var q = new Queue({
host: "localhost",
database: "mydb",
user: "user",
password: "password"
});
q.start();
If you are trying out the program, it currently takes a bit of setup. The database and user/password need to be created beforehand, then you should run this code in an app.js before using the above code. This is until I can get a "setup" page built:
var DB = require("student-queue-mysql-plugin");
// These are the values that you have set up, to be used in the above snippet
var db = new DB({
host: "localhost",
database: "mydb",
user: "user",
password: "password"
});
db.createConfigTable().then(
function(){
db.addNewQueue({
name: "test",
password: "password"
}).then(
function(){
console.log("You can now access the queue 'test' at localhost:3000/test using the above code. The teacher password is 'password'");
}
);
}
);
Links: I am attempting something new to try and resolve this issue and have made the repositories temporarily private. They will become public again when I am done and I will update this question with the results. - https://github.com/Shadow53/student-queue - https://github.com/Shadow53/student-queue-mysql-plugin
I appreciate any help!
The password was wrong.
That is, the password was given correctly, but for some reason the username was being used as the username and password, so the password was wrong.
Sheesh.
I have fixed the issue as part of the commit made in the transition to mariasql (the thing I was trying before). As far as I can tell, everything works now.