sequelize mysql ssl SequelizeConnectionError: ER_HANDSHAKE_ERROR: Bad handshake - mysql

I try to connect to an Azure MySQL DB with ssl.
new Sequelize('db', 'user', 'pw',
{
host: '...',
port: '3306',
dialect: 'mysql',
dialectOptions: {
insecureAuth: true,
ssl: {
ca: fs.readFileSync('ca.pem')
}
}
}
However I get ... `
SequelizeConnectionError: ER_HANDSHAKE_ERROR: Bad handshake
I have already tried:
https://github.com/sequelize/sequelize/issues/578
`

Ensure that your credentials are in the format of user#servername; this is required for Azure Database for MySQL.

A little late to the party but just came across this myself. This thread helped me solve it. If it's an option you could also just downgrade your version of Node but that's more of a bandaid than a fix.

Related

Database query doesn't return anything

I'm trying to connect my flutter app to the database using the mysql1 dart package. Everything seems right, I get no errors on the connection but I can't query my database. I'm not sure if my query reaches the database and is ignored or maybe I'm not reading the results right. I did as much debugging as my skills allow for and I'm out of ideas.
MySqlConnection.connect(ConnectionSettings(
host: 'localhost',
port: 3306,
user: 'root',
password: 'Haffenstadt!',
db: 'dbco'))
.then((conn) {
conn.query('SELECT * FROM User').then((results) {
print(results.isEmpty);
print(List.from(results));
});
conn.close();
});
My console:
flutter: true
flutter: []

nodejs sequelize connect to a remote mySQL database always give ETIMEDOUT

i need your help regarding connecting sequelize to a remote mySQL database
sequelize connects fine when i set host attribute to 'localhost' like this:
new Sequelize('billsmanager', 'root', '12345', {
host: `localhost`,
dialect: 'mysql',
define: {
timestamps: false
},
pool: {
max: 25,
min: 0,
idle: 10000
},
})
then i've tried to put my local IP address at home instead of 'localhost' and ETIMEDOUT comes
i tried freeinfinity hosting site it gives ETIMEDOUT
my office server it gives ETIMEDOUT
even i tried my brother's home server and it gives me ETIMEDOUT
and even my network at home it gives ETIMEDOUT
someone suggested here to add inbound rule in firewall for port 3306 and it doesn't work
and commenting bind-address in my.ini didn't work too
i'm using XAMPP
i don't know really why this happens
can you help me?
thanks so much in advance,i really need this to work
i've solved it at last with very silly solution
i added a connect timeout to 100Sec and it worked and connected after like 12Sec
i wrote the initialization like this:
sequelizer: new Sequelize('billsmanager', 'root', '12345', {
host: `192.168.1.2`,
dialect: 'mysql',
dialectOptions: {
connectTimeout:100000
},
define: {
timestamps: false
},
pool: {
max: 25,
min: 0,
idle: 10000
},
}),
thanks

Connect to RDS MySQL programatically (NodeJs, Java) - ER_ACCESS_DENIED_ERROR: Access denied for user

I am trying to connect to my RDS (AWS MySQL database) using NodeJs mysql library.
const mysql = require('mysql');
var connection;
connection = mysql.createConnection({
host: 'xxx.us-east-1.rds.amazonaws.com',
port: 3306,
user: "username",
password: "MyPassword",
database: "DbName",
});
I was also trying mysql2 and sequelize. All of them got me the same result:
{
error: ER_ACCESS_DENIED_ERROR: Access denied for user 'username'#'myhost,
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlState: '28000'
}
However, this remote database is set to public and I am able to connect to it with mysql command:
mysql -u username -pMyPassowrd -h xxx.us-east-1.rds.amazonaws.com
I am also able to connect to it with MySQL Workbench.
Also, the problem is not in NodeJs, because I am able to connect to my local database:
connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'root',
database: 'test',
});
In conclusion, my AWS database is publicly available and I can connect to it, just not using NodeJs for some reason.
I have not found a useful answer yet. Did anyone encounter this problem ?
UPDATE:
Trying to connect in Java with simple Connection returns the same result as well:
final Connection con = DriverManager.getConnection("jdbc:mysql:/xxx.us-east-1.rds.amazonaws.com:3306/DbName", "username", "MyPassword");
UPDATE 2:
I was missing one slash for Java code. I needed to use jdbc:mysql:// instead of jdbc:mysql:/. But NodeJs implementation is still one big mystery.
The answer was rather simple, just add an ssl option with true value
connection = mysql.createConnection({
host: 'xxx.us-east-1.rds.amazonaws.com',
port: 3306,
user: "username",
password: "MyPassword",
database: "DbName",
ssl: true //this does the trick
});

Sequelize ORM: How to connect to MYSQL on localhost, using the 'host' property?

I'm trying to connect to my local MYSQL(ran by XAMPP) through Sequelize:
const sequelize = new Sequelize(process.env.MYSQL_DB, 'root', '', {
host: process.env.CLEARDB_DATABASE_URL,
dialect: 'mysql',
logging: false
});
The process.env.CLEARDB_DATABASE_URL variable is set to "localhost", just like the documentation says(i'm using this specific variable because i want to deploy to Heroku later)
I'm getting the following error:
getaddrinfo ENOTFOUND localhost'; localhost';:3306
The process.env.MYSQL_DB variable is just the name of my database.
It all worked when i was using the "short way" to connect:
var sequelize = new Sequelize(process.env.MYSQL_DB , "root", "", {
dialect:'mysql',
logging: false
});
Can someone tell me what might be wrong with my setup?
EDIT: if anybody is interested, the problem was that i put a semicolon after the variable deceleration in my .env file.......

Using local.js to store sails-mysql password

I'm trying to use mysql as my database, but I can't figure out how to get my config/adapters.js to use mysql information in config/local.js to connect. What's the correct way to store the connection information so that sails-mysql can connect?
config/local.js is merged on top of all other configuration. So you can just put your own adapters key in there:
{
adapters: {
default: 'myLocalAdapter',
myLocalAdapter: {
module: 'sails-mysql',
host: 'localhost',
user: 'root',
password: 'password',
database: 'database'
}
}
}
and it'll be picked up and used by Sails.
EDIT In sails v0.10.x, use the key connections instead of adapters as the two are now differentiated and connections now hold authentication info. The original answer was for an earlier version of sails.
As of latest version of sails (i.e 0.12), while writing this answer, there is no Adapters.js. The list of connections are specified in the config/connections.js and default connection to use for all models are specified under config/models.js. So, going by this change the way to override the database configuration for local is specifying as below in config.local.js.
module.exports = {
connections: {
localMongoServer: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
user: 'YOUR_DB_USER',
password: 'YOUR_DB_PASSWORD',
database: 'YOUR_DB_NAME'
}
},
models: {
connection: 'localMongoServer'
}
}
NOTE: As in accepted answer, just changing adapters to connections won't work, since there is no default attribute under connections.