同1臺(tái)機(jī)器安裝兩個(gè)及以上MySQL服務(wù):
下載mysql安裝包,安裝完成以后將安裝文件夾復(fù)制多份在磁盤(pán)上面;分別進(jìn)入my.ini修改port(端口不能沖突),server_id,basedir(optional),datadir(數(shù)據(jù)文件路徑)等參數(shù);
# Path to the database root
datadir="D:/MySQL/MySQL Server 5.7/data/"
# General and Slow logging.
log-output=FILE
general-log=1
general_log_file="VIPSH⑵0140721I.log"
slow-query-log=1
slow_query_log_file="VIPSH⑵0140721I-slow.log"
long_query_time=2
# Binary Logging.
# log-bin
server_id = 54
log_bin = D:/MySQL/MySQL Server 5.7/data/EricSun-mysql-bin.log
log_bin_index = D:/MySQL/MySQL Server 5.7/data/EricSun-mysql-bin.index
max_binlog_size = 256M
expire_logs_days = 30
#=====從服務(wù)器需要配置=====
relay_log = EricSun-mysql-relay-bin
log_slave_updates = 1
read_only = 1
# Error Logging.
log-error="VIPSH⑵0140721I.err"
注:復(fù)制安裝文件夾時(shí)1定要?jiǎng)h除auto.cnf,否則啟動(dòng)slave的時(shí)候會(huì)報(bào)錯(cuò):Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.
以上完成以后,cmd輸入命令安裝windows service服務(wù):mysqld --install MySQLXY --defaults-file="C:Program FilesMySQLMySQL Server X.Ymy.ini"
安裝成功以后,分別啟動(dòng)不同的mysql服務(wù);
登陸進(jìn)入不同的mysql實(shí)例,輸入show master statusG;查看主服務(wù)器狀態(tài);輸入show slave statusG;查看從服務(wù)器狀態(tài);
然后再?gòu)?a href="http://www.vxbq.cn/server/" target="_blank">服務(wù)器CMD窗口設(shè)置:change master to master_host='localhost',master_user='root',master_password='root',master_log_file='mysql-bin.000001',master_log_pos='0';
然后再次輸入show slave statusG; 查看
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
后臺(tái)線程運(yùn)行YES。
此時(shí)在主庫(kù)上進(jìn)行CRUD,從庫(kù)會(huì)有更新