Simple configuration of MySQL master-slave server _mysql
Source: Internet
Author: User
First, add the user rights that can be logged on the primary server:
GRANT REPLICATE SLAVE on *.* to ' username ' @ ' host ' identified by ' password '
Then set the primary server's My.ini file.
Server-id=1 #主服务器标识
Log-bin #启用二进制日志
Binlog-do-bin=databasename #要备份的数据库名称, multiple can repeat the configuration process
Binlog-ignore-db=databasename #不备份的数据库名称, multiple can repeat the configuration process
From the server's configuration
server-id=2 #从服务器标识, range 1---2e32-1
Master-host=hostname/hostip #主服务器ip或主机名称
Master-user=username #登陆主服务器的用户名
Master-password=password #登陆主服务器的密码
Master-port = Portid #主服务器的运行端口号
Replicate-do-db=databasename #要同步的数据库名称, multiple can repeat the configuration process
Replicate-ignore=db=databasename #不同步的数据库名称, multiple can repeat the configuration
Log-bin #从服务器启动二进制日志记录
Master-connect-retry = seconds #与主服务器断开连接后, time to reconnect automatically
Skip-start-slave #防止随服务器的启动而启动同步程序
At this point, a simple master-slave server configuration is complete.
Commands that can be run on the master server side:
Show master status; #查看主服务器的运行状态
show slave hosts; #查看从服务器主机列表
Add:
Using show slave status from the server
Slave_io_running, for No, Io_thread does not start, please perform Slave start [Io_thread]
Slave_sql_running for no, copy error, view last_error field after error to perform Slave start [Sql_thread]
View Slave_io_state Fields
Null//Copy not started
Connecting to master//not connected to master
Waiting for Master to send event//is already connected
Add: You can use the load DATA from master statement to establish slave. But there are constraints:
The data table is all MyISAM table, must have super permission, master copy user must have reload and super permissions.
Perform reset master at master to purge existing log changes.
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 the relay log file is hostname-relay-bin.nnn and Hostname-relay-bin.index. Available from the server--
Relay-log and--relay-log-index options are modified. There is also a Relay-log.info relay information file from the server, available
--relay-log-info-file startup option to modify the filename.
Two-machine standby is two MySQL at the same time configured as Master and slave
Related commands on the primary server:
Show Master Status
Show slave hosts
Show logs
Show Binlog Events
Purge logs to ' log_name '
Purge logs before ' date '
Reset Master (old version flush Master)
Set sql_log_bin=
Related commands from the server:
Slave start
Slave stop
SLAVE STOP io_thread//This thread writes the log of the master segment to the local
SLAVE Start Io_thread
SLAVE STOP sql_thread//This thread applies logs written to local 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)
Changes master to master_host=, master_port=,master_user=, master_password=//dynamic Change master information
PURGE Master [before ' date '] Deletes a log that has been synchronized at the master end
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