After deploying the Ghost blogging platform with success, i tried to configure it to use Mysql instead of sqllite3 using this database section of their config page, which says:
Database
By default, Ghost comes configured to use an SQLite database, which
requires no configuration.
Alternatively Ghost can also be used with a MySQL database by changing
the database configuration. You must create a database and user first,
you can then change the existing sqlite config to something like:
database: { client: 'mysql', connection: {
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'ghost_db',
charset : 'utf8' }
}
So ok, the setup is straight forward. but i'm still unable to connect ghost with mysql. The error i receive after starting the platform using npm start --production is :
> ghost#0.6.2 start /var/www/ghost
> node index
Migrations: Database initialisation required for version 003
Migrations: Creating tables...
Migrations: Creating table: posts
ERROR: connect ECONNREFUSED
Error: connect ECONNREFUSED
at errnoException (net.js:905:11)
at Object.afterConnect [as oncomplete] (net.js:896:19)
--------------------
at Protocol._enqueue (/var/www/ghost/node_modules/mysql/lib/protocol/Protocol.js:110:48)
at Protocol.handshake (/var/www/ghost/node_modules/mysql/lib/protocol/Protocol.js:42:41)
at Connection.connect (/var/www/ghost/node_modules/mysql/lib/Connection.js:98:18)
at /var/www/ghost/node_modules/knex/lib/dialects/mysql/index.js:105:16
at tryCatch2 (/var/www/ghost/node_modules/bluebird/js/main/util.js:53:21)
at Promise._resolveFromResolver (/var/www/ghost/node_modules/bluebird/js/main/promise.js:544:13)
at new Promise (/var/www/ghost/node_modules/bluebird/js/main/promise.js:84:37)
at Client_MySQL.acquireRawConnection (/var/www/ghost/node_modules/knex/lib/dialects/mysql/index.js:104:10)
at Object.create (/var/www/ghost/node_modules/knex/lib/pool.js:33:19)
at Object.Pool.createResource (/var/www/ghost/node_modules/knex/node_modules/generic-pool-redux/pool.js:288:12)
I'm not sure what could be wrong, since i have other applications using mysql working without any problems.
Thanks in advance.
connection refused = tcp connection was attempted, but nothing is listening on the port, or was explicitly denied. Unless you explicitly enabled TCP support in mysql (and have the correct ip/port), you should probably be using a local unix-domain socket instead.
Related
I am trying to connect to a LocalDB\MSSQLLocalDB SQLExpress instance in my Node.js application that uses Objection.js/Knex for the data layer.
When I try to run a migration it fails to connect to the database. But I can connect via SSMS without issue.
Here is my Knexfile.js connection settings
module.exports = {
development: {
client: 'mssql',
useNullAsDefault: true,
connection: {
server: '(LocalDB)\\MSSQLLocalDB',
user: 'localadmin',
password: 'password$',
database: 'database'
},
migrations: {
directory: './migrations',
tableName: 'knex_migrations'
},
seeds: {
directory: './seeds'
},
...knexSnakeCaseMappers()
}
};
When I run a migration it gives the following error:
Failed to connect to (LocalDB)\MSSQLLocalDB:1433 - getaddrinfo ENOTFOUND (LocalDB)\MSSQLLocalDB
Error: Failed to connect to (LocalDB)\MSSQLLocalDB:1433 - getaddrinfo ENOTFOUND (LocalDB)\MSSQLLocalDB
at Connection.socketError (D:\Code\backend\node_modules\tedious\lib\connection.js:1393:28)
at D:\Code\backend\node_modules\tedious\lib\connection.js:1153:21
at GetAddrInfoReqWrap.callback (D:\Code\backend\node_modules\tedious\lib\connector.js:195:16)
at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:77:17)
I believe this is an issue with tcp/ip settings in SqlExpress but I cannot find an easy way to change those.
Is there any settings for the Knexfile that will allow for a SQLExpress database connection?
LocalDB only accepts named pipes connections. Use proper SQL Express and enable TCP connections
I am trying to connect my SQL Server database with node.js using knex but I am facing issue
Error: No event 'socketConnect' in state 'SentPrelogin'
at Connection.dispatchEvent (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1281:26)
at Connection.socketConnect (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1303:10)
at C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1145:12
at Socket.onConnect (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connector.js:106:7)
at Socket.emit (events.js:314:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1131:10)
Emitted 'error' event on Connection instance at:
at Connection.dispatchEvent (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1281:12)
at Connection.socketConnect (C:\Users\temp\Documents\PRactice\node_modules\tedious\lib\connection.js:1303:10)
[... lines matching original stack trace ...]
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1131:10)
[nodemon] app crashed - waiting for file changes before starting...
My code is
var knex = require('knex')({
client: 'mssql',
version:"7_1",
connection: {
user: 'sa',
password: 'Admin#123',
server: 'localhost',
database: 'Demo'
}
});
knex.select("*").from("Country")
.then(function (depts){
depts.forEach((dept)=>{ //use of Arrow Function
console.log({...dept});
});
}).catch(function(err) {
// All the error can be checked in this piece of code
console.log(err);
}).finally(function() {
// To close the connection pool
knex.destroy();
});
You need to add a missing dependency:
npm install --save tedious
As of knex v0.95.0 you'll need to use the tedious library instead of mssql when connecting to an MSSQL database. According to the knex upgrade instructions:
MSSQL driver was completely reworked in order to address the multitude of connection pool, error handling and performance issues. Since the new implementation uses tedious library directly instead of mssql, please replace mssql with tedious in your dependencies if you are using a MSSQL database.
Installing the package above should resolve your issue. I also had to set the encrypt option to false when connecting to my local database to avoid this error:
ConnectionError: Failed to connect to localhost:1433 - self signed certificate
while trying to connect to my cloudsql instance I am getting this error
{
errorno: "ETIMEDOUT",
code: "ETIMEDOUT",
syscall: "connect",
fatal: true
}
this is the log from my cloudsqlproxy container
2020/06/09 15:53:04 current FDs rlimit set to 1048576, wanted limit is 8500. Nothing to do here.
2020/06/09 15:53:04 using credential file for authentication; email=lion-db#estatelion-test-275318.iam.gserviceaccount.com
2020/06/09 15:53:04 Listening on 127.0.0.1:3306 for estatelion-test-275318:us-central1:estatelion
2020/06/09 15:53:04 Ready for new connections
but my nodejs application is unable to connect to it
const connection = mysql.createPool({
connectionLimit: 10,
host: config.get("database").host, // localhost
user: config.get("database").user, // cloud proxy user for my cloudsql instance
password: config.get("database").password, // password
database: config.get("database").db_name, // database
});
Well I found the solution to this
I just updated the Cluster version to 1.15.11-gke.15 from 1.14.* (I dont remember the rest ) and it worked fine.
I think there is some bug in the default GKE version of the deployment.
Thanks Everyone for your gracious time and effort. :-)
I have 3 servers which run a MongoDB replicaset, 1 primary, 1 secondary, 1 arbiter. And I have problem connecting to this replicaset. Tested with a test.js file which runs on localhost and a spare server.
Connect from localhost, node 6.5.0: OK
Connect from localhost, node 10.15.1: FAILED
Connect from the spare server, node 6.5.0: OK
Connect from the spare server, node 10.15.1: OK
Here's my test.js file:
const MongoClient = require("mongodb").MongoClient;
const url = "mongodb://root:password"+
"#mgdb1.mydomain,mgdb2.mydomain/vApp?replicaSet=rs0&authSource=admin";
console.log("Connecting...");
MongoClient.connect(url,(err,client)=>{
if (err!=null){
console.log("Error:",err);
return;
}
console.log("Connected.");
process.exit();
});
The strange thing is that it shows ECONNREFUSED error, but not at the IP of the 3 servers in the replicaset, it's the IP in range of my ISP. So why does it fail afterConnect? It shows TCPConnectWrap.afterConnect, does it mean the connection is already made?
The error is this way:
Connecting...
(node:1412) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
Error: { Error: connect ECONNREFUSED 125.235.4.59:27017
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1104:14)
errno: 'ECONNREFUSED',
code: 'ECONNREFUSED',
syscall: 'connect',
address: '125.235.4.59',
port: 27017 }
Edit:
My current work-around is connecting directly to the primary server without replicaset=rs0, however, this is not the desired manner.
I found out the problem. When created the replica set on a group of machines on cloud, the addresses to the servers are server names which are known only by other machines on the same server LAN. On localhost in office, there are no such server names.
Work-around 1:
Connect only to the primary or secondary server
Work-around 2:
Edit /etc/hosts file (or c:\windows\system32\drivers\etc\hosts)
Point the name of the servers to their appropriate IPs
Having a bit of trouble with this. Trying out Google Cloud at the moment and cant my GCloud Postgres db to link to my app engine app.
I'm following everything here :
https://cloud.google.com/appengine/docs/flexible/nodejs/using-cloud-sql-postgres
However, when I try to run the createTables.js process I get the following issue:
Failed to create 'visits' table: { Error: connect ECONNREFUSED 127.0.0.1:5432
at Object._errnoException (util.js:1026:11)
at _exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1174:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5432 }
Databases aren't really my strong point so I'm a bit stumped.
These are both running in the same GCloud Project also.
Let me know if you need me to supply any more info (not sure exactly what is useful)
Cheers,
Jay
To establish a connection between Google Cloud Postgres and App Engine, try these steps:
Enable the API
Install the proxy client on your local machine
Decide who will authenticate the proxy
Create a service account, in case your authentication method demands it
Decide how you will specify instances for your proxy
Start the proxy
Update your app and connect it to Googe Cloud Postgres