Windows mysql 主從服務(wù)器配置

參考資料

mysql replication on windows server

  1. Configure on both servers a different server-id, and activate the binary log on the master. If it is not already done, the most typical way to do that is modify the my.ini file and restart the service (net restart mysql):
[mysqld]
log-bin
server-id = 1

Make also sure that the master is accesible from the slave node and it is not bound to localhost (bind-address = 127.0.0.1)

  1. Create a user on the master for the slave to connect with REPLICATION SLAVE privileges (use MySQL-command line for this):
mysql master> CREATE USER 'user_name'@'ip.of.the.slave' IDENTIFIED BY 'password';
mysql master> GRANT REPLICATION SLAVE ON *.* TO 'user_name'@'ip.of.the.slave'; 
  1. Make a backup of the master and apply it to the slave. There are several ways to do that (stopping the server and copying the files works), but the easiest would be to se mysqldump (navigate to the bin directory of your sql-server installation (f.e. C:\Program Files\MySQL\MySQL Server 5.7\bin). Also you may need to provide credentials by appending this to both commands: -uroot -pPassword)
(on the master windows command line) mysqldump --all-databases --master-data > dump.sql
(on the slave windows command line ) mysql < dump.sql

At the beginning the dump.sql you will find a line like this:

-- CHANGE MASTER TO MASTER_LOG_FILE = 'file_name', MASTER_LOG_POS = file_pos;

Use those parameters to configure the replication on the slave:

mysql slave> CHANGE MASTER TO MASTER_HOST = 'ip.of.the.master',
                 MASTER_USER = 'user_name_you_just_created',
                 MASTER_PASSWORD = 'password_you_just_defined',
                 MASTER_LOG_FILE = 'file_name',
                 MASTER_LOG_POS = file_pos;

(beware, no quotes for integers, like MASTER_LOG_POS).

  1. If everything is ok until now, just start replication on the slave:
mysql slave> START SLAVE;

To check that it is running, execute:

mysql slave> SHOW SLAVE STATUS;

And look for:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
GTID-based replication is a bit different, and I have not mentioned it.

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容