docker启动mysql

目录结构

docker-compose.yml

version: '3.4'
services:
  mysql:
    image: mysql:5.7.35
    container_name: mysql
    hostname: mysql
    restart: always
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: Abc@123456
    volumes:
      #设置时区使用宿主机时区,防止时间少8小时
      - ./localtime:/etc/localtime:ro
      - ./data:/var/lib/mysql
      - ./config:/etc/mysql/conf.d
      - ./log:/var/log/mysql/
      - ./init:/docker-entrypoint-initdb.d/
      - ./mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
    command:
      --default-authentication-plugin=mysql_native_password
      --character-set-server=utf8mb4
      --collation-server=utf8mb4_unicode_ci
      --explicit_defaults_for_timestamp=true
      --lower_case_table_names=1
      --max_allowed_packet=128M
      --default-time-zone='+8:00'
    networks:
      test:
        ipv4_address: 172.18.0.10
networks:
  test:
    external: true

mysqld.cnf

# Copyright (c) 2014, 2021, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation.  The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
datadir		= /var/lib/mysql
#log-error	= /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address	= 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
federated

init.sql

CREATE DATABASE IF NOT EXISTS nacos_config DEFAULT CHARACTER SET = 'utf8mb4';
CREATE USER 'renkaige'@'%' IDENTIFIED BY 'Abc@123456';
GRANT ALL ON nacos_config.* TO 'renkaige'@'%' IDENTIFIED BY 'Abc@123456';

mysql.conf

[mysqld]
   character-set-server=utf8mb4
[client]
   default-character-set=utf8mb4
[mysql]
   default-character-set=utf8mb4

localtime

可以从服务器的/etc/localtime获取

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Docker启动MySQL,你可以按照以下步骤进行操作: 1. 首先,确保你已经安装了Docker,并确保Docker服务正在运行。你可以使用以下命令来重启Docker服务: [2] 2. 拉取MySQL Docker镜像。你可以使用以下命令从Docker Hub上拉取MySQL镜像: [1] 3. 创建MySQL容器。你可以使用以下命令来创建一个MySQL容器: ``` docker run --name mysql-container -e MYSQL_ROOT_PASSWORD=your_password -d mysql/mysql-server ``` 在这个命令中,你需要将`your_password`替换成你想要设置的MySQL root用户的密码。这个命令将创建一个名为`mysql-container`的容器,并在后台运行MySQL服务器。 4. 等待一段时间,直到MySQL容器启动完成。你可以使用以下命令来检查容器的状态: ``` docker ps ``` 如果你看到`mysql-container`容器的状态为"Up",则表示MySQL已成功启动。 现在,你已经成功启动MySQL容器,并且可以通过连接到容器来访问MySQL数据库。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Docker启动Mysql](https://blog.csdn.net/zk673820543/article/details/77765428)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [如何在 Docker 容器中运行 MySQL](https://blog.csdn.net/allway2/article/details/121583352)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值