Mysql Master Slave Config,mysqlslave

來源:互聯網
上載者:User

Mysql Master Slave Config,mysqlslave

同一台機器安裝兩個及以上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,從庫會有更新


相關文章

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.