拉取镜像
docker pull registry.cn-hangzhou.aliyuncs.com/qiluo-images/mysql:5.7.44
创建目录
mkdir -p /data/mysql/conf
mkdir -p /data/mysql/data
运行容器
docker run -d \
--name mysql-container \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=mypassword \
-v /data/mysql/conf/my.cnf:/etc/my.cnf \
-v /data/mysql/data:/var/lib/mysql \
--privileged=true \
--restart=always \
registry.cn-hangzhou.aliyuncs.com/qiluo-images/mysql:5.7.44
查看容器状态:
docker ps
创建my.cnf
如下
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
[mysqld_safe]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
skip-host-cache
skip-name-resolve
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
explicit_defaults_for_timestamp = true
symbolic-links = 0
!includedir /etc/mysql/conf.d/
# Custom settings
lower_case_table_names = 1
wait_timeout = 2147483
interactive_timeout = 2147483
max_connections = 20000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 512
max_allowed_packet = 500M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 64M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 512M
thread_cache_size = 32
query_cache_size = 128M
default-storage-engine = INNODB
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 4G
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 1G
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 32M
myisam_max_sort_file_size = 10G
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION