第一步,安装多个mysql
先停止mysql服务,将C:ProgramDataMySQLMySQL Server 5.7Data文件夹复制到新建的文件夹,比如:
E:MySQLMySQL3307
同时在文件夹Mysql3307中新建文件my.ini,内容如下
[mysql] character-set-server = utf8 [mysqld] port = 3307 server_id = 3307 basedir=E:MySQLMySQL3307 datadir=E:MySQLMySQL3307Data max_connections=200 character-set-server=utf8 default-storage-engine=INNODB log_error=error.log sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
并修改 E:MySQLMySQL3307Data中的auto.cnf,修改server-uuid
然后安装成服务
mysqld -install MySQL3307 --defaults-file="E:MySQLMySQL3307my.ini"
启动服务 net start MySQL3307,测试登录数据库
mysql -uroot -p -P3307
以上就是安装多个MySQL的步骤了。
第二步:MySQL的Master-Slave配置
首先配置Master,找到C:ProgramDataMySQLMySQL Server 5.7my.ini, 找到 # Error Logging位置,改之前
# Error Logging. log-error="iZgaj0ka5j3mumZ.err" # Server Id. server-id=1
改之后为
# Error Logging. log-error="iZgaj0ka5j3mumZ.err" log-bin=C:/ProgramData/MySQL/MySQL Server 5.7/mysql-bin sync_binlog=1 # Server Id. server-id=1
修改完成,重启主MySQL服务,执行
show master status G;
查看结果如下(其中File和Position的值后续会用到)
mysql> show master status G; *************************** 1. row *************************** File: mysql-bin.000001 Position: 1119 Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: 1 row in set (0.00 sec) ERROR: No query specified
接着配置从Mysql,在上面安装多个MySql的基础上,修改 E:MySQLMySQL3307my.ini 最新配置如下
[mysql] character-set-server = utf8 [mysqld] port = 3307 server_id = 3307 basedir=E:MySQLMySQL3307 datadir=E:MySQLMySQL3307Data log-bin=mysql-bin log-bin-index=mysql-bin.index sync_binlog=1 binlog_format=mixed binlog-do-db = test_db max_connections=200 character-set-server=utf8 default-storage-engine=INNODB log_error=error.log sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
重启从MySql服务,执行如下命令
mysql> stop slave;
mysql> CHANGE MASTER TO MASTER_HOST='localhost', MASTER_USER='root', MASTER_PASSWORD='123456', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=1119;
mysql> start slave;
mysql> show slave status G;
如下表示正常运行
Slave_IO_Running: Yes
Slave_SQL_Running: Yes