创建存储目录
[root@hecs-x-large-2-linux-20200321161149 ~]# mkdir -p /opt/data/mysql/data /opt/data/mysql/conf
基本使用
- 创建区分大小写文件
[root@iZrj987jhi4cl38mj8px0eZ conf]# cd /opt/data/mysql/conf/ cat >> my.cnf <<EOF [mysqld] lower_case_table_names = 1 EOF
- 下载镜像
[root@hecs-x-large-2-linux-20200321161149 ~]# docker pull mysql:8.0
- 查看镜像
[root@hecs-x-large-2-linux-20200321161149 ~]# docker images|grep mysql mysql 8.0 be0dbf01a0f3 2 days ago 541MB
启动容器
options说明:
–restart=always: 重启策略
-d: 后台运行容器,并返回容器ID
-p: 端口映射,格式为:主机(宿主)端口:容器端口
–name: 为容器指定一个名称
-v: 给容器挂载存储卷,挂载到容器的某个目录
-e MYSQL_ROOT_PASSWORD: 设置数据库密码
[root@iZrj987jhi4cl38mj8px0eZ ~]# docker run --restart=always --name=mysql8.0 -p 16380:3306 -v /opt/data/mysql/conf/my.cnf:/etc/my.cnf -v /opt/data/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=tgY7gHN7dhlAn7zS -e TZ=Asia/Shanghai -d mysql:8.0
进入容器
[root@iZrj987jhi4cl38mj8px0eZ ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 59e79e4e53af mysql:8.0 "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 33060/tcp, 0.0.0.0:3000->3306/tcp mysql8.0 [root@iZrj987jhi4cl38mj8px0eZ ~]# docker exec -it mysql8.0 /bin/bash
启动/停止容器
[root@iZrj987jhi4cl38mj8px0eZ ~]# docker start mysql8.0 mysql8.0 [root@iZrj987jhi4cl38mj8px0eZ ~]# docker stop mysql8.0 mysql8.0 [root@iZrj987jhi4cl38mj8px0eZ ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
删除容器与镜像
- 删除容器
[root@iZrj987jhi4cl38mj8px0eZ ~]# docker rm mysql8.0 mysql8.0 [root@iZrj987jhi4cl38mj8px0eZ ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 删除镜像
[root@iZrj987jhi4cl38mj8px0eZ ~]# docker rmi mysql:8.0
- 查看日志
[root@iZrj987jhi4cl38mj8px0eZ ~]# docker logs mysql8.0 2020-06-13 12:22:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started. 2020-06-13 12:22:18+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' 2020-06-13 12:22:18+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started. 2020-06-13 12:22:18+00:00 [Note] [Entrypoint]: Initializing database files 2020-06-13T12:22:18.586281Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and wil l be removed in a future release. 2020-06-13T12:22:18.586369Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.20) initializing of server in progress as process 42 2020-06-13T12:22:18.602581Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2020-06-13T12:22:19.825711Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2020-06-13T12:22:21.170894Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. 2020-06-13 12:22:24+00:00 [Note] [Entrypoint]: Database files initialized 2020-06-13 12:22:24+00:00 [Note] [Entrypoint]: Starting temporary server 2020-06-13T12:22:24.581386Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and wil l be removed in a future release. 2020-06-13T12:22:24.581537Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.20) starting as process 89 2020-06-13T12:22:24.603934Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2020-06-13T12:22:25.360541Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2020-06-13T12:22:25.571847Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' 2020-06-13T12:22:25.856802Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed. 2020-06-13T12:22:25.860069Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different direct ory. 2020-06-13T12:22:25.896608Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.20' socket: '/var/run/mysqld/mysqld.sock' port: 0 MySQL Community Server - GPL. 2020-06-13 12:22:25+00:00 [Note] [Entrypoint]: Temporary server started. Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it. Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it. 2020-06-13 12:22:29+00:00 [Note] [Entrypoint]: Stopping temporary server 2020-06-13T12:22:29.082564Z 10 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.20). 2020-06-13T12:22:30.764389Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.20) MySQL Community Server - GPL. 2020-06-13 12:22:31+00:00 [Note] [Entrypoint]: Temporary server stopped 2020-06-13 12:22:31+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
继续阅读
- 我的QQ
- QQ扫一扫
-
- 我的头条
- 头条扫一扫
-
评论