Search code examples
mysqldockersequelpro

Docker instance of MySQL is not setting root password -- any login without a password is allowed


I set up a new computer running macOS 10.14.5 and Docker Desktop community 2.0.0.3 (31259) and I noticed that my MySQL container wasn't being created properly. This is the command that I had run on my previous computer:

docker run --name virtual-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=mypassword -d mysql:5.7.22

That worked: it would properly set the root password. But on the new computer, when I run that command, the root password is NOT set. I can log in as the root user, but only if I leave the password blank. Only the root user can create a database.

But more curiously, I can specify ANYTHING as the user, e.g. asdf and successfully log in (!!!). When I log in as a non-existent user, I can only view the information_schema and I cannot create a database, however -- I get an error: Access denied for user ''@'localhost' to database 'asdf' -- which suggests that perhaps my client isn't sending the login credentials correctly (I am using Sequel Pro 1.1.2 as my MySQL client).

Can someone explain this strange behavior?


Solution

  • After some helpful nudging, I figured out where this was going off the rails.

    First problem: one of the apps I installed had installed an instance of MySQL onto the host OS. I didn't notice it because I had done which mysql from an open Terminal window that didn't have its PATH updated.

    Second problem: mysqld kept running a process that bound to port 3306. I didn't notice this until running lsof -Pnl +M -i4 | grep 'LISTEN'lsof -Pnl +M -i4 | grep 'LISTEN' revealed it. I had my suspicions when I could bring up new dockerized instances bound to other ports.

    So the solution was to THOROUGHLY delete mysql (and mysqld), then REBOOT to shake any dangling connections. Once I had done that, my dockerized versions ran fine.