I wanted to comment my solution here, just in case there were people as newbie as me in databases.
I was getting this error because I had installed the mysql
NPM package correctly but I hadn't installed any implementation of MySQL on my computer (I didn't know I had to).
I'm using Arch Linux so, in my case, with the NPM package already installed in my project, I did pacman -Syu mariadb
(MariaDB is the default implementation of MySQL in Arch Linux) and then configured it following the guide.
Then, you can use the root
user you just configured or create a new one to use in your project. For the latter:
Enter mysql
CLI by running mysql -u root -p
.
Enter the password for root
user.
Create a new database with CREATE DATABASE mydatabase;
.
Create a new user with CREATE USER test IDENTIFIED BY "testpass";
.
Grant privileges to test
user to use your new database with GRANT ALL PRIVILEGES ON mydatabase.* TO test@localhost IDENTIFIED BY "testpass";
. See for more information on this.
And then, in my project, I would have:
let connection = mysql.createConnection({
host: "localhost",
user: "test",
password: "testpass",
database: "mydatabase"
});