After deciphering the comments below, it seems you are adding docker run
arguments AFTER the image name. These args will be passed to the process inside the container - likely why you are seeing mysqld errors, because you are passing Docker flags to mysqld. The below answer still applies.
I'm not on Windows but this should be platform independent if you're using the standard client to connect and running the server in Docker.
You have the Docker commands right, this is a valid Docker command and works fine, exposing port 3306:
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -p 3306:3306 -d mysql:latest
Docker logs for the container that is started show:
[Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.32' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
The problem likely exists somewhere else in your setup, not related to running the container with the -p
argument.
Are you sure you're using mysql
client to connect with? (not mysqld
) ??
Example connection after starting the server:
>> mysql -u root -p -h 127.0.0.1 -P 3306
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>