I have a MySQL database with a large number of individual tables having the same definitions. The number of tables is about 2000-3000 and their total size is about 50 GB. Of course they have different content. I want to put them in one common table and get rid of them. To do that I will use the script like this (some variables are redacted!)
#!/bin/bash
pattern='individual_table_(.+)'
sudo mysql -ss --execute "SHOW TABLES;" -A database_name | while read -r line
do
if [[ $line =~ $pattern ]];
then echo "Inserting $line for object with id ${BASH_REMATCH[1]}";
sudo mysql -e "insert into common_table (timestamp, objectID, data) select timestamp, objectID, data from $line;" -A database_name
fi
done
echo "Script finished!"
So far so good. The database uses a master-slave strategy. I'll apply that script to the master. Once I start the script it will operates continuously several hours while serving another querries. Normaly the bin log gets updated and it's data grows. The log must be deleted from time to time otherwise the host's machine storage would get overfilled. In other words it acts as a "last in - first out" buffer. You can configure in what conditions MySQL to clear the old data. It's an excerpt from the master's my.cnf
file.
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 30
max_binlog_size = 4000M
So my question is at some point in time after I've started the script, could it happen that the oldest log bin data gets deleted before the slave has read it? Could it lead to a data and synchronization loss between master and slave and how to avoid it? I could put a sleep
line between each insert
in my script but that will make its executions slower. Is there any other solution?