Linux中docker安装mysql

准备工作

# 打开目录

[root@Yi~]# cd /usr/local/docker/

# 创建文件夹

[root@Yi docker]# mkdir mysql

# 打开文件夹

[root@Yi docker]# cd mysql/

创建挂载目录

# 创建配置文件目录

[root@Yi mysql]# mkdir config

# 打开config

[root@Yi mysql]# cd config/

# 编写配置文件

[root@Yi config]# vim my.cnf

配置文件内容

[client]

# 端口号

port=3306

[mysql]

no-beep

default-character-set=utf8mb4

[mysqld]

# 端口号

port=3306

# 数据目录

datadir=/var/lib/mysql

# 新模式或表时将使用的默认字符集

character-set-server=utf8mb4

# 默认存储引擎

default-storage-engine=INNODB

# 将 SQL 模式设置为严格

sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

#  最大连接数

max_connections=1024

# 表缓存

table_open_cache=2000

# 表内存

tmp_table_size=16M

# 线程缓存

thread_cache_size=10

# 设置大小写不敏感

lower_case_table_names=1

# myisam设置

myisam_max_sort_file_size=100G

myisam_sort_buffer_size=8M

key_buffer_size=8M

read_buffer_size=0

read_rnd_buffer_size=0

# innodb设置

innodb_flush_log_at_trx_commit=1

innodb_log_buffer_size=1M

innodb_buffer_pool_size=8M

innodb_log_file_size=48M

innodb_thread_concurrency=33

innodb_autoextend_increment=64

innodb_buffer_pool_instances=8

innodb_concurrency_tickets=5000

innodb_old_blocks_time=1000

innodb_open_files=300

innodb_stats_on_metadata=0

innodb_file_per_table=1

innodb_checksum_algorithm=0

# 其他设置

back_log=80

flush_time=0

join_buffer_size=256K

max_allowed_packet=4M

max_connect_errors=100

open_files_limit=4161

sort_buffer_size=256K

table_definition_cache=1400

binlog_row_event_max_size=8K

sync_master_info=10000

sync_relay_log=10000

sync_relay_log_info=10000

下载镜像

[root@Yi mysql]# docker pull mysql:5.7

编写脚本

# 打开目录

[root@Yi config]# cd /usr/local/docker/mysql/

# 编写脚本

[root@Yi mysql]# vim startMysql.sh

脚本内容

docker run -d \

--privileged=true \

--name mysql57 \

-p 3306:3306 \

--restart=always \

-v /usr/local/docker/mysql/data:/var/lib/mysql \

-v /usr/local/docker/mysql/config/my.cnf:/etc/mysql/my.cnf \

-e MYSQL_ROOT_PASSWORD=root mysql:5.7 \

权限赋予

# 权限赋予

[root@Yi mysql]# chmod -R 777 startMysql.sh

启动脚本

# 执行脚本

[root@Yi mysql]# ./startMysql.sh

查看结果

# 进入容器

[root@Yi mysql]# docker exec -it mysql57-3306 /bin/bash

# 连接MySQL

root@4ff92e46f363:/# mysql -uroot -pDongzl828..

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 2

Server version: 5.7.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, 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.01 sec)

  • 38
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值