MySQL raplication Configuration

Source: Internet
Author: User

Environment:

Main Library: 192.168.1.1

From library: 192.168.1.2


Yum Install wget

Mv/etc/yum.repos.d/centos-base.repo/etc/yum.repos.d/centos-base.repo.backup

wget Http://mirrors.163.com/.help/CentOS6-Base-163.repo

MV Centos6-base-163.repo/etc/yum.repos.d/centos-base.repo

Yum Clean All

Yum Makecache


Process Brief:

1, installation Mysql-server

2, define the master-slave library, namely Server-id

3. Define the path and name of the binary log file in the MySQL configuration file

4. Restart the main library and from the library in turn

5. Create a Telnet user with replication permissions on the main library

6, back up the main library, empty from the library

7. Back up the original library from the library

8. View the main library status, record the full name and position value of the main library binary log

9, log on from the library using the change command to dynamically connect to the main library

10, view from the library status, "Slave_io_running" and "slave_sql_running" for Yes, the master-slave configuration is successful

Start synchronizing the main library



1. Install MySQL

Yum Install-y mysql-server


2. Define SERVER_ID,ID values cannot be the same

Master

Server-id=1

Slave

server-id=2


3. Modify the MySQL configuration file (/etc/my.cnf) by adding the following:

Master

Server-id=1

Log-bin=binlog

# # #启用二进制日志

Slave

server-id=2

Relay_log=/var/lib/mysql/mysql-relay-bin

Relay_log_index=/var/lib/mysql/mysql-relay-bin.index


4. After the change, restart the MySQL service "Guthrie after":

/etc/init.d/mysqld restart


5. On master, go to MySQL to do the following:

Mysql>

Grant Replication Slave on * * to ' KKK ' @ '% ' identified by ' 123 ';

Query OK, 0 rows Affected (0.00 sec)

Mysql>

Flush privileges;

Query OK, 0 rows Affected (0.00 sec)

# #创建一个可以远程登录的用户, and give it replication slave permissions.


6. Do the following on the slave1:

Cd/var/lib/mysql

RM-RF *

/etc/init.d/mysqld restart


7. Do the following on master:

MYSQLDUMP-A-X--events >/tmp/backup.sql

##-x Lock Table

scp/tmp/backup.sql [Email protected]:/tmp/

# #将备份文件拷贝到 on the slave1 server.


8. Do the following on the slave1:

MySQL </tmp/backup.sql

# #在 The database restore operation on the slave1.


9. Do the following on master:

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 |

+---------------+----------+--------------+------------------+

| binlog.000003 |                          420724 |                                | |

+---------------+----------+--------------+------------------+

1 row in Set (0.00 sec)

Mysql>

Unlock tables;

Query OK, 0 rows Affected (0.00 sec)


10. Test on slave1 to connect to master

Mysql-u kkk-p123-h 192.168.1.1


11. Do the following on the slave1:

Mysql>

Change Master to master_host= ' 192.168.1.1 ', master_port=3306,master_user= ' KKK ', master_password= ' 123 ', Master_log_ File= ' binlog.000003 ', master_log_pos=420724;

Query OK, 0 rows affected (0.03 sec)

Mysql>

Start slave;

Query OK, 0 rows Affected (0.00 sec)

Mysql>

show slave status \g;

Slave_io_running:yes

Slave_sql_running:yes


12. Test: Create a database on master, add a table, and then log in to Slave

You can see that the data is synchronized.

Problems encountered: 11 steps to find slave_io_running behind is No, tried a lot of methods are

No, then simply copy a my.cnf configuration file from the master machine, modify it, reboot

Service, do it again.


This article is from the "Feng Ling ao xue" blog, please keep this source http://2689027.blog.51cto.com/2679027/1619586

MySQL raplication Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.