MySQL takes several minutes to start-up the first time since it must initialize the database. I suspect it also restarts during that time which could cause some issues for Docker.
I’d recommend using
-it to keep the container running and mounting a persistent volume so subsequent start-ups take a couple of seconds:
docker run \
-it --rm --name mysql \
-p 9876:3306 \
--mount "src=mysqldata,target=/var/lib/mysql" \
-e MYSQL_ROOT_PASSWORD=password \
My Docker for Web Developers book and video course describes how to create good development environments using Docker and Docker Compose. There’s a chapter about using MySQL and similar databases. Use the discount code
dock30 for 30% off.