MySQL database master-slave configuration

Source: Internet
Author: User

First, the primary database configuration
1) Modify the master database configuration file
[Mysqld]
#编号
Server-id=1
#打开二进制日志
Log-bin-master-bin
#主数据库日志
Log-bin-index=master-bin.index

2) Restart data
Service mysqld Restart

3) MySQL command to view the primary database log
SHOW MASTER STATUS


Second, from the database configuration
1) Modify the configuration file from the database
[Mysqld]
#编号
server-id=2
Relay-log-index=slave-relay-bin.index
Relay-log=slave-relay-bin


2) Restart the database
Another way:
/etc/init.d/mysql stop
/etc/init.d/mysql start

Third, the main library settings from the library connection is the user
1) Create user
Create user repl;
2) User Authorization
Grant REPLICATION SLAVE on * * to ' repl ' @ ' [from database IP] ' identified by ' [authorized user Password] ';
Flush privileges;

Iv. Modifying the point from the database to the primary database
1) Execute MySQL command
Change Master to master_host= ' [primary database IP] ', master_port=[Primary database Port],master_user= ' Repl ',
Master_password= ' [Repl's password] ', master_log_file= ' [master-bin.000001 (primary database binary log file)] ',
master_log_pos=0;

2) Start master/slave synchronization from Library
MySQL command: start slave;

3) View status from library
mysql command: show slave status \g;

4) Concou Stop master-Slave synchronization function
mysql command: Stop slave;

V. Import the local database into the remote database
1) Export SQL locally
Mysqldump-uroot-p TestDB > Testdb.sql
2) Copy SQL Guide remote server
SCP testdb.sql [Email protected][remote IP Address]:[remote folder path]
3) remote server Import SQL
Create DATABASE TestDB;
use;
source [SQL file address];

4) User-authorized SQL
Grant SELECT, INSERT, UPDATE, delete on *. * to ' [authorized user] ' @ '% '
Identified by ' [authorized user Password] ' with GRANT OPTION;

MySQL database 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.