If your slave does not also act as a master to another slave, then you should not have any issues from deleting binary logs. The relay logs are important to the slave.
You need to further investigate on why mysql schema disappeared. Is mysql schema still present on the disk, even though MySQL is not showing it? If you have not stopped the slave instance yet, then you could run under same user as MySQL is running:
lsof | grep '/path_to_mysql'
You might see mysql schema tables marked as deleted in there:
(deleted)
Another possibility is that you are connecting with a user that has limited privileges and just does not see mysql schema. Run SHOW GRANTS;
to see what privileges you currently have.
As Rolando pointed out, use PURGE BINARY LOGS as best practice for cleaning up binary logs. If MySQL is down, you could delete the files manually, but then you have to also delete the same file names from the index file. Be careful on master servers, as binary logs might still be needed by slaves.
And if you do need to copy mysql schema, you can do it with just these steps on the slave. Although, I would recommend executing FLUSH TABLES;
on master before doing these steps.
/etc/init.d/mysql stop
scp -rp master_server:/var/lib/mysql/mysql /var/lib/mysql/
/etc/init.d/mysql start
The warning about --log-slave-updates
will only apply if you had multiple intermediary 'Master/Slave' servers.
The warning is this (my emphasis):
Then it will write updates that it receives from Master to its own binary log. When Slave 2 changes from Master to Slave 1 as its master, it may receive updates from Slave 1 that it has already received from Master
But in your scenario, Slave 2
is not changing masters, it will still point to the same Master 2
server it always was at.
So now, in case of Master 1
failing, you will need to do two things:
- Make sure your applications point to
Master 2
- Follow the instructions on promoting one of the three slaves to be new
Master 2
- make sure to enable
--log-slave-updates
on the new Master 2
Best Answer
The easiest method is the following
SHOW SLAVE STATUS\G
Relay_Master_Log_File
on Each SlaveRelay_Master_Log_File
is the one you purge to on the MasterWhy
Relay_Master_Log_File
? First Look atSHOW SLAVE STATUS\G
You see
Master_Log_File
andRelay_Master_Log_File
In this display they are different. So why choose
Relay_Master_Log_File
?Master_Log_File
represents the binlog with the last binlog event downloaded to the SlaveRelay_Master_Log_File
represents the binlog with the last binlog event executed on the SlaveIn the event of any replication lag,
Relay_Master_Log_File
is always the oldest. If they are the same, fine. You chooseRelay_Master_Log_File
always.In this case, you purge to
mysql-bin.000254
on the Master. In the event the SQL thread dies, you don't want to erase binlogs from the Master the Slave has not processed yet.Getting back to multiple slaves, you choose the oldest
Relay_Master_Log_File
of all Slaves.To clarify, the oldest
Relay_Master_Log_File
is the binary log name with the lowest number.