Simple configuration of MySQL master-slave server

Source: Internet
Author: User

First, add the login user permissions on the master server:
Grant replicate slave on *. * To 'username' @ 'host' identified by 'Password'

Set the my. ini file of the master server.
Server-id = 1 # master server ID
Log-bin # enable binary log
BINLOG-do-bin = databasename # Name of the database to be backed up. You can repeat the configuration process for multiple database names.
BINLOG-ignore-DB = databasename # Name of the database that is not backed up. You can repeat the configuration process for multiple database names.

Slave Server Configuration
Server-id = 2 # slave server ID, range: 1-2-2 e32-1
Master-host = Hostname/hostip # master server IP address or host name
Master-user = username # username used to log on to the master server
Master-Password = PASSWORD # password used to log on to the master server
Master-Port = portid # Port Number of the master server
Replicate-do-DB = databasename # Name of the database to be synchronized. You can repeat the configuration process for multiple database names.
Replicate-ignore = DB = databasename # Name of the database that is not synchronized. You can repeat this configuration for multiple database names.
Log-bin # Start binary log records from the server
Master-connect-retry = seconds # time when the master server is reconnected after being disconnected
Skip-start-slave # prevents synchronization from being started as the server startsProgram

So far, a simple master-slave server is configured.
Commands that can be run on the master server:
Show Master Status; # view the running status of the master server
Show slave hosts; # view the slave server host list
Supplement:
Use show slave status on the slave server
If slave_io_running is set to no, io_thread is not started. Run slave start [io_thread]
If slave_ SQL _running is no, a replication error occurs. Check the last_error field to exclude the error and run slave start [SQL _thread].
View the slave_io_state Field
Null // copy not started
Connecting to master // no connection to master
Waiting for Master to send event // already connected
Supplement: You can use the load data from Master statement to create a Server Load balancer instance. But there are constraints:
All data tables must be MyISAM tables and have super permissions. Master replication users must have reload and super permissions.
On the master side, execute reset master to clear existing Log changes,
At this time, the slave end cannot start io_thread because the master log cannot be found. please clear the data directory
Relay-log.info, hosname-relay-Bin * and other files restart MySQL
The default file for relay log files is hostname-relay-bin.nnn and hostname-relay-bin.index. Available slave server --
Modify the relay-log and -- relay-log-index options. There is also a relay-log.info relay information file in the slave server, available
-- Relay-log-Info-file start option to modify the file name.
Dual-host mutual backup means that two MySQL instances are configured as both master and slave
Commands on the master server:
Show Master Status
Show slave hosts
Show logs
Show BINLOG events
Purge logs to ''log _ name''
Purge logs before ''date''
Reset master (earlier version of flush master)
Set SQL _log_bin =
Commands on the slave server:
Slave start
Slave stop
Slave stop io_thread // This thread writes logs of the master segment to the local
Slave start io_thread
Slave stop SQL _thread // This thread applies logs written locally to the database
Slave start SQL _thread
Reset slave
Set global SQL _slave_skip_counter
Load data from Master
Show slave status (super, replication client)
Change master to master_host =, master_port =, master_user =, master_password = // dynamically change master information
Purge master [before ''date'] deletes logs that have been synchronized from the master.

Related Article

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.