3

To ensure the data on the slave and master are in the same place for replication, the new master should be stopped and data transferred to the new slave before starting the master again, at least this is one option.

How can I start replication of a MySQL server without stopping the master?

Dave Cheney
  • 18,567
  • 8
  • 49
  • 56
davidmytton
  • 666
  • 3
  • 7
  • 17

4 Answers4

6

easy option - if you have small amount of data use

mysqldump --master-data -uyouruser -p.... -a > dump.sql

this will lock all tables and generate dump with info about current master position. dump will lock all tables - probably not something you want to do when you have busy website and 20gb data to dump.

more advanced option. take your data on lvm partition and use lvm snapshot. that is in one process lock all tables FLUSH TABLES WITH READ LOCK; SHOW MASTER STATUS; in another proces run sync few times for a good measure and create lvm snapshot of your data / innodb logs. just after creating snapshot [ that takes 2-3 seconds for me ] unlock all tables.

now you have consistent snapshot and your sql server still running. mount snapshot and 'ship it' asap to another server. there run mysql on this data, let innodb reover all data from it's logs and run mysqldump which output put to slave.

start slave using information from SHOW MASTER STATUS that you've run just before taking LVM snapshot.

mylvmbackup does exactly that. read about it here.

pQd
  • 29,981
  • 6
  • 66
  • 109
0

FLUSH TABLES WITH READ LOCK on the master, copy the data to the slave (possibly with periodic SELECT NULL operations on the client that's talking to the master to prevent the locks from being lost to connection timeouts), then start replication on the slave and UNLOCK TABLES on the master.

All the master operations specified need to be within a single client session. Don't go trying to exit it while the copy is in progress.

chaos
  • 7,483
  • 4
  • 34
  • 49
0

As pQd mentioned above:

mysqldump --master-data -uyouruser -p.... -a > dump.sql

but why not ssh into the remove machine and pipe the data directly trough ssh?

elcuco
  • 357
  • 1
  • 4
  • 10
  • sometimes ssh can slower than let's say nc http://www.mysqlperformanceblog.com/2009/05/31/using-netcat-to-copy-mysql-database/ – pQd Jun 01 '09 at 20:06
  • netcat kicks ass... you are right... (how about security?) – elcuco Jun 02 '09 at 16:32
  • 1
    @elcuco netcat comes with all the security benefits of telent and ftp combined, that is: no security what so ever if your data crosses untrusted network. – pQd Jun 03 '09 at 09:18
0

I can't comment yet, but what about the difference between MyISAM and INNODB? I'm not sure you can simply do a lock tables with INNODB and expect a good snapshot.

Dustin
  • 199
  • 3