Docker-compose install mysql

introduce

This series of articles mainly introduces the use of docker-compose to deploy middleware such as mysql, nginx, and redis, and separates the deployment process of microservice projects before and after. I don't introduce docker installation and basic commands, so I will first enter the mysql installation teaching without talking much.

operate

First create a directory to store the docker-compse file and mysql data storage address

The docker-compose file is as follows

version : '3'
services:
  zzx-mysql:
      # 容器名(以后的控制都通过这个)
    container_name: zzx-mysql
      # 重启策略
    restart: always
    image: mysql:5.7
    ports:
      - "3306:3306"
    volumes:
       # 挂挂载配置文件
       #  - ./mysql/db/:/docker-entrypoint-initdb.d
      # 挂挂载配置文件
      - ./mysql/conf:/etc/mysql/conf.d
      # 挂载日志
      - ./mysql/logs:/logs
      # 挂载数据
      - ./mysql/data:/var/lib/mysql
    command: [
          'mysqld',
          '--innodb-buffer-pool-size=80M',
          '--character-set-server=utf8mb4',
          '--collation-server=utf8mb4_unicode_ci',
          '--default-time-zone=+8:00',
          '--lower-case-table-names=1'
        ]
    environment:
      # root 密码
      MYSQL_ROOT_PASSWORD: 123456

Through the docker images command, we can see that there is no mysql5.7 image in our local warehouse at this time, and the mysql folder is also empty

Next, we execute the docker-compose up -d zzx-mysql command in the docker-compose directory

At this point we have completed the installation of mysql5.7 in the docker environment

Open the mysql folder and we can see the configuration files, logs, and data in the container have been mounted to the host

Then we open navicat and try to connect

The connection has been completed. In the next section, we will try to install redis in the docker-compose environment. The important thing is said three times.

Wang Gen is better than Ben! ! ! ! !

Wang Gen is better than Ben! ! ! ! !

Wang Gen is better than Ben! ! ! ! !

at last

I know that most junior and middle-level Java engineers want to improve their skills, and they often try to grow by themselves or enroll in classes. However, the tuition fees of nearly 10,000 yuan for training institutions are really stressful. The effect of self-study is inefficient and long, and it is easy to hit the ceiling and stagnate in technology!

Therefore, I collected and sorted out a " Complete Set of Learning Materials for Java Development " and gave it to everyone. The original intention is also very simple, that is, I hope to help friends who want to learn and improve themselves but don't know where to start, and at the same time reduce everyone's burden.

The editor has encrypted: aHR0cHM6Ly9kb2NzLnFxLmNvbS9kb2MvRFVrVm9aSGxQZUVsTlkwUnc==For security reasons, we have encoded the website through base64, and you can decode the URL through base64.

Guess you like

Origin blog.csdn.net/m0_67390963/article/details/126801699