Recently, i was trying to make a slave working by dumping via ssh the databases.
I had discart percona-xtrabackup because i liked to select which databases i'de like to sync.
For make the slave work, i used the next script, which connect to the master, makes the dump of the select database and restore it:
#!/bin/bash
sql_error_check()
{
if [ $? -ne 0 ]; then
echo "ERROR at mysql command!"
exit 1
fi
}
DBS=( db1 db2 db3 db4 db5... )
PASSW="SuperSecurePass"
for i in ${DBS[*]}
do
echo "- Deleting ${i}"
mysql -p${PASSW} -e "drop database IF EXISTS ${i}"
sql_error_check
echo "- Creating ${i}"
mysql -p${PASSW} -e "create database ${i}"
sql_error_check
echo "- Dumping & restoring ${i}"
ssh -C [email protected] "mysqldump -p${PASSW} -q --max_allowed_packet=1024M ${i}" | pv | mysql -p${PASSW} ${i}
sql_error_check
done
Every thing seems to work perfect, but in some queries (huge alter tables) i get the error:
mysqldump: Error 2013: Lost connection to MySQL server during query when dumping table