setting replicate mysql
huff.. setelah sukses install vmware dan setting network dengan bridge connection dari komputer guest (yang diinstall di vmware) — atau diasumsikan sebagai server baru (dalam artikel ini server database)– sekarang aku akan coba replicate mysql. kita asumsikan ada 2 server yaitu master (computer host:192.168.22.15) dan slave (computer guest–vmware–:192.168.22.115).
syarat2 yang dibutuhkan untuk replicate mysql ini adalah :
- terdapat lebih dari satu server database
- adanya mysql di kedua server
- adanya koneksi antara server2 tersebut
step2nya adalah sbb :
- untuk memudahkan remote ke slave, kita grant dulu akses mysql dari server luar
mysql> GRANT ALL PRIVILEGES ON *.* TO cuplis@localhost IDENTIFIED BY ‘pass’ WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO cuplis@192.168.22.15 IDENTIFIED BY ‘pass’ WITH GRANT OPTION;
mysql> flush privileges; - setting my.cnf di slave
sebelum setting dimulai, lebih baik kita backup dulu file my.cnf supaya jika terjadi kesalahan lebih mudah restorenya.user@computer:$ sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf-oriuser@computer:$ sudo vim /etc/mysql/my.cnftemukan baris seperti di bawah ini, kemudian remark dengan memberi tanda # (jika belum ada) di awal baris dan lakukan hal ini pada master dan slave.
#bind-address = 127.0.0.1
konfigurasi bind-address ini hanya semula (ketika belum diremark) mengijinkan ip 127.0.0.1 untuk terhubung dengan mysql (dalam hal ini di server mysql yang akan dijadikan slave). supaya mysql di server slave bisa di akses selain dari ip yang didefinisikan di bind-address, maka kita remark bind-address.
- lakukan remote dari master (jika dirasa perlu) dengan menjalankan perintah berikut :
user@computer:$ mysql -u cuplis -h 192.168.22.115 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 9
Server version: 5.0.51a-3ubuntu5.4 (Ubuntu)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> - siapkan database yang akan di replicate, dalam kasusku ini adalah dbuks
mysql> use dbuks;
Database changed
mysql> show tables;
+—————–+
| Tables_in_dbuks |
+—————–+
| medical |
| obat |
| siswa |
+—————–+
3 rows in set (0.00 sec)mysql>
- konfigurasi my.cnf di master. tambahkan 3 baris berikut ini di my.cnf :server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = dbuks - restart mysql service di master
user@computer:$ sudo /etc/init.d/mysql restart
- kemudian kita buat user untuk mysql dengan level replication di master
user@computer:$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 35
Server version: 5.0.75-0ubuntu10 (Ubuntu)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'password_slave';
Query OK, 0 rows affected (0.02 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.03 sec)
mysql> - masih setting mysql di master
user@computer:$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 31
Server version: 5.0.75-0ubuntu10-log (Ubuntu)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> use dbuks;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
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 | 98 | dbuks | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
mysql>informasi2 hasil dari show master status di atas akan diperlukan untuk konfigurasi di slave. kemudian kita keluar dari shell mysql dengan mengetikkan perintah quit.
- kopikan database yang ada di master ke slave. ada 2 cara yang dapat dilakukan untuk pengopian database ini. yang pertama dengan menggunakan dump database dan yang lainnya adalah dengan menggunakan “LOAD DATA FROM MASTER” di command slave. kali ini kita akan gunakan cara yang pertama. lakukan command berikut :
user@computer:$ mysql -u cuplis -h 192.168.22.115 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 9
Server version: 5.0.51a-3ubuntu5.4 (Ubuntu)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql>mysqldump -u root -p<password root di master> --opt dbuks > dbuks.sql
(tidak ada spasi di antara -p dan password)perintah di atas akan menghasilkan SQL dump untuk database dbuks di file dbuks.sql. kemudian kita unlock tabel yang ada di database dbuks :
user@computer:$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 33
Server version: 5.0.75-0ubuntu10-log (Ubuntu)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> use dbuks;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> UNLOCK TABLES;
Query OK, 0 rows affected (0.00 sec)
mysql> quit; - kopikan file dbuks.sql yang ada di master ke slave
user@computer:$ scp /home/arditto/dbuks.sql arditto@192.168.22.115:~
arditto@192.168.22.115's password:
dbuks.sql 100% 3363 3.3KB/s 00:00 - buat database dbuks di slave
user@computer:$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 13
Server version: 5.0.51a-3ubuntu5.4 (Ubuntu)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> create database dbuks;
Query OK, 1 row affected (0.02 sec)
mysql> quit; - kemudian import SQL dump yang sudah kita dapatkan dari master tadi
user@computer:$ mysql -u root -p dbuks < ~/dbuks.sql
- konfigurasi my.cnf di slave. tambahkan 5 baris berikut ini di my.cnf slave :
user@computer:$ sudo vim /etc/mysql/my.cnf
server-id=2
master-host=192.168.22.15
master-user=slave_user
master-password=password_slave
master-connect-retry=60
replicate-do-db=dbuks - restart mysql service di slave
user@computer:$ sudo /etc/init.d/mysql restart
- langkah terakhir adalah setting change master di slave :
user@computer:$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 10
Server version: 5.0.51a-3ubuntu5.4 (Ubuntu)
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> SLAVE START;
Query OK, 0 rows affected (0.00 sec)
mysql> CHANGE MASTER TO MASTER_HOST='192.168.22.15', MASTER_USER='slave_user', MASTER_PASSWORD='password_slave', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=98;
Query OK, 0 rows affected (0.10 sec)
mysql>MASTER_HOST : ip address master (dalam kasus ini 192.168.22.15)
MASTER_USER : user yang sudah kita grant dengan privileges replication di master
MASTER_PASSWORD : password MASTER_USER di master
MASTER_LOG_FILE : file MySql yang diterima ketika kita menjalankan SHOW MASTER STATUS; di master
MASTER_LOG_POS : posisi MySql yang diterima ketika kita menjalankan SHOW MASTER STATUS; di master
source :
http://groups.google.com/group/mysql-indonesia?hl=id
http://www.howtoforge.com/mysql_database_replication
http://forums.mysql.com/read.php?11,6916,184947#msg-184947
http://forums.mysql.com/read.php?26,36723,253532#msg-253532
Related posts:

just mlaku2….
eh ada yg bahas replicate juga ya….
btw picnya made in odad ya……
mntap gan…