MySQL-Synchronisation von Master und Slave
Software-Informationen:
Betriebssystemtyp: CentOS 6.3
Ausführung:mysql-5.5.28
master ip: 192.168.137.27
sklave ip 192.168.137.28
So stellen Sie MySQL bereit,Sie können auf https verweisen://www.roamway.com/55.html
Edit configuartion file.
vim /etc/my.cnf
Warnung:we only demo the basic fouction simply.You may need to add other extra feature
when this cluster be used to production.
[mysqld] part of mster configuration
[mysqld]
socket=/usr/local/mysql/data/mysql.sock
default-storage-engine=MyISAM
server-id=27
log-bin=mysqlmaster-bin.log
sync_binlog=1
lower_case_table_names=1
log_bin_trust_function_creators=1
[mysqld] part of slave configuration
[mysqld]
socket=/usr/local/mysql/data/mysql.sock
default-storage-engine=MyISAM
server-id=28
log-bin=mysqlslave-bin.log
sync_binlog=1
l0wer_case_table_names=1
l0g_bin_trust_function_creators=1
Edit startup script of master and slave
vim /etc/init.d/mysqld
modify the value of “basedir=” und “datadir=”
mysql initialization
/usr/local/mysql/scripts/mysql_install_db \
–basedIr=/usr/local/mysql \
–datadir=/usr/local/mysql/data \
–user = mysql
Start master and slave, logining master and creating account which is used to synchronization.
[root@mysqlmaster ~]#/usr/local/mysql/bin mysql -uroot -p
MySQL> GRANT REPLICATON SLAVE ON *.* TO ‘slave’@’192.168.137.28’ IDENTIFIED BY ‘123456’;
Query OK, 0 rows affected (0.34Sek)
Check status of master and note down File field and the value of Position,
The information will be used when configure this cluster.
MySQL> show master status;
+————————+———-+————–+——————+——————-+
| Datei | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+————————+———-+————–+——————+——————-+
| mysqlmaster-bin.000004 | 963| | | |
+————————+———-+————–+——————+——————-+
1 row in set (0.00 Sek)
startup slave and login it ,execute the following command.
change master to master_host=’192.168.137.27′,master_user=’slave’,master_password=’123456′,
master_log_file=’mysqlmaster-bin.00004′,master_log_pos=963;
And the value of master_log-bin and master_log_pos which were queried from master.
start duplicate thread in slave.
MySQL> start slave;
Query OK, 0 rows affected (0.02 Sek)
check status of slave
MySQL> show slave status
If both the status of Slave_IO_Running and Slave_SQL_Running are yes,It indicates that the
synchronization from master to slave is successfull, wie in der folgenden Abbildung gezeigt.
Confirm whether the synchronization machenism works or not .
master operation:
use roamway;
Tabellen anzeigen;
create table test2(id int primary key auto_increment,name varchar(20))auto_increment=1;
insert into test2 values(1,’roamway同步测试’);
Tabellen anzeigen;
wählen * from test2;
slave operation:
use roamway;
Tabellen anzeigen;
wählen * from test2;
It means that data synchronization from master to slave takes effect