docker exec -it $docker ps grep mysql awk print $1 env LANG=CUTF-8 mysql -uroot -p
This command will execute a shell command inside a running Docker container that has MySQL installed. Here's how it works:
docker execis the command used to execute a command inside a running Docker container.-itspecifies that we want to run the command interactively, giving us a shell prompt inside the container.$(docker ps | grep mysql | awk '{print $1})is a subcommand that finds the ID of the running Docker container that has MySQL installed. Here's how it works:docker pslists all running Docker containers.grep mysqlfilters the list of containers to only show those that have "mysql" in their name.awk '{print $1}'extracts the first column of the output, which is the container ID.
env LANG=C.UTF-8sets the environment variable LANG to C.UTF-8, which ensures that MySQL uses UTF-8 encoding.mysql -uroot -pis the command we want to execute inside the container. It starts the MySQL client and connects to the MySQL server running on the same container, using the root user and prompting for a password
原文地址: https://www.cveoy.top/t/topic/fJQz 著作权归作者所有。请勿转载和采集!