master server : unix.kunsan.ac.kr(203.234.57.44)
slave server : granada.kunsan.ac.kr(203.234.57.40)
ÀÌ ¿¹Á¦´Â MySQL version 4.1.0À» »ç¿ëÇÑ ¿¹ÀÌ´Ù.
Master server¿¡¼ ½ÇÇàÇÒ ´Ü°è
1) master server¿¡¼ replication »ç¿ëÀÚ(¿¹Á¦¿¡¼: repl)¸¦ ¸¸µé°í replication slave ±ÇÇÑÀ» ºÎ¿©ÇÔ
# mysql -u root -proot_pass
mysql> grant replication slave
-> on *.*
-> to repl@'%'
-> identified by 'arirang';
Query OK, 0 rows affected (0.06 sec)
mysql>
load data from master¸¦ ¼öÇàÇϱâ À§Çؼ ÁÖ¾îÁ®¾ß ÇÏ´Â ±ÇÇÑ
mysql> grant reload,super on *.* to repl@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
mysql>
2) Å×À̺íÀ» lockÇÏ°í µ¥ÀÌÅͺ£À̽º¸¦ ¹¾î ¾ÐÃàÇÑ ´ÙÀ½ unlock ÇÔ
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.03 sec)
mysql> exit
Bye
# cd /export/home/mysql
# tar cf mysql-snapshot.tar ./var/jijoeDB
# ls -l mysql-snapshot.tar
-rw-r--r-- 1 root other 20480 Aug 18 13:36 mysql-snapshot.tar
# mysql -u root -p
mysql> show master status;
+-----------------+----------+--------------+------------------+
| File | Position | Binlog_do_db | Binlog_ignore_db |
+-----------------+----------+--------------+------------------+
| unix-bin.000006 | 289 | | |
+-----------------+----------+--------------+------------------+
1 row in set (0.19 sec)
¢Ð ¨çFile°ú ¨èPositionÀÇ ÇÊµå °ªÀ» È®ÀÎÇÔ
mysql> unlock tables;
Query OK, 0 rows affected (0.02 sec)
mysql> exit
3) my.cnfÀÇ mysqld ¼½¼ÇÀ» ¼öÁ¤ÇÑ´Ù.
# vi /etc/my.cnf
[mysqld]
log-bin
server-id=1
Slave server¿¡¼ ½ÇÇàÇÒ ´Ü°è
1) Slave ¼¹ö¸¦ stop½Ã۰í, my.cnf¿¡ ´ÙÀ½ Ç׸ñÀ» Ãß°¡ÇÑ´Ù.
# mysqladmin -uroot shutdown
#
# vi /etc/my.cnf
[mysqld]
server-id=2 ¢Ð 1À» 2·Î ¼öÁ¤
2) Slave ¼¹ö¸¦ start½ÃŰ´Ù.
# /export/home/mysql/share/mysql/mysql.server start
# pgrep mysqld
450
470
#
3) master ¼¹ö¿¡ snapshotÇÑ mysql-snapshot.tar¸¦ µ¥ÀÌÅÍ µð·ºÅ丮¿¡ º¹»çÇÑ´Ù.
# cd /export/home/mysql
# ftp unix.kunsan.ac.kr
ftp> cd /export/home/mysql
ftp> dir
-rw-r--r-- 1 root other 20480 Aug 18 13:36 mysql-snapshot.tar
drwx------ 5 mysql mysql 512 8¿ù 18ÀÏ 10:15 var
ftp> bi
ftp> get mysql-snapshot.tar
ftp> by
# tar xf mysql-snapshot.tar
#
4) Slave ¼¹ö¿¡¼ ´ÙÀ½ ¸í·ÉÀ» ½ÇÇàÇÑ´Ù.
mysql> stop slave;
Query OK, 0 rows affected (0.02 sec)
mysql> change master to
-> master_host="unix.kunsan.ac.kr",
-> master_user="repl",
-> master_password="arirang",
-> master_log_file="unix-bin.000006", ¢Ð ¨çÀÇ file°ªÀÓ
-> master_log_pos=289; ¢Ð ¨èÀÇ position °ªÀÓ
Query OK, 0 rows affected (0.01 sec)
mysql>
5) slave thread¸¦ startÇÑ´Ù.
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql>
¡¼¿¹Á¦¡½½ÇÇà È®ÀÎ
1) master¿¡¼
mysql> select * from bb;
+------+
| a |
+------+
| 1111 |
| 2222 |
| 3333 |
| 4444 |
| 55 |
| 66 |
+------+
6 rows in set (0.01 sec)
mysql> delete from bb where a="1111";
Query OK, 1 row affected (0.08 sec)
mysql> delete from bb where a="2222";
Query OK, 1 row affected (0.00 sec)
mysql> select * from bb;
+------+
| a |
+------+
| 3333 |
| 4444 |
| 55 |
| 66 |
+------+
4 rows in set (0.00 sec)
mysql>
2) slave¿¡¼ (master ¼öÁ¤ Àü)
mysql> select * from bb;
+------+
| a |
+------+
| 1111 |
| 2222 |
| 3333 |
| 4444 |
| 55 |
| 66 |
+------+
6 rows in set (0.09 sec)
mysql>
3) slave¿¡¼ (master ¼öÁ¤ Á÷ÈÄ)
mysql> select * from bb;
+------+
| a |
+------+
| 3333 |
| 4444 |
| 55 |
| 66 |
+------+
4 rows in set (0.01 sec)
mysql>
¶Ç ´Ù¸¥ ¿¹Á¦ º¸±â
Replication Options in 'my.cnf'
SQL commands Related to replication