Search code examples
node.jsghost-blog

Ghost Blog - Unable to connect with mysql


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.


Solution

  • 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.