13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

308 Chapter 12 Advanced <strong>MySQL</strong> Administration<br />

The reason for the read lock is that you need to record the place the server is up to in<br />

its binary log when the snapshot was taken.You can do this by executing this statement:<br />

show master status;<br />

You should see output similar to the following from this statement:<br />

+----------------------+----------+--------------+------------------+<br />

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |<br />

+----------------------+----------+--------------+------------------+<br />

| laura-ltc-bin.000001 | 95 | | |<br />

+----------------------+----------+--------------+------------------+<br />

Note the File <strong>and</strong> Position; you will need this information to set up the slaves.<br />

Now take your snapshot <strong>and</strong> unlock the tables with the following statement:<br />

unlock tables;<br />

If you are using InnoDB tables, the easiest way is to use the InnoDB Hot Backup tool,<br />

available from Innobase Oy at http://www.innodb.com.This is not Free Software, so<br />

there is a license cost involved. Alternatively, you can follow the procedure described<br />

here <strong>and</strong>, before unlocking the tables, shut down the <strong>MySQL</strong> server <strong>and</strong> copy the entire<br />

directory for the database you want to replicate before restarting the server <strong>and</strong> unlocking<br />

the tables.<br />

Setting Up the Slave or Slaves<br />

You have two optionsfor setting up the slave or slaves. If you have taken a snapshot of<br />

your database, begin by installing it on the slave server.<br />

Next, run the following queries on your slave:<br />

change master to<br />

master-host=’server’,<br />

master-user=’user’,<br />

master-password=’password’,<br />

master-log-file=’logfile’,<br />

master-log-pos=logpos;<br />

start slave;<br />

You need to fill in the data shown in italics.The server is the name of the master server.<br />

The user <strong>and</strong> password come from the GRANT statement you ran on the master server.<br />

The logfile <strong>and</strong> logpos come from the output of the SHOW MASTER STATUS statement<br />

you ran on the master server.<br />

You should now be up <strong>and</strong> running.<br />

If you did not take a snapshot, you can load the data from the master after running<br />

the preceding query by executing the following statement:<br />

load data from master;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!