I can't connect to mysql database using process.env.variable on replit - mysql

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!

Related

Does anyone knows what does mysql erro code ECONNREFUSED mean?

So I use nodejs, I have remote hosted mysql server. I also have user seted with % host, I can even login into mysql-workbench, but when i try to connect with node it throw this err on me:
errno: -111,
code: 'ECONNREFUSED',
my connection code looks like this:
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
})
I tried to search but even when I tried everything I could find it doesn't work.
As a server i use ubuntu 20.04
Anyone here know what to do?

I try to connect MySQL with nodejs but Error:Access denied for user 'root'#'localhost' (using password: YES)

I try to connect MySQL with nodejs but Error:Access denied for user 'root'#'localhost' (using password: YES)
const mysql = require("mysql2")
const db = mysql.createConnection({
host:"127.0.0.1",
port:"3306",
user:"root",
password:"123456",
database:"my_db_01"
})
db.connect((err,conn)=>{
if(err) {
console.log('MySQL connection error: ', err);
process.exit(1);
}
})
But my command line and MySQL workbench can connect mysql successfully.Why is that?
I think it might be my dependency verion,so I change that but useless.
In mysql, 127.0.0.1 is different from localhost. Judging from the error message provided, the reasons for this problem are as follows:
1.127.0.0.1 mapping of hosts file
2.skip_name_resolve parameter
You can check it and it will solve the problem

MySQL Node.js module: Unable to create connection pool. Error: Access denied for user

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

ERROR 1045 (28000): Access denied for user 'rails_user'#'localhost' (using password: YES)

I can't get access to my recently created database. I have tried repeatedly to flush privileges but am unable to reset the password to gain access.
I get the following error when trying to access it on the command line after typing mysql -u rails_user -p then entering what I believe should be the correct password:
ERROR 1045 (28000): Access denied for user 'rails_user'#'localhost'
(using password: YES)
Here's my database.yml:
default: &default
adapter: mysql2
encoding: utf8
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: rails_user
password: examplepassword
host: localhost
development:
<<: *default
database: simple_cms_development
Also, when I enter: grant all on simple_cms_development.* to 'rails_user'#'localhost' identified by 'examplepassword'; on the command line I get the following error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the
manual that corresponds to your MySQL server version for the right
syntax to use near 'identified by 'examplepassword'' at line 1
I've read other examples somewhat similar to my own here on stackoverflow but the solutions do not work to successfully configure and connect my database to my rails app. Any pointers would be greatly appreciated!
If you forget your password for mysql or getting access denied while doing mysql -u UserName -p
then you can open mysql by skipping authorization and then change the password.
See Here

Connect to online database using node.mysql

Is it possible to connect to my online database using node.mysql. I'm using cPanel as my hosting site. So far I've tried this approach
var connection = mysql.createConnection({
host: 'www.agrilif3.com',
user: 'secret',
password: 'secret',
database: 'SmartSurface'
});
But this code gives me this error ER_ACCESS_DENIED_ERROR: Access denied for user 'secret'#'202.92.128.112' (using password: YES) After this I've tried replacing the host to 202.92.128.112 and now this error shows up
Error: connect ETIMEDOUT
at Connection._handleConnectTimeout
Can anyone explain what I'm doing wrong and any tutorial site on how to achieve this will be usefull thanks