1. Home
  2. High Availability
  3. How do I clone additional MySQL databases in Bright Cluster?

How do I clone additional MySQL databases in Bright Cluster?

The following steps show an example method that has been verfied on Bright 7.3 and 8.0

1. Copy /cm/local/apps/cluster-tools/ha/conf/extradbclone.xml.template to /cm/local/apps/cluster-tools/ha/conf/extradbclone.xml

2. Add the following section to /cm/local/apps/cmd/scripts/cm-update-mycnf on both head nodes (after making a backup of the original file):

###################### 
extradbclone=/cm/local/apps/cluster-tools/ha/conf/extradbclone.xml 
# additional dbs for replication 
if [[ -e "$extradbclone" ]];then 
  xmlgood=0 
  if [[ -x $xmllint ]];then 
    $xmllint $extradbclone 1>/dev/null 2>&1 
    xmlgood=$? 
  fi 
  if [[ $xmlgood -eq 0 ]];then 
    OLDIFS=$IFS 
    IFS=$'\n' 
    extradbs=($(sed -e 's/<!--.*-->//g' -e '/<!--/,/-->/{//!d}' $extradbclone | awk '/<db name=/')) 
    IFS=$OLDIFS 
    for db in "${extradbs[@]}"; do 
      dbname=$(echo $db |cut -d' ' -f2 | sed 's/name=//' | sed 's/"//g') 
      if [[ ! $content =~ "replicate-do-db=$dbname" ]]; then 
        perl -pi.bak -e 's/(log-bin=mysql-bin)/$1\nreplicate-do-db='$dbname'/' $mycnf; 
      fi 
      if [[ ! $content =~ "binlog-do-db=$dbname" ]]; then 
        perl -pi.bak -e 's/(log-bin=mysql-bin)/$1\nbinlog-do-db='$dbname'/' $mycnf; 
      fi 
    done 
  fi 
###################### 



3. Add the additional databases in /cm/local/apps/cluster-tools/ha/conf/extradbclone.xml

Here, mydb1, mydb2, and the values for username and userpass are used as examples. Modify the XML file as appropriate for your own needs.
<dbclone> 
<db name="mydb1" username="root" userpass="system" /> 
<db name="mydb2" username="root" userpass="system" /> 
<!-- 
<db name="mydb" username="root" userpass="system" servicesactive="s1,s4" servicespassive="s2" services="cmd"/> 
--> 
</dbclone> 

4. Run the “/cm/local/apps/cmd/scripts/cm-update-mycnf” script on both head nodes 
/cm/local/apps/cmd/scripts/cm-update-mycnf 

5. Create the database directories on the secondary head nodes: 
# mkdir /var/lib/mysql/mydb1 
# mkdir /var/lib/mysql/mydb2 
# chown -R mysql:mysql /var/lib/mysql/mydb1 
# chown -R mysql:mysql /var/lib/mysql/mydb2 

6. Restart MySQL service on both head nodes: 
# service mysqld restart 

7. Run cmha dbreclone <passive> to clone the additional databases. This step may not be required in some cases.
# cmha dbreclone <passive>

Updated on October 27, 2020

Was this article helpful?

Related Articles

Leave a Comment