# MySQL replication MASTER setting #
server-id = 1
log-bin = /var/log/mysql/binary/mysql-bin.log
binlog-do-db = student
binlog-ignore-db = mysql
log = /var/log/mysql/mysql.log
SHELL> mkdir /var/log/mysql/
SHELL> chown mysql:mysql -R /var/log/mysql/
SHELL> mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 950
Server version: 5.0.45-community-log MySQL Community Edition (GPL)
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| cPanel |
| cphulkd |
| devendra |
| eximstats |
| horde |
| leechprotect |
| mysql |
| pleskmods |
+——————–+
9 rows in set (0.00 sec)
mysql> create database student;
Query OK, 1 row affected (0.03 sec)
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| cPanel |
| cphulkd |
| devendra |
| eximstats |
| horde |
| leechprotect |
| mysql |
| pleskmods |
| student |
+——————–+
10 rows in set (0.00 sec)
mysql> use student;
Database changed
mysql> create table class ( rollno INT(5) NOT NULL PRIMARY KEY AUTO_INCREMENT , name VARCHAR(30) );
Query OK, 0 rows affected (0.32 sec)
mysql> DESC class;
+——–+————-+——+—–+———+—————-+
| Field | Type | Null | Key | Default | Extra |
+——–+————-+——+—–+———+—————-+
| rollno | int(5) | NO | PRI | NULL | auto_increment |
| name | varchar(30) | YES | | NULL | |
+——–+————-+——+—–+———+—————-+
2 rows in set (0.03 sec)
mysql> INSERT INTO class VALUES (”, ‘Arun Bagul’);
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> SELECT * FROM class;
+——–+————+
| rollno | name |
+——–+————+
| 1 | BHAVESH |
+——–+————+
1 row in set (0.00 sec)
mysql> INSERT INTO class VALUES (”, ‘Suhail Thakur’);
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> INSERT INTO class VALUES (”, ‘Bhavesh Vala’);
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> SELECT * FROM class;
+——–+—————+
| rollno | name |
+——–+—————+
| 1 | BHAVESH |
| 2 | Suhail Thakur |
| 3 | Bhavesh Vala |
+——–+—————+
3 rows in set (0.00 sec)
mysql> GRANT REPLICATION SLAVE ON *.* TO ‘replication’@’192.168.0.%’ IDENTIFIED BY ‘mypwd’;
Query OK, 0 rows affected (0.01 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
mysql> SHOW MASTER STATUS;
+——————+———-+—————–+——————+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+——————+———-+—————–+——————+
| mysql-bin.000002 | 98 | student,student | mysql,mysql |
+——————+———-+—————–+——————+
1 row in set (0.02 sec)
mysql>
mysql> SHOW PROCESSLIST;
+—-+——-+———–+——-+———+——+————+————————–+
| Id | User | Host | db | Command | Time | State | Info |
+—-+——-+———–+——-+———+——+————+————————–+
| 31 | root | localhost | NULL | Query | 0 | NULL | SHOW PROCESSLIST |
| 41 | horde | localhost | horde | Sleep | 0 | | NULL |
| 42 | horde | localhost | horde | Query | 1 | statistics | SELECT session_data FROM horde_sessionhandler WHERE session_id = ‘f70a7d64bd353917679814813a513c8f’ |
| 43 | horde | localhost | horde | Query | 1 | statistics | SELECT session_data FROM horde_sessionhandler WHERE session_id = ‘f70a7d64bd353917679814813a513c8f’ |
+—-+——-+———–+——-+———+——+————+————————–+
4 rows in set (0.00 sec)
mysql> SHOW PROCESSLIST\G;
*************************** 1. row ***************************
Id: 31
User: root
Host: localhost
db: NULL
Command: Query
Time: 0
State: NULL
Info: SHOW PROCESSLIST
1 row in set (0.00 sec)
mysql>
SHELL> /etc/init.d/mysql restart
Shutting down MySQL… [ OK ]
Starting MySQL [ OK ]
SHELL> cd /var/log/mysql/binary/
SHELL> ls
mysql-bin.000001 mysql-bin.index
# MySQL replication SLAVE setting #
server-id=3
master-port=3306
master-host=192.168.XXX.XXX
master-user=replication
master-password=mypwd
master-connect-retry=60
replicate-do-db=student
SHELL> mysqladmin create student -u admin -p
Enter password:
SHELL> mysql -u admin -p student show databases;
+———–+
| Database |
+———–+
| horde |
| mysql |
| pleskmods |
| psa |
| student |
+———–+
5 rows in set (0.00 sec)
mysql> use student;
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> show tables;
+——————-+
| Tables_in_student |
+——————-+
| class |
+——————-+
1 row in set (0.00 sec)
mysql> select * from class;
+——–+—————+
| rollno | name |
+——–+—————+
| 1 | Arun Bagul |
| 2 | Suhail Thakur |
| 3 | Bhavesh Vala |
| 4 | Nishit Shah |
+——–+—————+
4 rows in set (0.00 sec)
mysql>
mysql> CHANGE MASTER TO MASTER_HOST=‘192.168.XXX.XXX’, MASTER_USER=’replication’ , MASTER_PASSWORD=’mypwd’,MASTER_LOG_FILE=’mysql-bin.000004′,MASTER_LOG_POS=412;
Query OK, 0 rows affected (0.01 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for 192.168.XXX.XXX
Master_Host: 192.168.XXX.XXX
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000103
Read_Master_Log_Pos: 16995
Relay_Log_File: magnet-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000103
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB: auth,auth
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 16995
Relay_Log_Space: 98
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
1 row in set (0.00 sec)
mysql> quit
Bye
SHELL> /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]