docker部署mysql5.7

--------------拉取容器------------

docker pull mysql:5.7

--------------创建目录------------

mkdir /data/docker/mysql/conf

mkdir /data/docker/mysql/data

mkdir /data/docker/mysql/logs

--------------修改mysql配置文件,内容在最下面------------

vi /data/docker/mysql/conf/my.cnf

--------------分配权限------------

chmod -R 777 /data/docker/mysql/

--------------创建容器------------

docker run --net=host --name mysql --restart=always \

-v /data/docker/mysql/conf:/etc/mysql \

-v /data/docker/mysql/logs:/var/log/mysql \

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

-e MYSQL_ROOT_PASSWORD=123456 \

-d mysql:5.7

--------------进入容器------------

docker exec -it mysql /bin/bash

--------------进入容器后,并登录mysql------------

mysql -uroot -p123456

grant all privileges on *.* to root@'%' identified by "123456";

create user canal identified by 'canal';

grant select, replication slave, replication client on *.* to 'canal'@'%';

flush privileges;

--------------my.cnf内容------------

[client]

#客户端设置

port    = 3306

socket    = /data/mysql/data/mysql.sock

default-character-set = utf8mb4

[mysqld]

user    = mysql

port    = 3306

socket    = /data/mysql/data/mysql.sock

server-id = 1

pid-file = /data/mysql/data/mysql.pid

#安装目录

basedir    = /usr/local/mysql

#数据库存放目录

datadir    = /var/lib/mysql/

#系统数据库编码设置,排序规则

character_set_server = utf8mb4

collation_server = utf8mb4_bin

back_log = 1024

explicit_defaults_for_timestamp = ON

lower_case_table_names = 0

sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

max_connections = 512

max_connect_errors = 1000000

table_open_cache = 1024

max_allowed_packet = 8M

thread_stack = 256K

thread_cache_size = 384

skip-external-locking

interactive_timeout = 600

wait_timeout = 3600

log_timestamps = SYSTEM

log-error = /data/mysql/logs/error.log

#默认使用InnoDB存储引擎

default_storage_engine = InnoDB

innodb_buffer_pool_size = 64M

innodb_purge_threads = 1

innodb_log_buffer_size = 2M

innodb_log_file_size = 128M

innodb_lock_wait_timeout = 120

bulk_insert_buffer_size = 32M

myisam_sort_buffer_size = 8M

# MySQL重建索引时所允许的最大临时文件的大小

myisam_max_sort_file_size = 10G

myisam_repair_threads = 1

# 开启 binlog

log-bin=mysql-bin

# 选择 ROW 模式

binlog-format=ROW

# 配置 MySQL replaction 需要定义,不要和 canal 的 slaveId 重复

server_id=1

[mysqldump]

quick

max_allowed_packet = 16M

[myisamchk]

key_buffer_size = 8M

sort_buffer_size = 8M

read_buffer = 4M

write_buffer = 4M

你可能感兴趣的:(docker部署mysql5.7)