MySQL database synchronization from the master configuration and separate read and write

The main benefit from using mysql replication are:

1, from the master server using this architecture, stability can be improved. If the primary server fails, we can use from the server to provide services.

2, the main processing user requests from the server separately, can improve data processing efficiency.

3, the copied data on the primary server from the server to protect the data from accidental loss.

Environment Description:

To build a new enterprise architecture based mysql database from replication.

The primary server (mysql-master): IP Address: 192.168.48.128, mysql installed, no user data.

From the server (mysql-slave): IP Address: 192.168.48.130, mysql installed, no user data.

Master and slave server can provide normal service.

Configure the master server (master)

1, edit the database configuration file my.cnf or my.ini (windows), usually in the / etc / directory.

In the following [mysqld] adding the following codes:

 log-bin=mysql-bin
server-id=1
innodb_flush_log_at_trx_commit=1
sync_binlog=1
binlog-do-db=wordpress
binlog_ignore_db=mysql

 Description:

server-id = 1 // 1 can Rending Yi, as long as the line is unique.

binlog-do-db = wordpress // is a backup only wordpress.

binlog_ignore_db = mysql // omit backup mysql.

Without binlog-do-db and binlog_ignore_db, it means all the backup database.

2, and then restart MySQL: #service mysqld restart

3, log mysql, add a backup of the account in mysql, and licensed to the server.

[root@localhost~]#mysql -u root –p 123456 登录mysql
mysql>grant replication slave on*.* to 'backup'@'192.168.48.130' identifiedby 'backup';

Create a backup user, and licensed to use 192.168.48.130.

4, the state of the primary database query, and note the value of Position FILE and, behind this configuration from the time server to use.

mysql> show masterstatus; note the information in the display configuration from the server will be used.

+——————+———-+————–+——————

+|File|Position|Binlog_Do_DB|Binlog_Ignore_DB|

+——————+———-+————–+——————

+|mysql-bin.000001|253|dbispconfig|mysql|

+——————+———-+————–+——————+

1rowinset(0.00sec)

In operation, from the server:

1), to ensure that there /etc/my.cnf log-bin = mysql-bin server-id = 1 and the parameter, and the server-id = 1 modified to server-id = 10. After modifying follows:

[mysqld] 

?
1
2
log-bin=mysql-bin //启动二进制文件
server-id=10 //服务器ID

2), restart the mysql service.

[root@localhost~]#mysqladmin-p123456shutdown

[root@localhost~]#mysqld_safe--user=mysql&

3), log in mysql, execute the following statement

[root@localhost~]#mysql-uroot–p123456

mysql>changemastertomaster_host='192.168.48.128',master_user='backup',master_password='backup',master_log_file='mysql-bin.000003',master_log_pos=401;

4) Start slave synchronization.

mysql>start slave;

5) Check master-slave replication connection from the normal synchronization, and if you see Slave_IO_Running Slave_SQL_Running are Yes, the Lord.
mysql>show slave status\G

Verify the configuration is normal, mysql master can be copied from the normal.

Create a new library on the master database, and a table and write some data in the library.

[root@localhost~]#mysql -u root –p 123456

mysql>create database mysqltest;

mysql>use mysqltest;

mysql>create table user(idint(5),namechar(10));

mysql>insert into user values(00001,'zhangsan');

In the verification from the database and see whether normal to copy data.

[root@localhost~]#mysql -u root –p 123456

mysql>show databases;

mysql>select * from mysqltest.user;

Guess you like

Origin www.cnblogs.com/HKROnline-SyncNavigator/p/10971462.html