Skip to content

Commit

Permalink
master slave db should now function
Browse files Browse the repository at this point in the history
  • Loading branch information
user committed Dec 7, 2023
1 parent 3510840 commit 4ced562
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions mysql/docker-entrypoint-initdb.d/masterslave.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

if [ $MYSQL_ROLE = "master" ]; then

Expand All @@ -7,7 +7,7 @@ if [ $MYSQL_ROLE = "master" ]; then

echo "Creating replication user"
mysql -uroot -p$MYSQL_ROOT_PASSWORD \
--execute="CREATE USER 'replication_user'@'%' IDENTIFIED WITH caching_sha2_password BY 'bigs3cret'; GRANT REPLICATION SLAVE ON *.* TO 'replication_user'@'%'; FLUSH PRIVILEGES;"
--execute="CREATE USER 'replication_user'@'%' IDENTIFIED WITH mysql_native_password BY 'DVvh5lnR1iqok1CV0cAd'; GRANT REPLICATION SLAVE ON *.* TO 'replication_user'@'%'; FLUSH PRIVILEGES;"

echo "Performing temporary backup of all databases"
mysqldump -uroot -p$MYSQL_ROOT_PASSWORD --all-databases --source-data > /tmp/mysql-backup/master_initialization.sql
Expand All @@ -17,14 +17,14 @@ else
echo "MYSQL_ROLE set to slave"
cp /etc/default/template/mysql-conf.d/slave.cnf /etc/mysql/conf.d/

echo "Setting replication host"
mysql -uroot -p$MYSQL_ROOT_PASSWORD \
--execute="CHANGE SOURCE TO \
SOURCE_HOST='ghost-db-master', \
SOURCE_USER='replication_user', \
SOURCE_PASSWORD='bigs3cret';"
--execute="CHANGE REPLICATION SOURCE TO SOURCE_HOST='ghost-db-master', SOURCE_USER='replication_user', SOURCE_PASSWORD='DVvh5lnR1iqok1CV0cAd';"

echo "Importing master database"
mysql -uroot -p$MYSQL_ROOT_PASSWORD < /tmp/mysql-backup/master_initialization.sql

echo "Starting replica"
mysql -uroot -p$MYSQL_ROOT_PASSWORD --execute="START REPLICA;"

fi
Expand Down

0 comments on commit 4ced562

Please sign in to comment.