Search code examples
phpmysqldockerdocker-composephinx

Access denied when running phinx command on Docker container


I am running the official MySQL Docker container for my PHP app. I am using Phinx for migrations. The MySQL image seems to work fine as I can connect to it as 'dbuser' (non-root) using MySQL Workbench. I can also connect with Docker exec as well.

Problem occurs when I try to run any Phinx command, such as status. I'm getting:

[InvalidArgumentException]
There was a problem connecting to the database: SQLSTATE[HY000][1045] Access denied for user 'dbuser'@'localhost' (using password: YES)

My grants on the DB look like:

GRANT USAGE ON *.* TO 'dbuser'@'%' IDENTIFIED BY PASSWORD '*8232A1298A49F710DBEE0B330C42EEC825D4190A'
GRANT ALL PRIVILEGES ON `dbuser`.* TO 'app_db'@'%'

My development section of the phinx.yml file looks like:

development:
    adapter: mysql
    host: localhost
    name: app_db
    user: dbuser
    pass: '<no-hash-password>'
    port: 3306
    charset: utf8

Any ideas?


Solution

  • Solved it: I had MySQL running on the host as well (different port 3307), so I shut that down. I'm now able to run phinx within the container. Looks like it might have been trying to connect to the host server via unix socket, instead of port 3306 on the container.