我的编程空间,编程开发者的网络收藏夹
学习永远不晚

Docker安装Mysql5.7

短信预约 信息系统项目管理师 报名、考试、查分时间动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

Docker安装Mysql5.7

Docker安装Mysql5.7

Docker安装

系统版本:CentOS Linux release 7.5.1804 (Core)

如果之前有装过docker可以先卸载旧版本再安装,没有则跳过。

yum remove docker 
                  docker-client 
                  docker-client-latest 
                  docker-common 
                  docker-latest 
                  docker-latest-logrotate 
                  docker-logrotate 
                  docker-engine

 

安装软件包:

yum install -y yum-utils 
device-mapper-persistent-data 
lvm2

 

设置镜像仓库:

yum-config-manager 
 --add-repo 
 https://download.docker.com/linux/centos/docker-ce.repo

 

安装docker:

yum install -y docker-ce docker-ce-cli containerd.io

 

启动docker:

systemctl start docker

 

可以进行测试:

# docker run hello-world
Unable to find image "hello-world:latest" locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:fc6a51919cfeb2e6763f62b6d9e8815acbf7cd2e476ea353743570610737b752
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/get-started/

 

安装Mysql5.7

可以看下镜像库里的mysql相关镜像:

# docker search mysql
NAME                              DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
mysql                             MySQL is a widely used, open-source relation…   9191                [OK]
mariadb                           MariaDB is a community-developed fork of MyS…   3273                [OK]
mysql/mysql-server                Optimized MySQL Server Docker images. Create…   679                                     [OK]
centos/mysql-57-centos7           MySQL 5.7 SQL database server                   70
mysql/mysql-cluster               Experimental MySQL Cluster Docker images. Cr…   63
centurylink/mysql                 Image containing mysql. Optimized to be link…   61                                      [OK]
deitch/mysql-backup               REPLACED! Please use http://hub.docker.com/r…   41                                      [OK]
bitnami/mysql                     Bitnami MySQL Docker Image                      36                                      [OK]
tutum/mysql                       Base docker image to run a MySQL database se…   34
schickling/mysql-backup-s3        Backup MySQL to S3 (supports periodic backup…   29                                      [OK]
prom/mysqld-exporter                                                              27                                      [OK]
linuxserver/mysql                 A Mysql container, brought to you by LinuxSe…   24
centos/mysql-56-centos7           MySQL 5.6 SQL database server                   19
circleci/mysql                    MySQL is a widely used, open-source relation…   19
mysql/mysql-router                MySQL Router provides transparent routing be…   14
arey/mysql-client                 Run a MySQL client from a docker container      13                                      [OK]
databack/mysql-backup             Back up mysql databases to... anywhere!         10
openshift/mysql-55-centos7        DEPRECATED: A Centos7 based MySQL v5.5 image…   6
fradelg/mysql-cron-backup         MySQL/MariaDB database backup using cron tas…   5                                       [OK]
genschsa/mysql-employees          MySQL Employee Sample Database                  4                                       [OK]
devilbox/mysql                    Retagged MySQL, MariaDB and PerconaDB offici…   2
ansibleplaybookbundle/mysql-apb   An APB which deploys RHSCL MySQL                2                                       [OK]
jelastic/mysql                    An image of the MySQL database server mainta…   1
monasca/mysql-init                A minimal decoupled init container for mysql    0
widdpim/mysql-client              Dockerized MySQL Client (5.7) including Curl…   0                                       [OK]

第一条就是官方的镜像,目前是8.0版本,由于我们需要的是5.7的所以要带上版本号来拉镜像。

# docker pull mysql:5.7
5.7: Pulling from library/mysql
Image docker.io/library/mysql:5.7 uses outdated schema1 manifest format. Please upgrade to a schema2 image for better future compatibility. More information at https://docs.docker.com/registry/spec/deprecated-schema-v1/
68ced04f60ab: Downloading
f9748e016a5c: Downloading
da54b038fed1: Downloading
6895ec5eb2c0: Downloading
111ba0647b87: Downloading
c1dce60f2f1a: Downloading
702ec598d0af: Downloading
63cca87a5d4d: Downloading
ec05b7b1c5c7: Downloading
834b1d9f49b0: Downloading
8ded6a30c87c: Downloading
5.7: Pulling from library/mysql
68ced04f60ab: Pull complete
f9748e016a5c: Pull complete
da54b038fed1: Pull complete
6895ec5eb2c0: Pull complete
111ba0647b87: Pull complete
c1dce60f2f1a: Pull complete
702ec598d0af: Pull complete
63cca87a5d4d: Pull complete
ec05b7b1c5c7: Pull complete
834b1d9f49b0: Pull complete
8ded6a30c87c: Pull complete
Digest: sha256:f4a5f5be3d94b4f4d3aef00fbc276ce7c08e62f2e1f28867d930deb73a314c58
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7

 

查看本地镜像

# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
mysql               5.7                 84164b03fa2e        15 hours ago        456MB
hello-world         latest              fce289e99eb9        14 months ago       1.84kB

可以看到版本是5.7

 

创建所需目录,用以挂载外部配置文件和数据目录:

mkdir /data
mkdir /data/mysql3306
mkdir /data/mysql3306/conf.d
mkdir /data/mysql3306/data/

 

编辑配置文件,以下配置文件仅供参考:

# vim /data/mysql3306/my.cnf
[client]
port= 3306
socket  = /tmp/mysql.sock
#default-character-set = utf8mb4

## The MySQL server
[mysqld]
port = 3306
socket  = /tmp/mysql.sock
user = mysql
skip-external-locking
skip-name-resolve
#skip-grant-tables
#skip-networking
###################################### dir
#basedir=/usr/local/mysql
datadir=/var/lib/mysql
tmpdir=/var/lib/mysql
secure_file_priv=/var/lib/mysql
###################################### some app
log-error=mysql.err
pid-file=/var/lib/mysql/mysql.pid
local-infile=1
event_scheduler=0
federated
default-storage-engine=InnoDB
#default-time-zone= "+8:00"
log_timestamps=SYSTEM
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect="SET NAMES utf8mb4"
#5.6
explicit_defaults_for_timestamp=true

#fulltext
innodb_optimize_fulltext_only
ft_min_word_len=1
#ft_max_word_len
innodb_ft_min_token_size=1

###################################### memory allocate and myisam configure
max_connections=3000
#back_log=200
max_connect_errors=10000

key_buffer_size = 16M
max_allowed_packet = 16M
table_open_cache = 10240
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 2M
join_buffer_size=2M
myisam_sort_buffer_size = 4M
#net_buffer_length = 2M
thread_cache_size = 24

query_cache_type=1
query_cache_size=256M
query_cache_limit=32M

tmp_table_size=1G
max_heap_table_size=1G

#thread_concurrency =48
###################################### replication
server-id = 19216810951
log-bin=mysql-bin
binlog_format=mixed
max_binlog_size=1G
#binlog_cache_size=512M
log_slave_updates=true
log_bin_trust_function_creators=true
expire_logs_days=15
replicate-ignore-db=mysql
replicate-ignore-db=test
replicate-ignore-db=information_schema
replicate-ignore-db=performance_schema
replicate-wild-ignore-table=mysql.%
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=information_schema.%
replicate-wild-ignore-table=performance_schema.%

lower_case_table_names = 1
#read_only=1
master_info_repository=TABLE
relay_log_info_repository=TABLE

###################################### slow-query
long_query_time=1
slow_query_log=1
slow_query_log_file=/var/lib/mysql/slow-query.log
interactive_timeout=600
wait_timeout=600
#log_queries_not_using_indexes=1

###################################### innodb configure
innodb_file_per_table
#innodb_file_format=Barracuda
#innodb_io_capacity=200

innodb_data_home_dir = /var/lib/mysql
#innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
innodb_log_group_home_dir = /var/lib/mysql
innodb_buffer_pool_size =4G
# Set .._log_file_size to 25 % of buffer pool size
innodb_log_file_size = 1G
innodb_log_files_in_group = 3
innodb_log_buffer_size = 32M
#innodb_lock_wait_timeout = 50
innodb_flush_log_at_trx_commit = 1
sync_binlog=0
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
##########################################
[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
default-character-set = utf8mb4
prompt=\U \h \R:\m:\s \d>

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

 

开始启动容器

# docker run --restart=always --privileged=true -v /etc/localtime:/etc/localtime:ro -d -v /data/mysql3306/data/:/var/lib/mysql -v /data/mysql3306/conf.d:/etc/mysql/conf.d -v /data/mysql3306/my.cnf:/etc/mysql/my.cnf -p 3306:3306 --name mysql5.7 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7

参数说明:
--restart=always: 当Docker 重启时,容器会自动启动。
--privileged=true:容器内的root拥有真正root权限,否则容器内root只是外部普通用户权限
-v /opt/mysql/conf.d/my.cnf:/etc/my.cnf:映射配置文件
-v /opt/mysql/data/:/var/lib/mysql:映射数据目录
-v /etc/localtime:/etc/localtime:ro:设置容器的时间与宿主机同步
-p 3306:3306:将容器的3306端口映射到主机的3306端口
-e MYSQL_ROOT_PASSWORD=123456:设置mysql的root密码

查看容器状态:

# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                   PORTS            NAMES
5aa35cacab13        mysql:5.7           "docker-entrypoint.s…"   20 minutes ago      Up 20 minutes            0.0.0.0:3306->3306/tcp,33060/tcp   mysql5.7
3d60c83336e8        hello-world         "/hello"                 2 hours ago         Exited (0) 2 hours ago            vibrant_wescoff

 

进入容器

# docker exec -it 5aa35cacab13 /bin/bash
root@5aa35cacab13:/#

验证配置文件是否生效:

root@5aa35cacab13:/# mysql -uroot -p123456
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 3
Server version: 5.7.29-log MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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.

root@localhost localhost 17:13:48 (none)>select @@sql_mode;
+----------------------------------------------------------------+
| @@sql_mode                                                     |
+----------------------------------------------------------------+
| STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+----------------------------------------------------------------+
1 row in set (0.00 sec)

可以看到和我们配置文件里设置的一样。

 

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

Docker安装Mysql5.7

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

Docker安装Mysql5.7

Docker安装系统版本:CentOS Linux release 7.5.1804 (Core)如果之前有装过docker可以先卸载旧版本再安装,没有则跳过。yum remove docker docker-client
Docker安装Mysql5.7
2018-07-23

centos7安装docker,再在docker上安装mysql5.7

1.使用命令查看Linux内核是否在3.10以上 uname -r 如果Linux内核没有在3.10以上,则使用下面的命令升级内核版本 yum update -y 安装必要的软件包 yum install -y yum-utils device-mapper-
centos7安装docker,再在docker上安装mysql5.7
2016-11-21

mysql5.7安装

Mysql数据库的安装对于开发者来说,是我们必然会面对的问题,它的安装过程其实并不复杂,并且网络上的安装教程也非常多,但是对于新手来说,各种不同形式的安装教程,又给新手们带来了要选择哪种方式进行安装的难题,而且很多时候按照教程也没有能够安装成功,安装过程出现各
mysql5.7安装
2021-11-25

安装mysql5.7

原文:https://www.cnblogs.com/wutou/p/14509330.html
安装mysql5.7
2019-03-07

centos安装mysql5.7

切换yum源网易yum源:wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo阿里云yum源:wget -O /etc/yum.
centos安装mysql5.7
2019-03-11

yum安装mysql5.7

环境:1.centos7添加MySQL Yum存储库下载rpm包 :链接:https://pan.baidu.com/s/1ufIwmoEVOfKuGv_aTODhiQ提取码:t84u将下载的rpm包上传至服务器安装rpm包yum localinstall -
2022-02-24

怎样安装MySQL5.7

这篇文章主要为大家展示了“怎样安装MySQL5.7”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“怎样安装MySQL5.7”这篇文章吧。1、先卸载原有版本mysqlrpm -qa|grep mys
2023-06-04

windows下安装mysql5.7

1.首先官网下载ZIP安装包(即以解压,配置的方式安装)2.解压完成之后在目录下创建my.ini文件内容如下:[mysql]# 设置mysql客户端默认字符集default-character-set=utf8[mysqld]#设置3306端口port = 3
windows下安装mysql5.7
2019-06-26

Linux怎么安装mysql5.7

本篇内容主要讲解“Linux怎么安装mysql5.7”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Linux怎么安装mysql5.7”吧!MySQL 是最流行的关系型数据库管理系统,在 WEB
2023-06-28

编程热搜

目录