Leif の 坊

己亥中原兴似火,九月金陵凉至秋。
琴声已散弦犹振,雁飞九天声已留。

目录
如何修改docker容器中mysql的端口号
/  

如何修改docker容器中mysql的端口号

修改docker中mysql配置文件,在mysqld项目下新增port=3307配置

[mysqld]
port=3307
federated
max_connections = 200
max_allowed_packet = 64M
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
#限制mysql内存占用
#performance_schema_max_table_instances=400
#table_definition_cache=400
#table_open_cache=256

character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8

[mysql.server]
default-character-set=utf8

[mysqld_safe]
default-character-set=utf8

之后执行mysql.sh脚本

#!/usr/bin/env bash
config_dir=`pwd`
PASSWORD=123456
docker run -d --net host --name solo_mysql\
     -p 3307:3307 \
     -e MYSQL_ROOT_PASSWORD=$PASSWORD \
     -e TZ=Asia/Shanghai \
     --restart=always \
     -v ${config_dir}/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf \
     mysql:5.7
exit

若容器已经生成,则先停止宿主机mysql服务,之后启动容器,通过docker exec命令进入容器中,修改/etc/mysql/mysql.conf.d/mysqld.cnf配置文件即可


“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” – Tom Cargill

标  题如何修改docker容器中mysql的端口号
作  者Leif160519
出  处https://leif.fun/articles/2019/12/02/1575269749864.html
关于博主:坐标金陵古城,运维工程师,如有问题探讨可以直接下方留言。
声援博主:如果您觉得文章对您有帮助,可以评论、订阅、收藏。您的鼓励是博主的最大动力!

评论