How to use MySQL in Docker
This article is to share with you about how to use MySQL in Docker. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.
Download the image:
# docker pull mysql
Create a MySQL instance:
# docker run-p 3306 MYSQL_ROOT_PASSWORD=123456 3306-- name mysql-e MYSQL_ROOT_PASSWORD=123456-d chag/mysql
Connect to the MySQL:
# docker run-it-- link mysql:mysql-- rm mysql sh-c 'exec mysql-h "$MYSQL_PORT_3306_TCP_ADDR"-P "$MYSQL_PORT_3306_TCP_PORT"-uroot-p "$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'
You can also go directly to the container and connect to MySQL.
# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 944ba58d59dd chag/mysql:latest "/ entrypoint.sh mysq 7 days ago Up 7 hours 0.0.0.0 days ago Up 3306-> 3306/tcp mysql
Use the docker-enter command
# docker-enter mysqlroot@944ba58d59dd:~# mysql-uroot-p123456
You can enter mysql:
Warning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 1Server version: 5.6.25 MySQL Community Server (GPL) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c'to clear the current input statement.mysql > show databases +-+ | Database | +-+ | information_schema | | mysql | | orcl | | performance_schema | +-+ 4 rows in set (0.16 sec) above is how to use MySQL in Docker The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.