Docker安裝Mysql5.7

来源:https://www.cnblogs.com/wangb2/archive/2020/03/05/12421367.html
-Advertisement-
Play Games

Docker安裝 系統版本:CentOS Linux release 7.5.1804 (Core) 如果之前有裝過docker可以先卸載舊版本再安裝,沒有則跳過。 yum remove docker \ docker-client \ docker-client-latest \ docker-c ...


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)

可以看到和我們配置文件里設置的一樣。

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Windows IIS日誌提取和安全檢查分析 一、IIS日誌介紹: 1.IIS簡介: IIS全稱Internet Information Services,是由微軟公司提供的基於運行Microsoft Windwos的互聯網基本服務,IIS是一種Web(網頁)服務組件,其中包括Web伺服器、FTP服 ...
  • Step 1:更換阿裡雲 yum 源 Step 2:Apache 部分 安裝Apache : 啟動Apache服務 : 檢查Apache服務狀態是否running : 設置Apache服務自啟動守衛 : 此時,訪問伺服器的80埠,應可以看到Apache的預設頁。如果不能訪問,請檢查防火牆設置。 A ...
  • STT-MRAM是通過自旋電流實現信息寫入的一種新型非易失性磁隨機存儲器,是磁性存儲器MRAM的二代產品。STT-MRAM存儲的結構簡單,它省略了帶磁性外殼的附加寫信息線,最大限度地減少了製備工藝程式,並使存儲單元的橫截面積減小、存儲密度高、存儲速度快,滿足高性能電腦系統的設計要求。 研究人員建議 ...
  • 痞子衡嵌入式半月刊: 第 3 期 這裡分享嵌入式領域有用有趣的項目/工具以及一些熱點新聞,農曆年分二十四節氣,希望在每個交節之日準時發佈一期。 本期刊是開源項目(GitHub: "JayHeng/pzh mcu bi weekly" ),歡迎提交 issue,投稿或推薦你知道的嵌入式那些事兒。 上期 ...
  • 存儲引擎 DBMS使用存儲引擎進行數據的創建、查詢、更新、刪除操作。 不同的存儲引擎提供不同的存儲機制、索引技巧、鎖定水平等功能,使用不同的存儲引擎還可以獲得特定的功能。 MySQL提供了多種存儲引擎,最常見的有3種。 1、MyISAM MySQL5.5之前的預設的存儲引擎,每個MyISAM在磁碟上 ...
  • 分散式與雲計算第三單元答案: 1、lasS 全稱是:基礎設施即服務 2、以下哪些不是IaaS服務的優勢所在? 一次投入,終身免費 3、虛擬化作用於IaaS技術架構中那一層? 動態資源層 4、管理層的作用是對動態資源層進行統一的運維和管理,以下哪些不是管理層的主要功能 系統監控 5、PaaS全稱是:平 ...
  • 第一次寫博客,有漏洞的地方希望大佬指正 背景:優化公司老系統中的一條慢sql,查看執行過程如下: sql雖然比較簡單,平時執行也沒發現什麼問題,但一到生產環境系統頻繁調用,問題就顯現出來了,整個系統停滯不前,打開Navicat的伺服器監控發現裡面出現好多執行中的sql甚至出現死鎖 查看knowled ...
  • 下載MySQL mysql、oracle這2個資料庫都是oracle公司的,不知道是不是晚上要維護,這家公司的伺服器晚上很卡,儘量早上下載。 mysql可以下載msi、zip,但zip配置麻煩,建議使用msi。 第一個是網路安裝包,安裝時根據選擇下載插件;第二個裡面已經包含了所有插件。 安裝MySQ ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...