Skip to content
This repository has been archived by the owner on Nov 29, 2020. It is now read-only.

#52 - binlog position #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion 5.5/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
VOLUME_HOME="/var/lib/mysql"
CONF_FILE="/etc/mysql/conf.d/my.cnf"
LOG="/var/log/mysql/error.log"
REPLICATION_SLAVE_OPTS=${REPLICATION_SLAVE_OPTS:-''};

# Set permission of config file
chmod 644 ${CONF_FILE}
Expand Down Expand Up @@ -134,7 +135,16 @@ if [ -n "${REPLICATION_SLAVE}" ]; then
echo "=> Starting MySQL ..."
StartMySQL
echo "=> Setting master connection info on slave"
mysql -uroot -e "CHANGE MASTER TO MASTER_HOST='${MYSQL_PORT_3306_TCP_ADDR}',MASTER_USER='${MYSQL_ENV_REPLICATION_USER}',MASTER_PASSWORD='${MYSQL_ENV_REPLICATION_PASS}',MASTER_PORT=${MYSQL_PORT_3306_TCP_PORT}, MASTER_CONNECT_RETRY=30"
if [ -n "${REPLICATION_SLAVE_CURRENT}" ] ; then
mysql -h"${MYSQL_PORT_3306_TCP_ADDR}" -u"${MYSQL_ENV_REPLICATION_USER}" -p"${MYSQL_ENV_REPLICATION_PASS}" -e 'SHOW MASTER STATUS\G' > /tmp/mysql.master.info && {
cat /tmp/mysql.master.info
FILE=$(awk -F': ' '/File/ {print $2}' /tmp/mysql.master.info);
POSITION=$(awk -F': ' '/Position/ {print $2}' /tmp/mysql.master.info);
REPLICATION_SLAVE_OPTS="${REPLICATION_SLAVE_OPTS}, MASTER_LOG_FILE='${FILE}', MASTER_LOG_POS=${POSITION}"
echo "Replication binlog position set to '${FILE}' '${POSITION}'"
} || echo "FAILED to connect to master database @${MYSQL_PORT_3306_TCP_ADDR}";
fi
mysql -uroot -e "CHANGE MASTER TO MASTER_HOST='${MYSQL_PORT_3306_TCP_ADDR}',MASTER_USER='${MYSQL_ENV_REPLICATION_USER}',MASTER_PASSWORD='${MYSQL_ENV_REPLICATION_PASS}',MASTER_PORT=${MYSQL_PORT_3306_TCP_PORT} ${REPLICATION_SLAVE_OPTS}, MASTER_CONNECT_RETRY=30"
echo "=> Done!"
mysqladmin -uroot shutdown
touch /replication_configured
Expand Down
12 changes: 11 additions & 1 deletion 5.6/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
VOLUME_HOME="/var/lib/mysql"
CONF_FILE="/etc/mysql/conf.d/my.cnf"
LOG="/var/log/mysql/error.log"
REPLICATION_SLAVE_OPTS=${REPLICATION_SLAVE_OPTS:-''};

# Set permission of config file
chmod 644 ${CONF_FILE}
Expand Down Expand Up @@ -134,7 +135,16 @@ if [ -n "${REPLICATION_SLAVE}" ]; then
echo "=> Starting MySQL ..."
StartMySQL
echo "=> Setting master connection info on slave"
mysql -uroot -e "CHANGE MASTER TO MASTER_HOST='${MYSQL_PORT_3306_TCP_ADDR}',MASTER_USER='${MYSQL_ENV_REPLICATION_USER}',MASTER_PASSWORD='${MYSQL_ENV_REPLICATION_PASS}',MASTER_PORT=${MYSQL_PORT_3306_TCP_PORT}, MASTER_CONNECT_RETRY=30"
if [ -n "${REPLICATION_SLAVE_CURRENT}" ] ; then
mysql -h"${MYSQL_PORT_3306_TCP_ADDR}" -u"${MYSQL_ENV_REPLICATION_USER}" -p"${MYSQL_ENV_REPLICATION_PASS}" -e 'SHOW MASTER STATUS\G' > /tmp/mysql.master.info && {
cat /tmp/mysql.master.info
FILE=$(awk -F': ' '/File/ {print $2}' /tmp/mysql.master.info);
POSITION=$(awk -F': ' '/Position/ {print $2}' /tmp/mysql.master.info);
REPLICATION_SLAVE_OPTS="${REPLICATION_SLAVE_OPTS}, MASTER_LOG_FILE='${FILE}', MASTER_LOG_POS=${POSITION}"
echo "Replication binlog position set to '${FILE}' '${POSITION}'"
} || echo "FAILED to connect to master database @${MYSQL_PORT_3306_TCP_ADDR}";
fi
mysql -uroot -e "CHANGE MASTER TO MASTER_HOST='${MYSQL_PORT_3306_TCP_ADDR}',MASTER_USER='${MYSQL_ENV_REPLICATION_USER}',MASTER_PASSWORD='${MYSQL_ENV_REPLICATION_PASS}',MASTER_PORT=${MYSQL_PORT_3306_TCP_PORT} ${REPLICATION_SLAVE_OPTS}, MASTER_CONNECT_RETRY=30"
echo "=> Done!"
mysqladmin -uroot shutdown
touch /replication_configured
Expand Down