Mysql database master-slave Replication

Source: Internet
Author: User

1 )*.LoginMysqlDatabase master server and set authorized users for slave server.

# Mysql-uroot-p123456 test


Mysql> grantall (slave) on *. * to user1_zc@192.168.10.2identified by "456 ";

Or

Mysql> grantreplication (slave) on *. * user1_zc@192.168.10.2identified by "pass ";

Mysql> showgrants for user1_zc@192.168.10.2; // check whether user authorization is successful

Ormysql> selectuser, host, password from mysql. user;


2 )*.LoginMysqlDatabase master server clearingBin-logLog records.

Mysql> resetmaster;

Mysql> showmaster status;


3 )*.ModifyMysqlConfiguration file of the database master server/Etc/my. cnf, Account OpeningBin-log,And setServer-idAnd restart the service..

# Vi/etc/my. cnf is enabled by default)

Log-bin = mysql-bin

Server-id = 1 (server-id can be set once)

# Servicemysqld restart or/usr/local/mysql/bin/mysqld_safe-user = mysql &


4 )*.BackupMysqlDatabase master server database)

#/Usr/local/mysql/bin/mysqldump-uroot-p123456 test-l-F>/tmp/test. SQL


5 )*.Restore the backed up database to the slave server.

# Scp/tmp/test. SQL root@192.168.10.2:/tmp/


6 )*.FromMysqlRecover data on the database server(Library)


#/Usr/local/mysql/bin/mysql-uroot-p123456 test </tmp/test. SQL

Mysql> showtables;

Mysql> select * from t1; // check whether the Master/Slave Data reaches



7 )*.ClearBin-logLogs(Original Master/Slave DatabasesBin-logLog consistency)

Mysql> resetmaster;

Mysql> showmaster status;



8 ).*Modify the configuration file of the slave Database ServerMy. cnfAnd restart the service..

Log-bin = mysql-bin

Server-id = 2 (server-id can be set once)


Master-host = 192.168.10.1

Master-user = user‑zc

Masters-password = 456

Master-port = 3306

# Servicemysqld restart or/usr/local/mysql/bin/mysqld_safe-user = mysql &


9 ).Slave TestUser‑zcCan a user log on to the master server from the slave server?

#/Usr/local/mysql/bin/mysql-uuser1_zc-p456-h192.168.10.2 test


10 ).Test data insertion on the master server and check whether the data is consistent on the slave server.





This article is from the "mhf_zzjc" blog, please be sure to keep this http://1meir3a.blog.51cto.com/6176787/1298417

Related Article

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.