preface

This article introduces how to use Docker to install MySQL, and connect MySQL in the terminal (iTerm2) using commands.

MySQL installation

The core commands are as follows:

# use version 8.0.17 as an exampleDocker pull mysql: 8.0.17# running mysqlDocker run -itd --name mysql8.0.17 -p 23306:3306 -e MYSQL_ROOT_PASSWORD=root mysql:8.0.17 docker psCopy the code

Log on to the MySQL

# Enter container
docker exec- it mysql8.0.17 bash# login mysql
mysql -u root -p
Copy the code