网站首页 > 技术文章 正文
一、安装数据库
1、导入镜像:
说明:考虑到从网上镜像不好下载,采用导入镜像方式,镜像可从我百度网盘下载:
通过网盘分享的文件:mysql-5.7.32.tar
链接:
https://pan.baidu.com/s/1a2EyfNbGzT4yEhs323qDkg 提取码: zbit
下载下来镜像后用下面命令导入。
docker load < D:\soft\java\docker\images\mysql-5.7.32.tar
或
docker load -i D:\soft\java\docker\images\mysql-5.7.32.tar
截屏如下
查看本地docker镜像
docker images
-----------
2、创建mysql容器并运行
先创建 D:\data\dockerData\mysql5.7.32\conf文件夹、 D:\data\dockerData\mysql5.7.32\log和 D:\data\dockerData\mysql5.7.32\data 文件夹,D:\data\dockerData\mysql5.7.32\conf下面创建my.cnf配置文件。
说明:
mysql5.7.32默认没有创建my.cnf配置文件,如果需要可手动添加,放到 /mysql5.7.32/conf 下面。
配置文件如下:
# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
#
# 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
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
root@689036e28de4:/etc/mysql# pwd
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#日志文件,如果没有需要手动创建,并赋予相应写权限,否则会导致mysql启动失败。
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
lower_case_table_names=1
max_connections = 2000
max_allowed_packet=500M
# 设置时区为当前时间
default-time_zone = '+8:00'
给文件夹赋予权限
本次我给所有用户赋予了写权限
#(注意一定要设置时区) default-time_zone = '+8:00'
再运行如下命令。
docker run -d -p 13306:3306 --name mysql --restart=always --privileged=true -v /d/data/dockerData/mysql5.7.32/conf:/etc/mysql -v /d/data/dockerData/mysql5.7.32/data:/var/lib/mysql -v /d/data/dockerData/mysql5.7.32/log:/var/log -e MYSQL_ROOT_PASSWORD=MyStrogePwd@0418 mysql:5.7.32
说明:
--privileged=true 设置权限,否则容器启动不起来
在 Windows 系统中,路径通常以盘符开头(如 D:/),而在 Linux 系统中,路径以 / 开头。Docker 容器基于 Linux 环境运行,因此挂载路径需要符合 Linux 的路径格式。
例如:windows中路径是:D:\data\dockerData,则需要写成:/d/data/dockerData
执行结果截屏如下:
++++++以下是确认 my.cnf data log等目录路径++++++++++++++++++++++++++++++++++++
进入Docker容器内
docker exec -it mysql bash
确定Docker内 MySQL 文件相关路径
查找my.cnf
1、Linux下MySQL的配置文件是my.cnf,一般会放在/etc/my.cnf,/etc/mysql/my.cnf。如果找不到,可以用find命令查找。
2、mysql help命令
# Docker内,MySQL配置文件my.cnf的位置
mysql --help | grep my.cnf
# 显示如下,意思是路径按优先排序,会是在以下路径里:
order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
# 配置文件的路径不一定都一样,有些文章介绍的位置是在/etc/my.cnf。而我的docker虚拟机系统上,实际存在位置是在/etc/mysql/my.cnf
3、docker登录到mysql
docker exec-it mysql bash
4、相关命令
停止正在运行中的容器
docker stop 容器的id(或names)
启动容器
docker start 容器id(或names)
二、创建数据库实例和用户
1、创建数据库实例
使用 sqlyol的UI界面创建一个数据库,命名为wsclc,指定其默认字符集为 utf8,默认排序规则为 utf8_general_ci(简体中文,不区分大小写),输入的 SQL 语句与执行结果如下所示:
CREATE DATABASE IF NOT EXISTS wsclc DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;
2、执行sql语句创建相关表。
截屏如下:
- 上一篇: 常见文件系统格式有哪些
- 下一篇: JAVA语言基础
猜你喜欢
- 2025-08-02 WAF-Bypass之SQL注入绕过思路总结
- 2025-08-02 深夜整理!55道BAT高频MySQL灵魂拷问,背完跳槽涨薪不再是梦想!
- 2025-08-02 手把手教你在嵌入式设备中使用SQLite3
- 2025-08-02 MySQL 高级(进阶)SQL 语句
- 2025-08-02 互联网微服务:使用Flyway版本化管理数据库脚本
- 2025-08-02 Linux下,VirtualBox虚拟机常用操作命令
- 2025-08-02 MySQL 教程的天花板--入门到高级
- 2025-08-02 了解 SQL 语言特点、分类及规则
- 2025-08-02 Redis中9种基本数据类型及常用操作命令和应用场景
- 2025-08-02 01.Java发展历史
你 发表评论:
欢迎- 644℃几个Oracle空值处理函数 oracle处理null值的函数
- 634℃Oracle分析函数之Lag和Lead()使用
- 628℃0497-如何将Kerberos的CDH6.1从Oracle JDK 1.8迁移至OpenJDK 1.8
- 625℃Oracle数据库的单、多行函数 oracle执行多个sql语句
- 620℃Oracle 12c PDB迁移(一) oracle迁移到oceanbase
- 608℃【数据统计分析】详解Oracle分组函数之CUBE
- 599℃最佳实践 | 提效 47 倍,制造业生产 Oracle 迁移替换
- 584℃Oracle有哪些常见的函数? oracle中常用的函数
- 最近发表
- 标签列表
-
- 前端设计模式 (75)
- 前端性能优化 (51)
- 前端模板 (66)
- 前端跨域 (52)
- 前端缓存 (63)
- 前端aes加密 (58)
- 前端脚手架 (56)
- 前端md5加密 (54)
- 前端路由 (61)
- 前端数组 (73)
- 前端js面试题 (50)
- 前端定时器 (59)
- 前端获取当前时间 (50)
- Oracle RAC (76)
- oracle恢复 (77)
- oracle 删除表 (52)
- oracle 用户名 (80)
- oracle 工具 (55)
- oracle 内存 (55)
- oracle 导出表 (62)
- oracle约束 (54)
- oracle 中文 (51)
- oracle链接 (54)
- oracle的函数 (58)
- 前端调试 (52)
本文暂时没有评论,来添加一个吧(●'◡'●)