all-in-one配置
系统环境
Ubuntu 20.04.3 LTS
机器环境规划
MySQL-Master-5.7 10.2.0.47
安装并启动docker:
apt install docker.io -y && systemctl start docker
创建build目录和数据目录
mkdir -p mysql-5.7.43/mysql/conf && mkdir -p /apps/mysql/
创建my.cnf文件
cat >> mysql/conf/my.cnf <<EOF
[mysqld]
server-id=1
binlog-ignore-db=mysql
innodb_buffer_pool_size = 64M
innodb_log_file_size = 2G
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
character-set-server = utf8
collation-server = utf8_bin
default-storage-engine = INNODB
innodb_data_file_path = ibdata1:10M:autoextend
binlog_format = mixed
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 32M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 512K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
wait_timeout = 60
interactive_timeout = 10
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysql.sock
secure-file-priv=/var/lib/mysql-files
user=mysql
symbolic-links=0
pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/var/run/mysqld/mysql.sock
no-auto-rehash
default-character-set = utf8
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
EOF
创建docker-compose.yml文件
version: '3'
services:
mysql:
container_name: mysql
image: mysql:5.7
restart: always
volumes:
- /apps/mysql/log:/var/log/mysql
- ./mysql/conf/my.cnf:/etc/mysql/my.cnf
- /apps/mysql/data:/var/lib/mysql
ports:
- '3306:3306'
command: [
'--explicit_defaults_for_timestamp=true',
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_general_ci',
'--max_connections=3000'
]
environment:
MYSQL_ROOT_PASSWORD: "PASSWD"
构建MySQL
docker-compose up -d
验证是否创建成功
1. 查看容器
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
be817f461f8d mysql:5.7 "docker-entrypoint.s…" 53 minutes ago Up 52 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql-slave
2. 进入容器
docker exec -it mysql /bin/bash
3. 登录MySQL
mysql -uroot -pSeca@2024...
4. 查看数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
仅登录用户可评论,点击 登录