New mysql multi-thread master-slave replication _ PHP Tutorial

Source: Internet
Author: User
The new version of mysql builds multi-threaded master-slave replication. New mysql build multi-thread master-slave replication 1: yuminstall-ymysql-community-cl new mysql build multi-thread master-slave replication









I. First, get
Mysql-5.7.11-1.el6.x86_64.rpm-bundle.tar

Tar xf mysql-5.7.11-1.el6.x86_64.rpm-bundle.tar
Yum install-y mysql-community-client-5.7.11-1.el6.x86_64.rpm mysql-community-common-5.7.11-1.el6.x86_64.rpm mysql-community-libs-5.7.11-1. el6.x86 _ 64.rpm mysql-community-libs-compat-5.7.11-1.el6.x86_64.rpm mysql-community-server-5.7.11-1.el6.x86_64.rpm

Start:
/Etc/init. d/mysqld start
[Root @ vm10 mnt] #/etc/init. d/mysqld start
Initializing MySQL database: [OK]
Installing validate password plugin: [OK]
Starting mysqld: [OK]

Obtain the initial password:
Grep 'temporary password'/var/log/mysqld. log
Mysql-p Press enter and enter the initial password

Change password:
Alter user root @ localhost identified by 'redhat007! '
Password Rules: must be greater than eight characters long and contain uppercase letters, lowercase letters, numbers, and special characters.

Create a database xp1 in it and use it for testing.
Mysql> create database xp1;
Then I created add. SQL under/mnt (for later use) code as follows:

 
 
  1. Create table usertb (
  2. Id serial,
  3. Uname varchar (20 ),
  4. Ucreatetime datetime,
  5. Age int (11)
  6. )
  7. ENGINE = MYISAM
  8. Default character set = utf8 COLLATE = utf8_general_ci
  9. AUTO_INCREMENT = 1
  10. ROW_FORMAT = COMPACT;

  11. Delimiter $
  12. Set autocommit = 0 $

  13. Create procedure test1 ()
  14. Begin
  15. Declare v_cnt decimal (10) default 0;
  16. Dd: loop
  17. Insert into usertb values
  18. (Null, 'user 1', '2017-01-01 00:00:00 ', 20 ),
  19. (Null, 'user 2', '2017-01-01 00:00:00 ', 20 ),
  20. (Null, 'user 3', '2017-01-01 00:00:00 ', 20 ),
  21. (Null, 'user 4', '2017-01-01 00:00:00 ', 20 ),
  22. (Null, 'user 5', '2017-01-01 00:00:00 ', 20 ),
  23. (Null, 'user 6', '2017-01-01 00:00:00 ', 20 ),
  24. (Null, 'user 7', '2017-01-01 00:00:00 ', 20 ),
  25. (Null, 'user 8', '2017-01-01 00:00:00 ', 20 ),
  26. (Null, 'user 9', '2017-01-01 00:00:00 ', 20 ),
  27. (Null, 'user 0', '2017-01-01 00:00:00 ', 20)
  28. ;
  29. Commit;
  30. Set v_cnt = v_cnt + 10;
  31. If v_cnt = 10000000 then leave dd;
  32. End if;
  33. End loop dd;
  34. End; $

  35. Delimiter;
Then execute the code in the newly created database.

Trigger the stored procedure in the code
Call test1 inserts 10 million rows of data in the usertb table
The following shows that the data has been inserted.

Modify the code, create usertb1 in the table, and then continue triggering. write 10 million rows of data to it.
(Create two tables to make the difference between mysqldump and mysqlpump more obvious)
The creation is successful as follows


Test mysqldump and mysqlpump
Mysqldump:

Mysqlpump:
Time mysqlpump-p xp1> xp1. SQL

As shown above, it is much faster than 10 seconds, and the default number of threads of mysqlpump is 2.
Time mysqlpump-pRedhat006! -- Default-parallelism = 4 db1> db1. SQL
-- Default-parallelism = 4 you can modify the number of threads by yourself.

Make A mysql A -- B Copy
Configuration environment: master: 172.25.254.10
Slave: 172.25.254.11
First, in the master host
Vim/etc/my. cnf
Server-id = 1
Log-bin = mysql-bin
Binlog-do-db = test
/Etc/init. d/mysqld restart
Mysql-pRedhat007!
Run the following command to check whether the operation is successful:

Create database test;

Authorization:
Mysql> grant replication slave on *. * to xpp @ '2017. 25.254.11 'identified by 'redhat007! ';
Query OK, 0 rows affected, 1 warning (0.40 sec)
/Etc/init. d/mysqld restart

Slave end: 172.25.254.11
Vim/etc/my. cnf
Server-id = 2 is different from master.
Then install the latest mysql version on slave.
First, verify that the master is successfully authorized.
Mysql-pRedhat007! -Uxpp-h172.25.254.10 if you can log on to it, it will prove successful.

Mysql-pRedhat007!
Create a test database because the content of the two databases must be consistent before synchronization.
Then: chang master to master_host = '192. 25.254.10 ', master_user = 'xpp', master_password = 'redhat007! ', Master_log_file = 'MySQL-bin.000001', master_log_pos = 154;

/Etc/init. d/mysqld restart

On the master side:
One of the new features of MySQL is the addition of a global transaction ID (GTID) to enhance database master/slave consistency, fault recovery, and fault tolerance capabilities.
Vim/etc/my. cnf add the following two lines to enable gtid mode

Gtid-mode = on
Enforce-gtid-consistency = on

/Etc/init. d/mysqld restart

And then on slave
Vim/etc/my. cnf is added as follows
Gtid-mode = on
Enforce-gtid-consistency = on
Slave-parallel-type = LOGICAL_CLOCK
Slave-parallel-workers = 16
Master_info_repository = TABLE
Relay_log_info_repository = TABLE
Relay_log_recovery = ON

/Etc/init. d/mysqld restart




















First get the mysql-5.7.11-1.el6.x86_64.rpm-bundle.tar tar xf mysql-5.7.11-1.el6.x86_64.rpm-bundle.tar yum install-y mysql-community-cl...

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.