3分鐘部署mysql並開啟binlog

赚窝囊费的小苏發表於2024-04-29

curl -fsSL https://get.docker.com | bash

yum -y install docker-ce
sudo systemctl start docker
sudo systemctl enable docker

mysql快速安裝

sudo docker pull mysql
mkdir -p /opt/module/mysql/conf /opt/module/mysql/data /opt/module/mysql/conf/config.d/
touch /opt/module/mysql/conf/my.cnf
vi /opt/module/mysql/conf/my.cnf
[client]
default-character-set = utf8mb3

[mysqld]
datadir = /opt/module/mysql/data
character_set_server = utf8mb3
collation_server = utf8mb3_general_ci
secure-file-priv =
symbolic-links = 0
server-id = 1 # 配置 MySQL replication 需要定義,不要和 Canal 的 slaveId 重複
log-bin = mysql-bin # 開啟 binlog
binlog-format = ROW # 選擇 ROW 模式
binlog-do-db = dwshow # dwshow是資料庫的名稱

docker run --restart=unless-stopped -d --name mysql -v /opt/module/mysql/conf/my.cnf:/etc/mysql/my.cnf -v /opt/module/mysql/data:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root mysql
cd /opt/module/mysql/data
如果沒有日誌檔案,給my.cnf加滿許可權即可

相關文章