mysql+centos7+ Master-slave replication

Source: Internet
Author: User

MYSQL (MARIADB)
MARIADB database management System is a branch of MySQL, mainly by the open source community in the maintenance, the use of GPL license.
One of the reasons for developing this branch is that after Oracle acquired MySQL, there is a potential risk of shutting MySQL out of the source, so the community uses a branching approach to avoid this risk.
MARIADB is designed to be fully compatible with MySQL, including APIs and command lines, making it easy to be a replacement for MySQL.
Method 1:yum Installation Mariadb

Related commands

The relevant command for the MARIADB database is: Systemctl start mariadb  #启动MariaDBsystemctl stop mariadb  #停止MariaDBsystemctl restart MARIADB  #重启MariaDBsystemctl enable mariadb  #设置开机启动

Normal use of MySQL after startup

Systemctl Start mariadb# Enter mysqlmysql-uroot-p

Method 2: Download Mysql-server package (RPM)

# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm# RPM-IVH mysql-community-release-el7-5.noarch.rpm# Yum Install Mysql-community-server
Configure MySQL

1. Chinese Encoding settings

Edit MySQL configuration file/etc/my.cnf[mysqld]character-set-server=utf8datadir=/var/lib/mysqlsocket=/var/lib/mysql/ Mysql.sockcollation-server=utf8_general_cisecurity riskssymbolic-links=0log-error=/var/log/mysqld.logpid-file=/ Var/run/mysqld/mysqld.pid[client]default-character-set=utf8[mysql]default-character-set=utf8

2. Authorization Configuration

Remote connection Settings Oh set all permissions for all libraries, all tables, assign permissions to root users for all IP addresses
MySQL > Grant all privileges on * * to [email protected] '% ' identified by ' password ';
#创建用户
MySQL > Create user ' username ' @ '% ' identified by ' password ';
#刷新权限
Flush privileges;
MySQL Master-slave replication

Principle of Master-slave mechanism implementation

(1) Master changes the record to binary log (these are called binary log events, binary logs event), and (2) slave copies the binary log events of master to its trunk log (relay log); (3) Slave redo the event in the trunk log and change the data to reflect its own.
Master Master Library Configuration
#查看数据库状态systemctl status mariadb# stop Mariadbsystemctl stop mariadb

#修改配置文件
Vim/etc/my.cnf
#修改内容

[Mysqld]
Server-id=1
Log-bin=mysql-bin

#重启mariadb
Systemctl Start mariadb
Master Main Library add from library account
1. New user chaoge for master-slave synchronization, allow login from the library is ' 192.168.178.130 ' Create user ' chaoge ' @ ' 192.168.178.130 ' identified by ' Redhat '; 2.# Digression: If prompt password is too simple not compound strategy add in front add this sentence mysql> set global validate_password_policy=0;3. To grant permission from the library account to the Chaoge copy from the library, Copy on the 192.168.178.130 machine
Grant Replication Slave on * * to ' chaoge ' @ ' 192.168.178.130 ';

4. Check the status of the main library

MariaDB [(None)]> Show Master Status
;
+------------------+----------+--------------+------------------+
| File | Position | binlog_do_db | binlog_ignore_db |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 | 575 | | |
+------------------+----------+--------------+------------------+
1 row in Set (0.00 sec)

File is the binary log file name, and Position is where the log begins. Back from the library will be used back from the library will use the back from the library will use the!!!!!!

Slave configuration from Library
1. Check the slave database status Systemctl status Mariadb2. Stop Mariadbsystemctl Stop mariadb

3. Modify the configuration file my.cnf

server-id=2 #一定要和主库区别开

4. Restart MARIADB
Systemctl Start mariadb

5. Login MARIADB
Mysql-uroot-p

6. Use the account authorized by the main library

MySQL > Change master to master_host= ' 192.168.178.129 ',
Master_user= ' Chaoge ',
Master_password= ' Redhat ',
Master_log_file= ' mysql-bin.000001 ',
master_log_pos=575;

7. Restart the database

Systemctl Restart MARIADB

mysql+centos7+ Master-slave replication

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.