FeelingLife FeelingLife
首页
  • Go

    • Go基础知识
  • Python

    • Python进阶
  • 操作系统
  • 计算机网络
  • MySQL
  • 学习笔记
  • 常用到的算法
  • Docker
  • Kubernetes
  • Observability
  • 容器底层
其他技术
  • 友情链接
  • 收藏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

xuqil

一介帆夫
首页
  • Go

    • Go基础知识
  • Python

    • Python进阶
  • 操作系统
  • 计算机网络
  • MySQL
  • 学习笔记
  • 常用到的算法
  • Docker
  • Kubernetes
  • Observability
  • 容器底层
其他技术
  • 友情链接
  • 收藏
关于
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 环境搭建

    • 环境搭建
    • MySQL 容器形式搭建
      • 创建工作目录
      • 编写 docker-compose.yaml
      • 设置配置文件
      • 启动 MySQL
      • 检查 MySQL
      • 参考
  • 事务

  • 数据库优化

  • 日志

  • 《探下MySQL》
  • 环境搭建
xuqil
2023-03-31
目录

MySQL 容器形式搭建

# 容器形式安装 MySQL5.7

# 创建工作目录

mkdir -p /opt/mysql57/{mydir,data,conf}
1

# 编写 docker-compose.yaml

version: '3'

services:
  mysql:
    image: mysql:5.7
    # NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
    # (this is just an example, not intended to be a production configuration)
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    container_name: mysql57
    ports:
      - 3306:3306 # 宿主机 port:容器 port
    volumes:
      - /opt/mysql57/data:/var/lib/mysql
      - /opt/mysql57/conf/my.cnf.d:/etc/my.cnf.d/
      - /opt/mysql57/conf/my.cnf:/etc/my.cnf
    environment:
      MYSQL_ROOT_PASSWORD: youpassword
      TZ: Asia/Shanghai
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# 设置配置文件

/opt/mysql/conf/my.cnf

[mysqld]
user=mysql
default-storage-engine=INNODB
character-set-server=utf8
character-set-client-handshake=FALSE
collation-server=utf8_unicode_ci
init_connect='SET NAMES utf8'

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8
1
2
3
4
5
6
7
8
9
10
11
12
13

# 启动 MySQL

# docker compose up -d
[+] Running 1/1
 ⠿ Container mysql57  Started
# docker compose ps
NAME                IMAGE               COMMAND                  SERVICE             CREATED             STATUS              PORTS
mysql57             mysql:5.7           "docker-entrypoint.s…"   mysql               5 minutes ago       Up 5 minutes        0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp
1
2
3
4
5
6

# 检查 MySQL

进入 MySQL 容器:

# docker exec -it mysql57 bash
1

登录 MySQL:

# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.41 MySQL Community Server (GPL)

Copyright (c) 2000, 2023, Oracle and/or its affiliates.

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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

# 参考

https://hub.docker.com/_/mysql/tags

上次更新: 2024/05/29, 06:25:22
环境搭建
事务隔离性和隔离级别

← 环境搭建 事务隔离性和隔离级别→

最近更新
01
VXLAN互通实验
05-13
02
VXLAN
05-13
03
VLAN
05-13
更多文章>
Theme by Vdoing | Copyright © 2018-2025 FeelingLife | 粤ICP备2022093535号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式