Mysql is configured based on binlog master-slave replication and mysqlbinlog master-slave

Source: Internet
Author: User

Mysql is configured based on binlog master-slave replication and mysqlbinlog master-slave

The last time I configured the master-slave replication for mysql was at the beginning of the year, I did not expect to start using mysql again. If you don't talk much about it, go to the topic.

Master-Slave Build Environment: Master: OS: rhel-server-6.3-x86_64Mysql: MySQL-5.5.35-1 Virtual Machine: Virtual BOXIp: 192.168.56.12Slave: OS: rhel-server-6.3-x86_64Mysql: MySQL-5.5.35-1 Virtual Machine: Virtual BOXIp: 192.168.56.13

Overall steps:
1. Modify the Master configuration file (my. cnf)
2. Create a user with the copy permission on the Master.
3. Copy the database on the Master to Slave.
4. Modify the Slave configuration file (my. cnf)
5. Slave initialization and Replication
6. Test
7. FAQs



1. Modify the Master configuration file (my. cnf)

[Mysqld] server-id = 1 // it must be the unique id of the server. The default value is 0. log-bin = mysql-bin // binary log replicate-do-db = zbdba must be enabled.




2. Create a user with the copy permission on the Master.

mysql>create user zbdba; mysql>grant replication slave on *.* to zbdba identified by '123456';



3. Copy the database on the Master to Slave.

Mysql> flush tables with read lock; mysql> show master status->; + metric + ---------- + -------------- + ---------------- + | File | Position | Binlog_Do_DB | usage | + usage + ---------- + -------------- + usage + | ogg1-bin.000003 | 107 | + usage + -------- + -------------- + ------------------ + 1 row in set (0.00 sec) mysql> quit [root @ ogg/] #/usr/bin/mysqldump zbdba-uroot-pmysql -- opt | mysql zbdba-uroot-pmysql-h 192.168.56.13 must be authorized in slave: grant all privileges on *. * TO 'root' @ '192. 168.56.13 'identified BY 'mysql' with grant option; mysql> unlock tables;


4. Modify the Slave configuration file (my. cnf)

[Mysqld] server-id = 2 // it must be the unique id of the server. The default value is 0. log-bin = mysql-bin // binary log replicate-do-db = zbdba must be enabled.



5. Slave initialization and Replication
mysql>slave stop; mysql>CHANGE MASTER TO MASTER_HOST='192.168.56.12',MASTER_USER='zbdba',MASTER_PASSWORD='123456',MASTER_LOG_FILE='ogg1-bin.000003',MASTER_LOG_POS=107;mysql> show slave status\G;*************************** 1. row ***************************               Slave_IO_State: Waiting for master to send event                  Master_Host: 192.168.56.12                  Master_User: zbdba                  Master_Port: 3306                Connect_Retry: 60              Master_Log_File: ogg1-bin.000003          Read_Master_Log_Pos: 107               Relay_Log_File: ogg2-relay-bin.000002                Relay_Log_Pos: 252        Relay_Master_Log_File: ogg1-bin.000003             Slave_IO_Running: Yes            Slave_SQL_Running: Yes              Replicate_Do_DB: zbdba


6. Test

Master:

mysql> show tables;+-----------------+| Tables_in_zbdba |+-----------------+| guestbook       || test            || test1           |+-----------------+

create table test2 select * from test1;

mysql> show tables;+-----------------+| Tables_in_zbdba |+-----------------+| guestbook       || test            || test1           || test2           |+-----------------+
Salve:

mysql> show tables;+-----------------+| Tables_in_zbdba |+-----------------+| guestbook       || test            || test1           || test2           |+-----------------+4 rows in set (0.00 sec)



If you need to configure the relationship between master and slave, you only need to create the corresponding user on the slave database, and initialize the original master.


7. FAQs
There is no corresponding my. cnf file under/etc
Solution:
If mysql is installed using the rpm package, no corresponding my. cnf file. At this time, you only need to copy one/usr/share/mysql directory. cnf file to the/etc directory and renamed it my. cnf.


The Server-id parameter cannot be modified.
Solution:
Check whether the same server-id = 1 exists in my. cnf.


MYSQL master/backup ERROR: ERROR 1201 (HY000 ):
Solution:
Mysql> slave stop;
Query OK, 0 rows affected, 1 warning (0.00 sec)


Mysql> reset slave;


Query OK, 0 rows affected, (0.00 sec)




ERROR 1130 (HY000): Host '*. *' is not allowed to connect to this MySQL server
Solution:
If you want to allow myuser to connect to the mysql server from a host whose ip address is 192.168.1.3, and use mypassword as the password
Grant all privileges on *. * TO 'myuser' @ '192. 168.1.3 'identified BY 'mypassword' with grant option;





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.