i'm working on a google cloud project and i get this error when i run node index.js / try to access mysql database remotely.
this is the complete error message:
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'#'external_ip' (using password: YES)
at Handshake.Sequence._packetToError (/home/it21695/nodeproject/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
at Handshake.ErrorPacket (/home/it21695/nodeproject/node_modules/mysql/lib/protocol/sequences/Handshake.js:130:18)
at Protocol._parsePacket (/home/it21695/nodeproject/node_modules/mysql/lib/protocol/Protocol.js:279:23)
at Parser.write (/home/it21695/nodeproject/node_modules/mysql/lib/protocol/Parser.js:76:12)
at Protocol.write (/home/it21695/nodeproject/node_modules/mysql/lib/protocol/Protocol.js:39:16)
at Socket.<anonymous> (/home/it21695/nodeproject/node_modules/mysql/lib/Connection.js:103:28)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:277:12)
at readableAddChunk (_stream_readable.js:262:11)
at Socket.Readable.push (_stream_readable.js:217:10)
--------------------
at Protocol._enqueue (/home/it21695/nodeproject/node_modules/mysql/lib/protocol/Protocol.js:145:48)
at Protocol.handshake (/home/it21695/nodeproject/node_modules/mysql/lib/protocol/Protocol.js:52:23)
at Connection.connect (/home/it21695/nodeproject/node_modules/mysql/lib/Connection.js:130:18)
at Object.<anonymous> (/home/it21695/nodeproject/index.js:10:12)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
at Function.Module._load (internal/modules/cjs/loader.js:520:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
this is my index.js code (the test DB and books table both exist):
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'external_ip',
user : 'root',
password : 'password',
database : 'test',
});
connection.connect();
connection.query('SELECT * from books', function (error, results, fields) {
if (error) throw error;
console.log(results);
});
connection.end();
i have added the mysql port (3306) to the firewall exceptions and i've granted privileges for root user. i turned the mysql and node.js external ips to static. i use the passwords that google cloud has assigned.
+------------------+----------------+------------+
| user | host | grant_priv |
+------------------+----------------+------------+
| root | % | Y |
| root | external_ip | Y |
| mysql.infoschema | localhost | N |
| mysql.session | localhost | N |
| mysql.sys | localhost | N |
| root | localhost | Y |
| stats | localhost | N |
+------------------+----------------+------------+
mysql v8.0.11node.js v10.1.0npm v5.6.0
Before checking the application any further make sure to check the user credentials and access privileges on the database host server.
This problem is related to permissions not with nodejs.
First of all i recommend you to install MySQL Workbech and perform your test from that tool.
Also you need to make some configurations into your MySQL database to allow those remote root connections, take a look at this post:
How to allow remote connection to mysql
Related
I am total beginner to database.
I am using localhost(127.0.0.1) with port 9090.
I successfully created mysql database, ran/used it in windows 10 command prompt and MySQL Workbench.
But when I try to run it with node.js, I fail to connect to server.
Below is index.js file I tried to run in windows command line.
var mysql = require('mysql');
var client = mysql.createConnection({
user:'root',
password:'password',
});
client.query('USE mydb');
client.query('SELECT * FROM PRODUCTS',function(error, result, fields){
if(error){
console.log(error);
} else{
console.log(result);
}
});
And it results in this error.
D:\Coding\VSCode\nodejs>node index.js
Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
--------------------
at Protocol._enqueue (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:116:18)
at Connection._implyConnect (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:454:10)
at Connection.query (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:196:8)
at Object.<anonymous> (D:\Coding\VSCode\nodejs\index.js:10:8)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 3306,
fatal: true
}
I am at the stage not knowing what I am not knowing.
I tried to change port in createConnection() function like this
var client = mysql.createConnection({
user:'root',
password:'password',
port: '9090'
});
Then I get this error.
D:\Coding\VSCode\nodejs>node index.js
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by
server; consider upgrading MySQL client
at Handshake.Sequence._packetToError
(D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
at Handshake.ErrorPacket
(D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\sequences\Handshake.js:123:18)
at Protocol._parsePacket (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Parser.js:433:10)
at Parser.write (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Parser.js:43:10)
at Protocol.write (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Protocol.js:38:16)
at Socket.<anonymous> (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:88:28)
at Socket.<anonymous> (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:526:10)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:309:12)
--------------------
at Protocol._enqueue (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:116:18)
at Connection._implyConnect (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:454:10)
at Connection.query (D:\Coding\VSCode\nodejs\node_modules\mysql\lib\Connection.js:196:8)
at Object.<anonymous> (D:\Coding\VSCode\nodejs\index.js:10:8)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14) {
code: 'ER_NOT_SUPPORTED_AUTH_MODE',
errno: 1251,
sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading
MySQL client',
sqlState: '08004',
fatal: true
}
1.Open your windows terminal and login :
mysql -uroot -p
( then type you password )
use mysql;
update user set authentication_string=password(''), plugin='mysql_native_password' where user='root';
4 Restart you mysql db : sudo service mysql restart
Doing this in MySQL Workbench solved the problem.
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password
BY 'YourRootPassword';
FLUSH PRIVILEGES;
I am trying to connect to a remote server via ssh tunnel and then connect to a mysql.
I first tried on mysql workbench and it works fine. The "fake" information looks like this:
With the same information I tried to connect to mysql with nodeJS but I have no idea how to do it. Please help. This is what I have tried so far.
var mysql = require('mysql');
var tunnel = require('tunnel-ssh');
var config = {
username:'hoffnung8493',
Password:'password123',
host:'hoffnung.com',// not sure if its right
port:22,// not sure if its right
dstHost:'hoffnung.com',// not sure if its right
dstPort:3306, // not sure if its right
localHost:'127.0.0.1',// not sure if its right
localPort: 27000 // not sure if its right
};
tunnel(config, function(error, server){
var db = mysql.createConnection({
host: '127.0.0.1',// not sure if its right
user: 'stock_id',
password: 'stock_password',
database: 'database_name',
charset : 'utf8'
});
db.connect();
db.query(`show tables`, function(error, result){
console.log(error);
console.log(1, result);
})
})
module.exports = db; //probably wrong
Then from main.js I want to send query like this:
db = require('./lib/db.js');
db.query('show tables', function(error, result){
console.log(result)
});
On my console I get the following error message:
0|main | Error: All configured authentication methods failed
0|main | at tryNextAuth (/home/cabox/workspace/node_modules/tunnel-ssh/node_modules/ssh2/lib/client.js:376:17)
0|main | at SSH2Stream.onUSERAUTH_FAILURE (/home/cabox/workspace/node_modules/tunnel-ssh/node_modules/ssh2/lib/client.js:587:5)
0|main | at emitTwo (events.js:125:13)
0|main | at SSH2Stream.emit (events.js:213:7)
0|main | at parsePacket (/home/cabox/workspace/node_modules/ssh2-streams/lib/ssh.js:3929:10)
0|main | at SSH2Stream._transform (/home/cabox/workspace/node_modules/ssh2-streams/lib/ssh.js:669:13)
0|main | at SSH2Stream.Transform._read (_stream_transform.js:186:10)
0|main | at SSH2Stream._read (/home/cabox/workspace/node_modules/ssh2-streams/lib/ssh.js:251:15)
0|main | at SSH2Stream.Transform._write (_stream_transform.js:174:12)
0|main | at doWrite (_stream_writable.js:385:12)
After I fixed from "Password" ->"password", I added db.query after db.connect to see if it works and I got the following error
0|main | { Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'stock'#'firstpg-server197-22' (using password: YES)
0|main | at Handshake.Sequence._packetToError (/home/cabox/workspace/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
0|main | at Handshake.ErrorPacket (/home/cabox/workspace/node_modules/mysql/lib/protocol/sequences/Handshake.js:124:18)
0|main | at Protocol._parsePacket (/home/cabox/workspace/node_modules/mysql/lib/protocol/Protocol.js:278:23)
0|main | at Parser.write (/home/cabox/workspace/node_modules/mysql/lib/protocol/Parser.js:76:12)
0|main | at Protocol.write (/home/cabox/workspace/node_modules/mysql/lib/protocol/Protocol.js:38:16)
0|main | at Socket.<anonymous> (/home/cabox/workspace/node_modules/mysql/lib/Connection.js:91:28)
0|main | at Socket.<anonymous> (/home/cabox/workspace/node_modules/mysql/lib/Connection.js:502:10)
0|main | at emitOne (events.js:115:13)
0|main | at Socket.emit (events.js:210:7)
0|main | at addChunk (_stream_readable.js:266:12)
0|main | --------------------
0|main | at Protocol._enqueue (/home/cabox/workspace/node_modules/mysql/lib/protocol/Protocol.js:144:48)
0|main | at Protocol.handshake (/home/cabox/workspace/node_modules/mysql/lib/protocol/Protocol.js:51:23)
0|main | at Connection.connect (/home/cabox/workspace/node_modules/mysql/lib/Connection.js:118:18)
0|main | at /home/cabox/workspace/inven_man/lib/db2.js:24:4
0|main | at Server.<anonymous> (/home/cabox/workspace/node_modules/tunnel-ssh/index.js:89:13)
0|main | at Object.onceWrapper (events.js:314:30)
0|main | at emitNone (events.js:105:13)
0|main | at Server.emit (events.js:207:7)
0|main | at emitListeningNT (net.js:1349:10)
0|main | at _combinedTickCallback (internal/process/next_tick.js:135:11)
0|main | code: 'ER_ACCESS_DENIED_ERROR',
0|main | errno: 1045,
0|main | sqlMessage: 'Access denied for user \'stock\'#\'firstpg-server197-22\' (using password: YES)',
0|main | sqlState: '28000',
0|main | fatal: true }
0|main | 1 undefined
I cant test it right now, but it should be sufficient to set port in the options to 27000.
tunnel(config, function(error, server){
var db = mysql.createConnection({
host: '127.0.0.1',
port: 27000, // the local port you defined for your tunnel
user: 'stock_id',
password: 'stock_password',
database: 'database_name',
charset : 'utf8'
});
db.connect();
})
Beside that the options are case sensitive, so it should be password and not Password.
var config = {
username:'hoffnung8493',
password:'password123',
host:'hoffnung.com',// not sure if its right
port:22,// not sure if its right
dstHost:'hoffnung.com',// not sure if its right
dstPort:3306, // not sure if its right
localHost:'127.0.0.1',// not sure if its right
localPort: 27000 // not sure if its right
};
First of all, I'd like to suggest you to change / hide the domain name in the future, just for caution cases.
Secondly, can you post the output you get from the console? If you get any output.
Thirdly, as this is an ssh connection matter, you need to make sure you are set as allowed to connect to the remote server, on port 22 in this case, whether in it's settings / firewall settings.
Regarding the settings, double check the variable values to be sure not to confuse between the MySQL and SSH connections variables, rely on the fact that the MySQL Workbench connection is working.
I am able to connect database from SQLyog, but when connecting from Node.js getting following error:
Database IP : 10.0.0.200
Error when connecting to db: { Error: ER_DBACCESS_DENIED_ERROR: Access denied for user 'myuser'#'10.0.0.100' to database 'db_new'
at Handshake.Sequence._packetToError (\node_modules\mysql\lib\protocol\sequences\Sequence.js:52:14)
at Handshake.ErrorPacket (\node_modules\mysql\lib\protocol\sequences\Handshake.js:103:18)
at Protocol._parsePacket (\node_modules\mysql\lib\protocol\Protocol.js:279:23)
at Parser.write (\node_modules\mysql\lib\protocol\Parser.js:76:12)
at Protocol.write (\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (\node_modules\mysql\lib\Connection.js:103:28)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
--------------------
at Protocol._enqueue (\node_modules\mysql\lib\protocol\Protocol.js:145:48)
at Protocol.handshake (\node_modules\mysql\lib\protocol\Protocol.js:52:23)
at Connection.connect (\node_modules\mysql\lib\Connection.js:130:18)
at Timeout.handleDisconnect [as _onTimeout] (\techdoc-connection.js:25:16)
at ontimeout (timers.js:386:14)
at tryOnTimeout (timers.js:250:5)
at Timer.listOnTimeout (timers.js:214:5)
code: 'ER_DBACCESS_DENIED_ERROR',
errno: 1044,
sqlMessage: 'Access denied for user \'myuser\'#\'10.0.0.100\' to database \'db_new\'',
sqlState: '42000',
fatal: true }
Code to connect to DB is as follows,
connection = mysql.createConnection({
host: settings.dbhost,
user: settings.user,
password: settings.password,
database: settings.database
});
Any ideas on how to fix this?
Related: Github issue on mysqljs
When encountering this issue, one common problem is that the user isn't being GRANTED with all the privileges. To grant with all the privileges, you may execute an SQL command as mysql suggests,
mysql> show grants;
+-------------------------------------------------------------------------------------------------------------+
| Grants for RollingRidge#% |
+-------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'RollingRidge'#'%' IDENTIFIED BY PASSWORD '*REDACTED' |
| GRANT ALL PRIVILEGES ON `rollingridge`.* TO 'RollingRidge'#'%' |
+-------------------------------------------------------------------------------------------------------------+
Hope this helps.
please i'm using expressjs in nodejs. Am actually new to nodejs.
Am trying to connect to mysql with the my usual credentials but i get the following errors.
Please help me out. Thank you.
"C:\Program Files (x86)\JetBrains\IntelliJ IDEA 15.0\bin\runnerw.exe" "C:\Program Files\nodejs\node.exe" bin\www
Tue, 08 Dec 2015 21:39:57 GMT NodeApp:server Listening on port 3306
c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Parser.js:82
throw err;
^
Error: ER_ACCESS_DENIED_ERROR: Access denied for user ''#'localhost' (using password: YES)
at Handshake.Sequence._packetToError (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\sequences\Sequence.js:48:14)
at Handshake.ErrorPacket (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\sequences\Handshake.js:101:18)
at Protocol._parsePacket (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Protocol.js:274:23)
at Parser.write (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Parser.js:77:12)
at Protocol.write (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\Connection.js:96:28)
at emitOne (events.js:77:13)
at Socket.emit (events.js:169:7)
at readableAddChunk (_stream_readable.js:146:16)
at Socket.Readable.push (_stream_readable.js:110:10)
--------------------
at Protocol._enqueue (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Protocol.js:135:48)
at Protocol.handshake (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\protocol\Protocol.js:52:41)
at Connection.connect (c:\Users\John\IdeaProjects\NodeApp\node_modules\mysql\lib\Connection.js:123:18)
at Object.<anonymous> (c:\Users\John\IdeaProjects\NodeApp\routes\about.js:16:12)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
Process finished with exit code 1
As shown in the readme you should use user instead of username:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'password',
database : 'db_name'
})
connection.connect();
for user : and password: please write them all in small letter if any of the letter of the mentioned captions( user and password) becomes uppercase it will display the error
'ER_ACCESS_DENIED_ERROR: Access denied for user ''#'localhost' (using password: YES)'
on the contrary, Host and database is not case sensitive
Host : 'localhost',
user : 'user_username',// if you create a user otherwise use 'root'
Database : 'the database',
password : 'your password',
I have a nodejs (with express) openshift app that has a MySQL database (because that is what I am most familiar with), and I cannot figure out how to connect to it on the local environment. My last project I used a php framework with mamp to connect to the local database. What is the equivalent for node? This is the code I have to connect:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '127.0.0.1',
port : '3307',
database : 'test'
});
connection.connect( function(err){
if (err){
throw err;
}
else {
console.log('Connected');
}
});
Here is the error when trying to connect locally:
Error: connect ETIMEDOUT
at errnoException (net.js:901:11)
at Object.afterConnect [as oncomplete] (net.js:892:19)
--------------------
at Protocol._enqueue (/Users/brandonmoffitt/stembudsnode/node_modules/mysql/lib/protocol/Protocol.js:110:26)
at Protocol.handshake (/Users/brandonmoffitt/stembudsnode/node_modules/mysql/lib/protocol/Protocol.js:42:41)
at Connection.connect (/Users/brandonmoffitt/stembudsnode/node_modules/mysql/lib/Connection.js:98:18)
at Object.<anonymous> (/Users/brandonmoffitt/stembudsnode/server.js:16: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)
I am guessing that because I am trying to locally connect to the MySQL db set up by openshift, that I am receiving errors. I just dont know what else to try here. I have tried it without the password as well.
If I switch to localhost for the host, this is the error I receive:
Error: ER_DBACCESS_DENIED_ERROR: Access denied for user ''#'localhost' to database 'stembuds'
at Handshake.Sequence._packetToError (/Users/brandonmoffitt/stembudsnode/node_modules/mysql/lib/protocol/sequences/Sequence.js:30:14)
at Handshake.ErrorPacket (/Users/brandonmoffitt/stembudsnode/node_modules/mysql/lib/protocol/sequences/Handshake.js:91:18)
at Protocol._parsePacket (/Users/brandonmoffitt/stembudsnode/node_modules/mysql/lib/protocol/Protocol.js:202:24)
at Parser.write (/Users/brandonmoffitt/stembudsnode/node_modules/mysql/lib/protocol/Parser.js:62:12)
at Protocol.write (/Users/brandonmoffitt/stembudsnode/node_modules/mysql/lib/protocol/Protocol.js:37:16)
at Socket.<anonymous> (/Users/brandonmoffitt/stembudsnode/node_modules/mysql/lib/Connection.js:72:28)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:736:14)
at Socket.EventEmitter.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:408:10)
--------------------
at Protocol._enqueue (/Users/brandonmoffitt/stembudsnode/node_modules/mysql/lib/protocol/Protocol.js:110:26)
at Protocol.handshake (/Users/brandonmoffitt/stembudsnode/node_modules/mysql/lib/protocol/Protocol.js:42:41)
at Connection.connect (/Users/brandonmoffitt/stembudsnode/node_modules/mysql/lib/Connection.js:98:18)
at Object.<anonymous> (/Users/brandonmoffitt/stembudsnode/server.js:16: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)
Sorry for the length of this post, I just have no idea why it isnt working.
EDIT:
I ssh'ed into the openshift shell to look at the mysql settings. When I do the 'show grants\g' command, this is what I receive:
Grants for adminMYXaSuf#127.11.28.130
GRANT ALL PRIVILEGES ON *.* TO 'adminMYXaSuf'#'127.11.28.130' IDENTIFIED BY PASSWORD '*D0CE5FA2AAD801A33C9190D0B615CC92F364BE6B' WITH GRANT OPTION
This password is different than the one openshift provided.
did you read their doc?.
if you have load balancer, your mysql will install on another gear.
you need to use the env variable when you install the cartridge
port
OPENSHIFT_MYSQL_DB_PORT=44331
host
OPENSHIFT_MYSQL_DB_HOST=12345600a4382ec97a10000f7-somehost.rhcloud.com
OPENSHIFT_MYSQL_DB_PASSWORD=somerandompassword
username
OPENSHIFT_MYSQL_DB_USERNAME=yourusername
pass the variable when you start your app as args.
look at the example for node
https://github.com/openshift-quickstart/nodejs-example/blob/master/server.js
just use the env variable like process.env.OPENSHIFT_MYSQL_DB_HOST to replace the string in the database connection.
var mysql = require('mysql');
var connection = mysql.createConnection({
host : process.env.OPENSHIFT_MYSQL_DB_HOST,
user : process.env.OPENSHIFT_MYSQL_DB_USERNAME,
password : process.env.OPENSHIFT_MYSQL_DB_PASSWORD,
port : process.env.OPENSHIFT_MYSQL_DB_PORT,
database : process.env.OPENSHIFT_APP_NAME
});
It looks like you are running this on your local computer? If you want to connect to your mysql database on OpenShift from your local computer, you need to use the rhc port-forward command, and look at the port it gives you for mysql, so then you would set the ip to 127.0.0.1 and the port to something like 3307 or whatever it gives you locally. Keep the port-forward command running while you test the connection. You could also try pushing your code up to openshift and run it with the values that you have (or use the mysql environment variables that you can get with env | grep MYSQL on your gear) and then see if it works.
127.x.x.x are not publicly available ip addresses, they are private to that server, that is why you can't connect to it from your machine, and need to use the rhc port-forward command
This works for me:
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '127.0.0.1',
port : '3306',
user : 'admind4DxYD5',
password : 'some_pass',
database : 'developercorey'
});
connection.connect( function(err){
if (err){
throw err;
}
else {
console.log('Connected');
}
});