master 10.0.0.100
slave 10.0.0.200

*** master ***

# vi /etc/my.cnf
server-id = 100
log_bin /var/lib/mysql/mysql-bin.log

# /etc/init.d/mysqld restart

# mysql -u root -pxxx
mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY 'passw0rd';

mysql> FLUSH TABLES WITH READ LOCK;
Query OK, 0 rows affected (0.00 sec)

mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 251 | | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
//remember the position

# mysqldump -u root -pxxxx --all-databases > all-databases.sql;

mysql> UNLOCK TABLES;
Query OK, 0 rows affected (0.00 sec)


*** slave ***
# scp login@10.0.0.100:all-databases.sql .

# vi /etc/my.cnf
server-id = 200
log_bin = /var/lib/mysql/mysql-bin.log

# /etc/init.d/mysql restart

# mysql -u root -pxxxx < all-databases.sql

mysql -u root -pxxxx
mysql> CHANGE MASTER TO
> MASTER_HOST='10.0.0.100',
> MASTER_USER='repl',
> MASTER_PASSWORD='passw0rd',
> MASTER_LOG_FILE='mysql-bin.000001',
> MASTER_LOG_POS=251;

mysql> START SLAVE;

arrow
arrow
    文章標籤
    mysql replication
    全站熱搜

    helloworld 發表在 痞客邦 留言(0) 人氣()