MySql Slave


MySql Slave my.cnf

# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql

server-id=2

default-storage-engine = InnoDB
innodb_file_per_table = 1

mysql> show slave status;
Empty set (0.00 sec)


MySql Database Restore

$ mysql -p mydb < mydb.sql


MySql Slave Change Master to

mysql> change master to 
master_host='master.mysql.com', 
master_user='replica',
master_password='password',
MASTER_LOG_FILE='mysql-bin.000002', 
MASTER_LOG_POS=461451;


MySql Slave Data Files

# ls -l /var/lib/mysql/
total 20552
-rw-rw---- 1 mysql mysql 10485760 Oct  5 11:55 ibdata1
-rw-rw---- 1 mysql mysql  5242880 Oct  5 11:55 ib_logfile0
-rw-rw---- 1 mysql mysql  5242880 Oct  5 11:30 ib_logfile1
-rw-rw---- 1 mysql mysql       75 Oct  5 11:56 master.info
drwx------ 2 mysql mysql     4096 Oct  4 16:56 mysql
-rw-rw---- 1 mysql mysql      235 Oct  5 11:56 mysqld-relay-bin.000004
-rw-rw---- 1 mysql mysql       26 Oct  5 11:56 mysqld-relay-bin.index
srwxrwxrwx 1 mysql mysql        0 Oct  4 16:56 mysql.sock
-rw-rw---- 1 mysql mysql       56 Oct  5 11:56 relay-log.info


MySql Slave master.info

# cat /var/lib/mysql/master.info 
14
mysql-bin.000002
461451
master.mysql.com
replica
password
3306
60
0


MySql Slave relay-log.info

# cat /var/lib/mysql/relay-log.info 
./mysqld-relay-bin.000002
16767
mysql-bin.000002
477983


MySql Slave Show Slave Status

when slave has been configured but is not (yet) running
mysql> show slave status \G

*************************** 1. row ***************************
			 Slave_IO_State: 
				Master_Host: master.mysql.com
				Master_User: replica
				Master_Port: 3306
			  Connect_Retry: 60
			Master_Log_File: mysql-bin.000002
		Read_Master_Log_Pos: 461451
			 Relay_Log_File: mysqld-relay-bin.000001
			  Relay_Log_Pos: 4
	  Relay_Master_Log_File: mysql-bin.000002
		   Slave_IO_Running: No
		  Slave_SQL_Running: No
			Replicate_Do_DB: 
		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: 461451
			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 Slave Start

start the slave
mysql> start slave;


stop the slave
mysql> stop slave;


MySql Slave Show Slave Status

when slave has been configured and started and is still running
mysql> show slave status \G
*************************** 1. row ***************************
			 Slave_IO_State: Waiting for master to send event
				Master_Host: master.mysql.com
				Master_User: replica
				Master_Port: 3306
			  Connect_Retry: 60
			Master_Log_File: mysql-bin.000002
		Read_Master_Log_Pos: 477983
			 Relay_Log_File: mysqld-relay-bin.000002
			  Relay_Log_Pos: 16767
	  Relay_Master_Log_File: mysql-bin.000002
		   Slave_IO_Running: Yes
		  Slave_SQL_Running: Yes
			Replicate_Do_DB: 
		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: 475080
			Relay_Log_Space: 13864
			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: 0
1 row in set (0.00 sec)




MySql Slave Show Status

mysql> show status 

+-----------------------------------+-----------+
| Variable_name                     | Value     |
+-----------------------------------+-----------+
| Aborted_clients                   | 0         | 
| Aborted_connects                  | 9         | 
| Binlog_cache_disk_use             | 0         | 
| Binlog_cache_use                  | 0         | 
| Bytes_received                    | 1436      | 
| Bytes_sent                        | 55976     | 


| Slave_open_temp_tables            | 0         | 
| Slave_retried_transactions        | 0         | 
| Slave_running                     | ON        | 


MySql Slave Processes

mysql> show processlist;

| Id  | User        | Host      | db   | Command | Time | State                           | Info             |
-----------------------+------------------+
| 184 | system user |           | NULL | Connect |  457 | Waiting for master to send event                 
| 185 | system user |           | NULL | Connect |  233 | Has read all relay log; waiting for the slave 

I/O thread to update it | NULL             | 

3 rows in set (0.00 sec)



REFERRERS
MySqlReplication
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki