前言:
目前我们对“mysql镜像网站”可能比较关怀,大家都需要学习一些“mysql镜像网站”的相关文章。那么小编在网摘上网罗了一些关于“mysql镜像网站””的相关内容,希望小伙伴们能喜欢,咱们快快来学习一下吧!#头条创作挑战赛#
单机
5.x
docker pull mysql:5.7.37docker run -d -p 3306:3306 --name mysql-5.7.37 \--privileged=true --restart=always \-v /opt/docker/mysql-5.7.37/log:/var/log/mysql \-v /opt/docker/mysql-5.7.37/data:/var/lib/mysql \-v /opt/docker/mysql-5.7.37/conf:/etc/mysql/conf.d \-e MYSQL_ROOT_PASSWORD=a19861125 mysql:5.7.37#进入容器docker exec -it mysql:5.7.37 bash#登录mysqlmysql -u root -p#/usr/gonice/docker/mysql/conf目录下添加my.cnf(简单配置)[client] default-character-set=utf8[mysqld]character-set-server=utf8 collation-server=utf8_general_ci
8.x
docker pull mysql:8.0.28docker run -d -p 3306:3306 --name mysql-8.0.28 \--privileged=true --restart=always \-v /opt/docker/mysql-8.0.28/log:/var/log/mysql \-v /opt/docker/mysql-8.0.28/data:/var/lib/mysql \-v /opt/docker/mysql-8.0.28/conf:/etc/mysql/conf.d \-e MYSQL_ROOT_PASSWORD=a19861125 mysql:8.0.28集群
1、修改配置文件
注意:宿主机配置文件不能给写权限,否则启动时会改写配置,导致配置无效
[mysqld]skip-name-resolvepid-file = /var/run/mysqld/mysqld.pidsocket = /var/run/mysqld/mysqld.sockdatadir = /var/lib/mysqlsecure-file-priv= NULLlower_case_table_names=1symbolic-links=0# 服务器唯一ID,默认是1server-id=4306# 启用二进制日志log-bin=mysql-bin# Custom config should go here!includedir /etc/mysql/conf.d/
2、启动容器
主库
docker run -d -p 4306:3306 --name mysql-4306 \--privileged=true --restart=always \-v /home/fzp_ms/docker/mysql/4306/data:/var/lib/mysql \-v /home/fzp_ms/docker/mysql/4306/conf/my.cnf:/etc/mysql/my.cnf \-v /home/fzp_ms/docker/mysql/4306/conf.d:/etc/mysql/conf.d \-v /home/fzp_ms/docker/mysql/4306/mysql-files:/var/lib/mysql-files \-v /home/fzp_ms/docker/mysql/4306/logs:/var/log/mysql \-e MYSQL_ROOT_PASSWORD=sundun \-e MYSQL_ROOT_HOST=% \-e TZ=Asia/Shanghai \mysql:8.0.23 \--lower-case-table-names=1
从库
docker run -d -p 4307:3306 --name mysql-4307 \--privileged=true --restart=always \-v /home/fzp_ms/docker/mysql/4307/data:/var/lib/mysql \-v /home/fzp_ms/docker/mysql/4307/conf/my.cnf:/etc/mysql/my.cnf \-v /home/fzp_ms/docker/mysql/4307/conf.d:/etc/mysql/conf.d \-v /home/fzp_ms/docker/mysql/4307/mysql-files:/var/lib/mysql-files \-v /home/fzp_ms/docker/mysql/4307/logs:/var/log/mysql \-e MYSQL_ROOT_PASSWORD=sundun \-e MYSQL_ROOT_HOST=% \-e TZ=Asia/Shanghai \mysql:8.0.23 \--lower-case-table-names=1
3、主库创建复制用户
CREATE USER 'sundun'@'%' IDENTIFIED WITH mysql_native_password BY 'sundun'; GRANT REPLICATION SLAVE ON *.* TO 'sundun'@'%';
4、查看主库状态
mysql> SHOW MASTER STATUS;+------------------+----------+--------------+------------------+-------------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |+------------------+----------+--------------+------------------+-------------------+| mysql-bin.000003 | 663 | | | |+------------------+----------+--------------+------------------+-------------------+1 row in set (0.00 sec)
5、从库配置
change master to master_host='192.168.0.246', master_user='sundun', master_password='sundun', master_port=4306, master_log_file='mysql-bin.000003', master_log_pos=663, master_connect_retry=30; master_port:Master的端口号,指的是容器的端口号master_user:用于数据同步的用户master_password:用于同步的用户的密码master_log_file:指定 Slave 从哪个日志文件开始复制数据,即上文中提到的 File 字段的值master_log_pos:从哪个 Position 开始读,即上文中提到的 Position 字段的值master_connect_retry:如果连接失败,重试的时间间隔,单位是秒,默认是60秒
6、从库开启主从复制
# 开启主从复制start slave;# 查看状态show slave status \G
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #mysql镜像网站 #docker下载mysql镜像不能连接