在docker仓库中搜索mysql的镜像
1 docker search mysql 下载镜像
1 docker pull mysql 启动
参数 -p 设置端口,–name 取名 ,-e MYSQL_ROOT_PASSWORD=123456 设置 账号为 root ,密码为 123456 ,-d 表示作为一个守护进程在后台运行
1 docker run -p 3306:3306 --name JY_mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql 宿主机连接docker中的mysql
错误的连接方式
1 2 3 4 5 $ mysql -u root -p Enter password: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) # 可以看出这样会报错 正确的连接方式
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 $ mysql -h 127.0.0.1 -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 5.7.26 MySQL Community Server (GPL) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. 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> 在docker容器中连接宿主机中的mysql
...