156156
157157master_status=/tmp/mstatus$$
158158
159- $master_use_script -e 'show master status\G' > $master_status
159+ # MySQL 8.2+ renamed SHOW MASTER STATUS to SHOW BINARY LOG STATUS
160+ show_master_status_cmd="show master status"
161+ minimum_version_binary_log="008002000"
162+ if [[ "v$master_sortable_version" > "v$minimum_version_binary_log" ]]
163+ then
164+ show_master_status_cmd="show binary log status"
165+ fi
166+
167+ $master_use_script -e "$show_master_status_cmd\G" > $master_status
160168binlog_file=$(grep File < $master_status | awk '{print $2}')
161169binlog_pos=$(grep Position < $master_status | awk '{print $2}')
162170rm -f $master_status
@@ -210,21 +218,37 @@ then
210218 exit 1
211219fi
212220
221+ # MySQL 8.0.23+ renamed CHANGE MASTER TO parameters
222+ minimum_version_change_source="008000023"
223+ change_master_cmd="CHANGE MASTER TO"
224+ auto_position_param="master_auto_position"
225+ log_file_param="master_log_file"
226+ log_pos_param="master_log_pos"
227+ public_key_param="GET_MASTER_PUBLIC_KEY"
228+ if [[ "v$slave_sortable_version" > "v$minimum_version_change_source" ]]
229+ then
230+ change_master_cmd="CHANGE REPLICATION SOURCE TO"
231+ auto_position_param="source_auto_position"
232+ log_file_param="source_log_file"
233+ log_pos_param="source_log_pos"
234+ public_key_param="GET_SOURCE_PUBLIC_KEY"
235+ fi
236+
213237if [ -n "$using_gtid" ]
214238then
215- connection_string=$(cat $master_connection ; echo -n ", master_auto_position =1")
216- else
217- connection_string=$(cat $master_connection ; echo -n ', master_log_file="' $binlog_file' ", master_log_pos=' $binlog_pos )
239+ connection_string=$(cat $master_connection ; echo -n ", $auto_position_param =1")
240+ else
241+ connection_string=$(cat $master_connection ; echo -n ", $log_file_param=\" $binlog_file\ ", $log_pos_param= $binlog_pos" )
218242 if [ -f clone_replication.sql ]
219243 then
220244 connection_string=$(cat $master_connection ; echo -n ", " ; cat clone_replication.sql)
221245 fi
222246fi
223247
224- # If master is 8.0, the slave must be at least 8.0
225- if [ "$master_short_version" == "8.0" ]
248+ # If master is 8.0+, need public key for caching_sha2_password
249+ if [[ $master_major -ge 8 ] ]
226250then
227- connection_string="$connection_string, GET_MASTER_PUBLIC_KEY =1"
251+ connection_string="$connection_string, $public_key_param =1"
228252fi
229253
230254echo "Connecting to $master_path"
@@ -236,12 +260,23 @@ if [ -f clone_replication.sql ]
236260then
237261 rm -f clone_replication.sql
238262fi
239- $SBDIR/use -v -e 'start slave'
240- $SBDIR/use -v -e 'SHOW SLAVE STATUS\G' | grep "\(Running:\|Master_Log_Pos\|\<Master_Log_File\|Retrieved\|Executed\|Auto_Position\)"
263+ # MySQL 8.0.22+ renamed START/STOP/SHOW SLAVE to REPLICA
264+ start_replica_cmd="start slave"
265+ show_replica_cmd="SHOW SLAVE STATUS"
266+ stop_reset_cmd="stop slave; reset slave"
267+ minimum_version_replica="008000022"
268+ if [[ "v$slave_sortable_version" > "v$minimum_version_replica" ]]
269+ then
270+ start_replica_cmd="start replica"
271+ show_replica_cmd="SHOW REPLICA STATUS"
272+ stop_reset_cmd="stop replica; reset replica"
273+ fi
274+ $SBDIR/use -v -e "$start_replica_cmd"
275+ $SBDIR/use -v -e "$show_replica_cmd\G" | grep "\(Running:\|Master_Log_Pos\|Source_Log_Pos\|\<Master_Log_File\|\<Source_Log_File\|Retrieved\|Executed\|Auto_Position\)"
241276date > $active_replication
242277echo "Connected to $master_path" >> $active_replication
243278echo "#!{{.ShellPath}}" > $remove_replication
244- echo "$SBDIR/use -v -e 'stop slave; reset slave '" >> $remove_replication
279+ echo "$SBDIR/use -v -e '$stop_reset_cmd '" >> $remove_replication
245280echo "rm -f $active_replication" >> $remove_replication
246281chmod +x $remove_replication
247282
0 commit comments