查看“Mysql安装之Docker mysql”的源代码
←
Mysql安装之Docker mysql
跳到导航
跳到搜索
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
=Run the application using Docker Compose= ==文件目录== <pre> mkdir -p /home/data/docker-compose-mysql/mysql mkdir -p /home/data/docker-compose-mysql/mysql docker-compose-mysql]# tree . . ├── data ├── docker-compose.yml └── mysql └── docker-my.cnf</pre> == mysql/docker-my.cnf== <pre> [mysqld] default-storage-engine=INNODB character-set-server=utf8mb4 server-id = 100 #default-time_zone = '+8:00' explicit_defaults_for_timestamp=true log-bin=mysql-bin max_connections = 10667 max_connect_errors = 6000 open_files_limit = 65535 table_open_cache = 1024 max_allowed_packet = 500M binlog_cache_size = 1M max_heap_table_size = 8M tmp_table_size = 128M read_buffer_size = 2M read_rnd_buffer_size = 8M sort_buffer_size = 8M join_buffer_size = 8M key_buffer_size = 256M thread_cache_size = 64 query_cache_type = 1 query_cache_size = 64M query_cache_limit = 2M ft_min_word_len = 4 binlog_format = mixed expire_logs_days = 7 slow_query_log = 1 long_query_time = 2 slow_query_log_file = /var/lib/mysql/mysql-slow.log general_log = 1 general_log_file = /var/lib/mysql/mysql.log [client] default-character-set=utf8mb4 [mysql] default-character-set=utf8mb4 </pre> == docker-compose.yml== <pre> version: '3.1' services: mysql: image: mysql:5.7.26 hostname: dev-hello-mysql volumes: - ./data/mysql:/var/lib/mysql - ./mysql/docker-my.cnf:/etc/mysql/conf.d/docker-my.cnf # - ./mysql/timezone:/etc/timezone ports: - 3306:3306 environment: MYSQL_ROOT_PASSWORD: pass3335 TZ: Asia/Shanghai restart: always </pre> ==usage== <pre> #本机访问 mysql yum install mysql -y #client mysql -uroot -p -h127.0.0.1 </pre> = my dockerfile= <pre> cat Dockerfile #名称: # # time FROM centos MAINTAINER evan evan886@gmail.com WORKDIR /root/ RUN yum -y install wget RUN wget http://repo.mysql.com/mysql-community-release-el7-7.noarch.rpm RUN rpm -ivh /root/mysql-community-release-el7-7.noarch.rpm RUN yum -y install mysql-server RUN mysql_install_db --user=mysql ENV MYSQL_USER test ENV MYSQL_PASS mypassword #支持中文 ENV LC_ALL en_US.UTF-8 ADD build_table.sh /root/build_table.sh RUN chmod u+x /root/build_table.sh EXPOSE 3306 ADD run.sh /root/run.sh RUN chmod u+x /root/run.sh CMD /root/run.sh cat build_table.sh #!/bin/bash mysqld_safe & sleep 3 mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASS' WITH GRANT OPTION; " mysql -e "create database evans" mysql -e "create table evans.name(name char(20) not null,evan int not null) DEFAULT CHARSET=utf8" mysql -e "insert into evans.evan values('韦子虚',36),('丽莉',33)" cat run.sh #!/bin/bash mysqld_safe docker build -t evan886/centos-mysql:v1 . Successfully built 3c3879c54e3b Successfully tagged evan886/centos-mysql:v1 [root@localhost mysql]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE evan886/centos-mysql v1 3c3879c54e3b 8 minutes ago 867MB docker push evan886/centos-mysql:v1 #测试 不加-d docker run -p 3309:3306 --name mysql -e MYSQL_ROOT_PASSWORD=mypassword --privileged=true mysql docker run -p 3309:3306 --name mysql -e MYSQL_ROOT_PASSWORD=mypassword -d --privileged=true mysql 如果想拉我的镜像 docker pull evan886/centos-mysql:v1 </pre> =测试= <pre> #我的母机是192.168.50.206 mysql -uroot -p -h 192.168.50.206 -P3309 Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g.</pre> ==完整测试== <pre> docker pull evan886/centos-mysql:v1 root@debian:~/mysql# docker images REPOSITORY TAG IMAGE ID CREATED SIZE evan886/centos-mysql v1 3c3879c54e3b 17 hours ago 867MB #运行 加-v 会有问题 docker run -p 3309:3306 --name mysql -e MYSQL_ROOT_PASSWORD=mypassword -v /data/mysql:/var/lib/mysql -d --privileged=true 3c3879c54e3b root@debian:~/mysql# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 34ce2a368d7d 3c3879c54e3b "/bin/sh -c /root/ru…" 4 minutes ago Exited (0) 4 minutes ago mysql root@debian:~/mysql# docker logs 34ce2a368d7d 180411 03:00:34 mysqld_safe Logging to '/var/log/mysqld.log'. 180411 03:00:34 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 180411 03:00:35 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended </pre> =用官方的= <pre> docker pull mysql:5.7 #config and run docker run -p 3307:3306 --restart 策略名称 -v 宿主机数据目录:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=mysql密码 -d 镜像ID docker run -p 3307:3306 --restart always -v /data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=2240800 -d 75576f90a779 </pre> =注意 = <pre> 运行启动 映射mysql外网访问端口: 3307 docker run -p 3307:3306 --restart 策略名称 -e MYSQL_ROOT_PASSWORD=mysql密码 -d 镜像ID docker run -p 3307:3306 --restart always -v /data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=224099 -d 75576f90a779 Docker容器自启动策略 no 不自动重启容器. (默认value) always 在容器已经stop掉或Docker stoped/restarted的时候才重启容器 on-failure 容器发生error而退出(容器退出状态不为0)重启容器 unless-stopped 在容器已经stop掉或Docker stoped/restarted的时候才重启容器 </pre> ==将MySQL的数据存到宿主机上== <pre>docker run -p 3307:3306 --restart 策略名称 -v 宿主机数据目录:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=mysql密码 -d 镜像ID docker run -p 3307:3306 --restart always -v /home/mysql-db-backup:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=rootroot -d 5709795eeffa</pre> ==使用本地的MySQL配置文件== <pre>docker run -p 3307:3306 --restart 策略名称 -v 宿主机数据目录:/var/lib/mysql -v 宿主机数据库配置文件目录:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=mysql密码 -d 镜像ID docker run -p 33306:3306 --restart always -v /data/mysql0:/var/lib/mysql -v /data/mysql0_conf:/etc/mysql/connf.d -e MYSQL_ROOT_PASSWORD=rootroot -d 5709795eeffa </pre> =err= <pre> # err 你现在不能用套接字建立连接因为它不见了,所以可以建立一个TCP/IP连接 mysql -uroot -p2240881 -P3307 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 您在 /var/spool/mail/root 中有新邮件 [root@localhost ~]# mysql -uroot -p2240881 -P3307 -h 127.0.0.1 Welcome to the MariaDB monitor. Commands end with ; or \g. https://blog.csdn.net/hjf161105/article/details/78850658 解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) " </pre> =see also= [https://github.com/docker-library/mysql/blob/f279c9cc0d20407a2c4d9465adae6b077dcf1b51/5.6/Dockerfile docker-library/mysql 5.6/Dockerfile] [https://itbilu.com/linux/docker/EyP7QP86M.html MySQL 官方Docker镜像的使用] [https://www.jianshu.com/p/5c18a4b01dcc?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation Docker部署安装MySQL5.7] [https://www.jyoryo.com/index.php/archives/89.html MySQL 5.6 Linux Debian/Ubuntu源码编译安装 LNMP之MySQL] [https://blog.csdn.net/sunyuhua_keyboard/article/details/81540012 docker 安装mysql 8] [https://blog.csdn.net/xiaolyuh123/article/details/72629300 Docker运行Mysql实例] [https://www.jianshu.com/p/7a01046b3c54 Docker部署(二):MySQL数据库] [https://www.cnblogs.com/atuotuo/p/9402132.html#_labelTop 修改 Docker-MySQL 容器的 默认用户加密规则] [https://blog.csdn.net/wxb880114/article/details/82219720 阿里云ECS-使用docker官方镜像安装mysql服务] [[category:ops]] [[category:容器]] [[category: container]]
返回至
Mysql安装之Docker mysql
。
导航菜单
个人工具
登录
名字空间
页面
讨论
变种
视图
阅读
查看源代码
查看历史
更多
搜索
导航
首页
我的导航
关于我
shell
python
ops
linuxchina.net
blog.linuxchina
最近更改
随机页面
帮助
工具
链入页面
相关更改
特殊页面
页面信息