Hello here,
I have 2 individual servers, Both have docker service on it & MySQL instance are hosted on that servers. On one server A on it’s docker server MySQL primary is hosted, On server B on it’s docker server MySQL Secondary is hosted.
Now I want to test the pt-table-checksum utility, the port for MySQL is used is 24306 on both servers. here is the code I have used it but it throws connectivity error :
#!/bin/bash
PRIMARY_HOST_IP="servera"
SECONDARY_HOST_IP="serverb"
USER="root"
PASSWORD="XXXXX"
PORT="24306"
# Run pt-table-checksum
pt-table-checksum h=$PRIMARY_HOST_IP,u=$USER,p=$PASSWORD,P=$PORT --no-check-binlog-format \
--databases=$(mysql -h $PRIMARY_HOST_IP -u$USER -p$PASSWORD -P=$PORT\
-NBe "SELECT GROUP_CONCAT(schema_name SEPARATOR ' ') FROM information_schema.schemata \
WHERE schema_name NOT IN ('mysql','information_schema','performance_schema','sys');")
# Assuming pt-table-checksum has been configured previously to store results in a percona database
UNSYNCED_TABLES=$(mysql -h $SECONDARY_HOST_IP -u$USER -p$PASSWORD -P=$PORT -NBe \
"SELECT COUNT(*) FROM percona.checksums WHERE (this_crc <> master_crc OR this_cnt <> master_cnt) AND db NOT IN ('mysql','information_schema','performance_schema','sys');")
# Send an alert if there are unsynchronized tables
if [[ $UNSYNCED_TABLES -gt 0 ]]; then
echo "There are $UNSYNCED_TABLES unsynchronized tables on the secondary server" \
| mail -s "Database Synchronization Alert" your-email@example.com
fi
Error :
Checking if all tables can be checksummed ...
Starting checksum ...
Cannot connect to P=3306,h=ServerB,p=...,u=root: DBI connect(';host=ServerB;port=3306;mysql_read_default_group=client','root',...) failed: Can't connect to MySQL server on 'ServerB:3306' (110) at /usr/bin/pt-table-checksum line 1639.
Can't call method "selectrow_array" on an undefined value at /usr/bin/pt-table-checksum line 5346.
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [ERROR] Unknown suffix '=' used for variable 'port' (value '=24306').
mysql: [ERROR] mysql: Error while setting value '=24306' to 'port'.
mysql_replication_sync_check.sh: 23: -NBe: not found
mysql_replication_sync_check.sh: 25: --databases=: not found
mysql: [Warning] Using a password on the command line interface can be insecure.
mysql: [ERROR] Unknown suffix '=' used for variable 'port' (value '=24306').
mysql: [ERROR] mysql: Error while setting value '=24306' to 'port'.
mysql_replication_sync_check.sh: 33: SELECT COUNT(*) FROM percona.checksums WHERE (this_crc <> master_crc OR this_cnt <> master_cnt) AND db NOT IN ('mysql','information_schema','performance_schema','sys');: not found
mysql_replication_sync_check.sh: 43: Syntax error: "|" unexpected