同一台机器安装两个及以上MySQL服务:
下载mysql安装包,安装完成以后将安装文件夹复制多份在磁盘上面;分别进入my.ini修改port(端口不能冲突),server_id,basedir(optional),datadir(数据文件路径)等参数;
# 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-20140721I.log"
slow-query-log=1
slow_query_log_file="VIPSH-20140721I-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
#=====从服务器需要配置=====
relay_log = EricSun-mysql-relay-bin
log_slave_updates = 1
read_only = 1
# Error Logging.
log-error="VIPSH-20140721I.err"
注:复制安装文件夹时一定要删除auto.cnf,否则启动slave的时候会报错: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服务:mysqld --install MySQLXY --defaults-file="C:\Program Files\MySQL\MySQL Server
X.Y\my.ini"
安装成功以后,分别启动不同的mysql服务;
登陆进入不同的mysql实例,输入show master status\G;查看主服务器状态;输入show slave status\G;查看从服务器状态;
然后再从服务器CMD窗口设置:change master to master_host=‘localhost‘,master_user=‘root‘,master_password=‘root‘,master_log_file=‘mysql-bin.000001‘,master_log_pos=‘0‘;
然后再次输入show slave status\G; 查看
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
后台线程运行YES。
此时在主库上进行CRUD,从库会有更新