侧边栏壁纸
博主头像
张种恩博主等级

一个能运维的 JPG 搬运工

  • 累计撰写 703 篇文章
  • 累计创建 60 个标签
  • 累计收到 24 条评论

Docker安装连接MySql

张种恩
2019-10-17 / 0 评论 / 0 点赞 / 219 阅读 / 0 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2020-02-25,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

1、拉取 mysql5.6 镜像文件:

[root@localhost ~]# docker pull mysql:5.6
Trying to pull repository docker.io/library/mysql ... 
5.6: Pulling from docker.io/library/mysql
27833a3ba0a5: Already exists 
864c283b3c4b: Already exists 
cea281b2278b: Already exists 
8f856c14f5af: Already exists 
9c4f38c23b6f: Already exists 
688342d0934f: Pull complete 
1f90d0188066: Pull complete 
6d31565f1a00: Pull complete 
12062e921a90: Pull complete 
066ae780ca9a: Pull complete 
f6eece737bcc: Pull complete 
Digest: sha256:de2913a0ec53d98ced6f6bd607f487b7ad8fe8d2a86e2128308ebf4be2f92667
Status: Downloaded newer image for docker.io/mysql:5.6

2、创建并运行一个 mysql5.6 的容器:

[root@localhost ~]# docker run --name mysql56 -e MYSQL_ROOT_PASSWORD=root -d -p 3306:3306 mysql:5.6 --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
3f76e2bcd4e1762f40d9bd9dbd8aa5798c0e4f1035c1d518d05359fdcdcdfd19

3、通过 mysql 容器提供的客户端功能测试连接 mysql 容器:

[root@localhost ~]# docker run -it --link mysql56 --rm mysql:5.6 sh -c 'exec mysql -hmysql56 -uroot -proot'
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 1
Server version: 5.6.43 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>
0

评论区