1:先下载MySQL镜像
# docker pull mysql:5.7
2:运行镜像生成容器
# docker run --name mysql -p 3306:3306 -e MYSQL\_ROOT\_PASSWORD=123456 -d mysql:5.7
3:查看生成最新的容器
# docker ps -l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
64f075017f93 mysql:5.7 "docker-entrypoint..." 17 minutes ago Exited (1) 16 minutes ago mysql
4:进入容器查看是否安装成功
# docker exec -it mysql bash
root@64f075017f93:/# mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3
Server version: 5.7.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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 [(none)]>
5:宿主机登录测试MySQL
# mysql -uroot -p123456 -h192.168.1.20
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MySQL connection id is 4
Server version: 5.7.22-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MySQL [(none)]>
6:修改my.cnf配置文件
my.cnf配置文件
# cat > /etc/mysql/my.cnf <
[client]
port= 3306socket= /var/run/mysqld/mysqld.sock
[mysqld]
port= 3306socket= /var/run/mysqld/mysqld.sock
back_log= 80basedir= /usr
tmpdir= /tmp
datadir= /var/lib/mysql
#-------------------gobal variables------------#
slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=16slave_preserve_commit_order=on
gtid_mode=ON
relay_log_info_repository=TABLE
master_info_repository=TABLE
relay_log_recovery=on
enforce_gtid_consistency=ON
binlog_checksum=NONE
log_slave_updates=ON
log-bin = /var/lib/mysql/mysql-bin
max_connect_errors= 20000max_connections= 2000wait_timeout= 3600interactive_timeout= 3600net_read_timeout= 3600net_write_timeout= 3600table_open_cache= 1024table_definition_cache= 1024thread_cache_size= 512open_files_limit= 10000character-set-server =utf8
collation-server =utf8_bin
skip_external_locking
performance_schema= 1user=mysql
myisam_recover_options=DEFAULT
skip-name-resolve
local_infile= 0lower_case_table_names= 0#--------------------innoDB------------#
innodb_buffer_pool_size=2000M
innodb_data_file_path=ibdata1:200M:autoextend
innodb_flush_log_at_trx_commit= 1innodb_io_capacity= 600innodb_lock_wait_timeout= 120innodb_log_buffer_size=8M
innodb_log_file_size=200M
innodb_log_files_in_group= 3innodb_max_dirty_pages_pct= 85innodb_read_io_threads= 8innodb_write_io_threads= 8innodb_support_xa= 1innodb_thread_concurrency= 32innodb_file_per_table
innodb_rollback_on_timeout
#------------session variables-------#
join_buffer_size=8M
key_buffer_size=256M
bulk_insert_buffer_size=8M
max_heap_table_size=96M
tmp_table_size=96M
read_buffer_size=8M
sort_buffer_size=2M
max_allowed_packet=64M
read_rnd_buffer_size=32M
#------------MySQL Log----------------#
log-bin = my3306-bin
binlog_format=row
sync_binlog= 1expire_logs_days= 15max_binlog_cache_size=128M
max_binlog_size=500M
binlog_cache_size=64k
slow_query_log
log-slow-admin-statements
log_warnings= 1long_query_time= 0.25#---------------replicate--------------#
relay-log-index =relay3306.index
relay-log =relay3306
server-id =88init_slave= 'set sql_mode=STRICT_ALL_TABLES'log-slave-updates
[myisamchk]
key_buffer=512M
sort_buffer_size=512M
read_buffer=8M
write_buffer=8M
[mysql]
prompt=MySQL [\d]>default-character-set=utf8
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192log-error = /var/lib/mysql/mysqld_error.log
END
View Code
7:生成新的镜像
# docker commit 64f075017f93 mysql:5.7.22
8:查看镜像
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mysql 5.7.22 1bc73a7082d4 20 minutes ago 372MB
mysql 5.7 66bc0f66b7af 2 weeks ago 372MB
9:测试新的镜像是否生效
# docker run --name mysql_test -p 3306:3306 -e MYSQL\_ROOT\_PASSWORD=123456 -d mysql:5.7.22
# docker exec -it mysql_test bash
查看/etc/mysql/my.cnf配置文件
宿主机登陆测试MySQL数据库
# mysql -uroot -p123456 -h192.168.1.20