MySQL Master-slave configuration

Source: Internet
Author: User

1. Configure the Environment:
Centos 7 64-bit basic network version mysql5.7

2.hosts file
[Email protected] log]# cat/etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
:: 1 localhost localhost.localdomain localhost6 localhost6.localdomain6


172.16.160.201 Master
172.16.160.202 slave

3. Configuration file Modification
[Email protected] log]# CAT/ETC/MY.CNF

[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
Symbolic-links=0
Log-error=/var/log/mysqld.log
Pid-file=/var/run/mysqld/mysqld.pid

# Zhuyr
Character_set_server=utf8
init_connect= ' SET NAMES UTF8 '

User=mysql
Log-bin = Master-bin
Log-bin-index = Master-bin.index
server_id = 1
Innodb_log_file_size = 256M
Expire-logs-days = 1
Port = 3306
Tmpdir =/tmp
Basedir =/usr


Note: Log-bin, Log-bin-index If the value is not provided, the default value is Hostname-bin. To avoid confusing log filenames due to system name changes, it is a good idea to create a machine for the server
Unique server name regardless of the person.

[Email protected] log]# CAT/ETC/MY.CNF
[Mysqld]

Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
Symbolic-links=0
Log-error=/var/log/mysqld.log
Pid-file=/var/run/mysqld/mysqld.pid

# Zhuyr
Character_set_server=utf8
init_connect= ' SET NAMES UTF8 '

User=mysql
Basedir =/usr
Tmpdir =/tmp
Port = 3306
server_id = 2
Relay_log_index = Slave_relay_bin.index
Relay_log = Slave_relay_bin
Innodb_log_file_size = 256M
Expire-logs-days = 1

[Email protected] log]#

4. Establish a master-slave connection
Create a replication user in master
mysql> grant replication Slave on * * to [e-mail protected] identified by ' maks.123 ';
After completing the user's creation, please remember to refresh the System permissions table;
Mysql>flush privileges;


Performing device connections on the slave side
--Use the Change Master to command to point to master
mysql> Change Master to master_host= ' master ', master_port=3306,master_user= ' repl_user ', master_password= ' Maks.123 ‘;
--Start replication
mysql> start slave;


5. Test replication

--Create a database or table on the master side
mysql> CREATE DATABASE Licz;
Query OK, 1 row Affected (0.00 sec)

--Check if sync is on slave side
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| Information_schema |
| MySQL |
| Performance_schema |
| Test |
+--------------------+
4 rows in Set (0.01 sec)


[Email protected] log]# Cat/var/log/mysqld.log

2017-04-12t07:37:07.081984z 1 [ERROR] Slave I/O for Channel ": Error Connecting to master ' [email protected]:3306 '-retry-time:60
Retries:8, error_code:1130
2017-04-12t07:38:07.082880z 1 [Error] Slave I/O for Channel ': Err or connecting to master ' [email protected]:3306 '-retry-time:60
Retries:9, error_code:1130
2017-04-12t07: 38:56.190835z 7 [Note] Access denied for user ' [email protected] ' @ ' localhost ' (using Password:yes)
2017-04-12T07:39:07.083771Z 1 [ERROR] Slave I/O for Channel ": ERROR Connecting to master ' [email protected]:3306 '- Retry-time:60
Retries:10, error_code:1130
2017-04-12t07:40:07.084596z 1 [ERROR] Slave I/O for Channel ': Error Connecting to master ' [email protected]:3306 '-retry-time:60
Retries:11, error_code:1130
2017-04-12t07:4 1:07.085259z 1 [Note] Slave I/O thread for Channel ": Connected to master ' [email protected]:3306 ', Replication start Ed
in log ' first ' at position 4

MySQL Master-slave configuration

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.