Rebuild Slave-DB & Replication

Since the mysqldump command locks the tables, it is not necessary that there is no traffic on the master database. With --master-data the command mysqldump stores the correct position for inserting the replication on the slave server. 

If the hard disk of the slave is full, please refer to the instructions on this page below - "Slave Disk Full".

  1. Login to slave server
  2. Write a MySQL dump. Now perform the following steps on the master server. Create a backup directory and change to the same. The MySQL dumb is now executed with the following command

    Here is a brief explanation of this:

    In versions 3.12, 3.14 and 3.15

    If someone logs on to the portal while the dump is being pulled, it will go wrong. Enclosed a SQL query. If the time changes after executing the query, a login has taken place.

    If this happens, the dump has to be pulled again and in the meantime it has to be permanently checked if a login has taken place. Only if this is not the case, the dump can be replicated error-free to the slave.

    SELECT Max(dtAcdLoggedIn) FROM Users;

    In versions 3.11 and below and version 3.16 this problem does not exist.


  3. Copy MySQL dump from master database server to slave database server
    Use the tool of your choice: command line (scp), WinSCP, ...

  4. We switch back to the slave server and now import the mysqldump.

    • mysql -uUSER -pPWD (we are now in MySql)

    • SET foreign_key_checks = 0;

    • drop database JTELLog;

    • drop database JTELStats;

    • drop database JTELWeb;

    • drop database JTELStats2;

    • SET foreign_key_checks = 1;

    • source <filename>;


  5. We are now determining the replication parameters, as we will need them in a moment:
  6. Now on the slave server there is already a consistent, fairly new state of the data. It is now only necessary to reconfigure the replication. The following commands do this:

    Now we check the slave status (a few times) with the command 

    • SHOW SLAVE STATUS\G


    and expect the following result:
    Now the replication is running again. The name of the logfile and the position should promptly correspond pretty much to the show master status on the master database.

  7. Do not forget to clean up data garbage! I.e. delete mysqldumps and directories at least on the slave. A backup can remain on the master database, provided there is enough space. 

Slave Disk Full

There are several reasons why the slave disk can become full.

tmp directory is full

Background

Every time a query creates a tmp table, it is written to the temp directory, usually /tmp. This happens when the maximum size exceeds the maximum "in memory" table size. This is defined with the variables tmp_table_size aswell as max_heap_table_size .

See also https://dev.mysql.com/doc/refman/5.6/en/internal-temporary-tables.html for more information. 

The tables in /tmp are kept until the respective DB connection is closed or a DROP TEMPORARY TABLE is called. If the /tmp directory is full, it is likely that a DROP TEMPORARY TABLE is missing somewhere. This can also happen through customer queries to the DB.

The installation of tmpwatch creates help in a permanent way

Hints:

Procedure

  1. Space must first be made available. Just mercilessly delete everything from /tmp.
  2. If this provides enough space, then restart the mysql service first: service mysql restart
  3. If there is enough space (at least about 20%), then proceed with replication as described above.

Lots of "relay logs" available

MySQL first writes the relay logs from the master to a file. Once replication is interrupted, but the slave relay process continues to operate, the disk is filled by relay logs. 

This step should be done in any case, especially before the next one (ibdata too large) to make room.

Procedure

The files for the database are usually located in /var/lib/mysql

If not, the location can be found in /etc/my.cnf The corresponding entry is datadir=(pfad)

  1. Alle Relay Logs löschen:

    cd /var/lib/mysql
    rm mysqld-relay-bin*

    Restart MySQL service

    service mysqld restart

    If enough space is available (at least 20%) then proceed with the slave recovery as described above.

ibdata files on the slave "very large"

The files for the database are usually located in /var/lib/mysql

Due to not clearly documented MySQL internas, the file /var/lib/mysql/ibdata1 can be huge compared to the master database.
To remedy this, you have to proceed a little more rigorously.

Procedure

  1. If no less than 100% disk can be achieved by the steps above:
    1. Unsubscribe the MySQL service from the autostart:

      service mysqld disable


    2. Restart the computer with :

      reboot

      Only works if less than 100% disk is reached (possibly after reboot above) then

      1. Log on to the mysql server:

        mysql -u root -p


      2. Drop all JTEL databases:

        SET FOREIGN_KEY_CHECKS=0;
        DROP DATABASE JTELLog;
        DROP DATABASE JTELStats;
        DROP DATABASE JTELWeb;
        SET FOREIGN_KEY_CHECKS=1;

        Press CTRL+C to return to the command line, and then

        service mysqld stop
        rm /var/lib/mysql/ibdata*
        rm /var/lib/mysql/ib_log_*

        Start MySql Server, and enable it again if necessary:

        service mysqld start
        service mysqld enable

        Check disk space, and proceed with Slave Restore as described above.

Still no disk space > 20% free

In this case the slave is simply too small. The hard disk must be expanded (as with extending the STORE role, apply only to the logical volume where the MySQL database data resides). Then perform the steps again, if the disk is too small, then restore the slave as described above.

Or the slave is completely rebuilt with a larger plate.