Startup triggers mysql root user error from Knex

Hello,

I’m trying to get Ghost installed and running the first time, on Centos with a manual/ansible install.

Basic Info

  • Ghost version: latest
  • OS: Centos8 on Linode
  • Node: v10.21.0
  • Installing with home-grown Ansible playbook (as the playbooks I found expected Ubuntu)

The ghost mysql user and database are already setup by Ansible, and the MySQL root use has a password set.

Config

The database portion of my config looks like:

database: {
    client: 'mysql',
    connection: {
        host: 'localhost',
        user: '{{ ghost_mysql_user}}',
        password: '{{ ghost_mysql_password }}',
        database: '{{ ghost_mysql_db}}',
        charset: 'utf8'
    },
    debug: false
},

What errors or information do you see in the console?

I’m just trying to start the server:

[bloguser@li225-158 ghost]$ NODE_ENV=production node index.js
[2020-11-10 19:12:05] ERROR ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)

ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)

"Unknown database error"

Error ID:
    500

Error Code:
    ER_ACCESS_DENIED_ERROR

----------------------------------------

DatabaseError: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)
    at DatabaseError.KnexMigrateError (/var/www/ghost/node_modules/knex-migrator/lib/errors.js:7:26)
    at new DatabaseError (/var/www/ghost/node_modules/knex-migrator/lib/errors.js:55:26)
    at connection.raw.catch (/var/www/ghost/node_modules/knex-migrator/lib/database.js:48:19)

Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)
    at Handshake.Sequence._packetToError (/var/www/ghost/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
    at Handshake.ErrorPacket (/var/www/ghost/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
    at Protocol._parsePacket (/var/www/ghost/node_modules/mysql/lib/protocol/Protocol.js:291:23)
    at Parser._parsePacket (/var/www/ghost/node_modules/mysql/lib/protocol/Parser.js:433:10)
    at Parser.write (/var/www/ghost/node_modules/mysql/lib/protocol/Parser.js:43:10)
    at Protocol.write (/var/www/ghost/node_modules/mysql/lib/protocol/Protocol.js:38:16)
    at Socket.<anonymous> (/var/www/ghost/node_modules/mysql/lib/Connection.js:88:28)
    at Socket.<anonymous> (/var/www/ghost/node_modules/mysql/lib/Connection.js:526:10)
    at Socket.emit (events.js:198:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at Socket.Readable.push (_stream_readable.js:224:10)
    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
    --------------------
    at Protocol._enqueue (/var/www/ghost/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/var/www/ghost/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at Connection.connect (/var/www/ghost/node_modules/mysql/lib/Connection.js:116:18)
    at Promise (/var/www/ghost/node_modules/knex-migrator/node_modules/knex/lib/dialects/mysql/index.js:69:18)
    at Promise._execute (/var/www/ghost/node_modules/bluebird/js/release/debuggability.js:384:9)
    at Promise._resolveFromExecutor (/var/www/ghost/node_modules/bluebird/js/release/promise.js:518:18)
    at new Promise (/var/www/ghost/node_modules/bluebird/js/release/promise.js:103:10)
    at Client_MySQL.acquireRawConnection (/var/www/ghost/node_modules/knex-migrator/node_modules/knex/lib/dialects/mysql/index.js:64:12)
    at create (/var/www/ghost/node_modules/knex-migrator/node_modules/knex/lib/client.js:291:39)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

Knex apparently wants to run migrations using the root user? and I cannot find any reference for changing this behavior…

I have confirmed that the blog user exists in MySQL, can login, and has the correct grants.

ok, might as well share the debugging process…

Added a console.log in /var/www/ghost/node_modules/knex-migrator/node_modules/knex/lib/dialects/mysql/index.js
to log the connection data:

{ host: '127.0.0.1',
  user: 'root',
  password: '',
  database: 'ghost',
  timezone: 'UTC',
  charset: 'utf8mb4',
  loggingHook: [Function: loggingHook],
  collation: 'utf8mb4_general_ci' 
}

Looks like it’s not picking up the configurattion in config.production.js in the Ghost home directory. Time to see why

Try changing it to config.production.json

Looks like that was it. Not sure I even remember where I found the template, but the template was a .js file, not proper json. Fixing that seems to have done the trick :slight_smile: