Sword refers to the installation of architect series-mysql and master-slave synchronization

Source: Internet
Author: User

1. Install the database
wget HTTP://DEV.MYSQL.COM/GET/MYSQL-COMMUNITY-RELEASE-EL7-5.NOARCH.RPMRPM-IVH Mysql-community-release-el7-5.noarch.rpmyum Install Mysql-community-server

Use the root user right when installing. After the installation is successful, it can be started:

/bin/systemctl Restart Mysqld.service

Modify the password for the root user of the MySQL database as follows:

Mysql-u rootmysql> set password for ' root ' @ ' localhost ' = password (' Password you want to set ');mysql> exit
Mysql-u root-p //Enter the password after the return

After retiring, re-login with username and password.

Remotely authorize a connection to MySQL

GRANT all privileges on * * to ' root ' @ '% ' identified by ' MyPassword ' with GRANT OPTION; FLUSH   privileges;

View MySQL's process pid

Netstat-anp|grep 3306|awk ' {printf $7} ' |cut-d/-f1

MySQL with system self-booting

/bin/systemctl Enable Mysqld

  

2, the database master-slave synchronization

Master: Master---192.168.0.147

From: slave1---192.168.0.248

To operate on the Master Master library:

Mysql-uroot   //user name root password at installation default is NULL//CREATE DATABASE Mysql>create IF not EXISTS cattle collate= ' utf8_general_ci ' CH Aracter set= ' UTF8 ';//Format: Grant permissions on database. * To username @ Login host identified by "password"; Mysql>grant all on cattle.*to ' cattle ' @ '% ' identified by ' cattle '; mysql>grant all on cattle.*to ' cattle ' @ ' localhost ' identified by ' cattle ';//create User mysql>grant REPLICATION slave,reload,super on * * to [email protected] ' 192.168.0.248 ' I Dentified by ' 123456 '; mysql>flush  privileges;

  

Modify the/ETC/MY.CNF configuration file and restart the MYQL after adding the following configuration under [MySQL].

Server-id = 1log-bin=mysql-binlog-slave-updates=cattlebinlog-do-db=cattlebinlog-ignore-db=mysql

After you lock the main library, package the main library, and then unlock the main library.

Mysql> FLUSH TABLES with READ lock;mysql> SHOW MASTER STATUS;

#cd/var/lib/mysql#tar czvf  cattle.tar.gz Cattle

Mysql> UNLOCK TABLES;

Then transfer the cattle.tar.gz to 192.168.0.248, as follows:

scp/var/lib/mysql/cattle.tar.gz  [Email protected]:/var/lib/mysql/cattle.tar.gz  

 

To operate from the library on Slave1:

Modify the file cattle.tar.gz permissions as follows:

#chown-R/var/lib/mysql/mysql:mysql Cattle

Modify the/ETC/MY.CNF configuration file and add the following configuration under [MySQL]:

Server-id =2log_bin=mysql-binrelay_log=mysql-relay-binread-only=1replicate-do-db=cattlelog-slave-updates=1

Verify after restarting MySQL.

Mysql-h192.168.0.147-uslave1-p123456show grants for [email protected];

To view file and position on master:

Mysql-ucattle-pcattlemysql>show  MASTER status\g;

As follows:

You can see the values of two properties.

Under the SLAVE1 host

Mysql-urootstop slavemysql>change MASTER to master_host= ' 192.168.0.147 ',         master_user= ' slave1 ',         master_ Password= ' 123456 ',         master_log_file= ' mysql-bin.000006 ',         master_log_pos=1018;  Start slave

Then look at the slave status as follows:

Observe the slave_io_running and slave_sql_running parameters are yes.

Under Master Host, proceed as follows:

You can do the synchronization test below.

Reference article: http://www.phperz.com/article/15/1113/169027.html

Official Document: Http://dev.mysql.com/doc/refman/5.6/en/replication-howto-slaveinit.html

  

  

  

Sword refers to the installation of architect series-mysql and master-slave synchronization

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.