docker 和 docker-compose 安装
http://xieboke.net/article/341/
创建 mysql主目录
mkdir /usr/local/mysql
cd /usr/local/mysql
创建 mysql 的子目录
mkdir conf data logs
conf 下 my.conf 配置文件
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
skip-grant-tables
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
lower_case_table_names=1
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
init_connect='SET collation_connection = utf8mb4_general_ci'
init_connect='SET NAMES utf8mb4'
character-set-client-handshake=FALSE
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
max_connections = 1000
net_read_timeout=3600
net_write_timeout=3600
创建 docker-compose.yml 文件
version: '3.1'
services:
db:
image: mysql:5.7 #mysql版本
volumes:
- ./data/db:/var/lib/mysql
- ./conf/my.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
restart: always
ports:
- 13306:3306
environment:
MYSQL_ROOT_PASSWORD: 123abc #访问密码
secure_file_priv:
启动容器
cd /usr/local/mysql
docker-compose up -d