Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MySQL master-slave replication configuration

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Configure the master database: my.cnf:server-id = 1log-bin restart database login and view: [root@Mysql-server ~] # mysql-uroot-p199429mysql > show variables like 'log_bin' +-+ | Variable_name | Value | +-+-+ | log_bin | ON | +-+-+ mysql > show variables like 'server_id' +-+-+ | Variable_name | Value | +-+-+ | server_id | 1 | establish master-slave replication account: mysql > grant replication slave on *. * to 'rep'@'192.1.1.%' identified by' 199429' Mysql > select user,host from mysql.user +-+-+ | user | host | +-+-+ | root | 127.0.0.1 | | bbs | 192.1.1.% | | keer | 192.1.1.1% | | rep | 192.1.1.1% | | wordpress | 192.1.1.1% | | root | | | localhost | +-+-+ implements read-only locking table on master database: mysql > flush table with read lock | Query OK, 0 rows affected (0.00 sec) mysql > show variables like'% timeout%' +-- +-+ | Variable_name | Value | +-+-+ | connect_timeout | 10 | | delayed_insert_timeout | 300 | | Innodb_lock_wait_timeout | 50 | innodb_rollback_on_timeout | OFF | | interactive_timeout | 28800 | # | lock_wait_timeout | 31536000 | | net_read_timeout | 30 | net_write_timeout | 60 | slave_net_timeout | 3600 | | wait_timeout | 28800 | # +- -- +-+ 10 rows in set (0.00 sec) to view the status of the main database: mysql > show master status +-+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-- -- + | Mysql-server-bin.000001 | 962 | +- -+-+ 1 row in set (0.00 sec) newly opened window backup exported data: [root@Mysql-server ~] # mkdir-p / server/backup/ [root@Mysql-server ~] # mysqldump-uroot-p199429-- events-A-B | gzip > / server/backup/mysql_bak.$ (date +% F). Sql.gz is here to check whether the status of the main database has changed: mysql > show master status +-+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-- -- + | Mysql-server-bin.000001 | 962 | +- -+-+ 1 row in set (0.00 sec) from database: configuration file my.cnfserver-id = 2 # guarantee unique restart login from database: [root@Mysql-server_02 backup] # mysql-uroot-p199429-S / data/3306/mysql.sock mysql > show variables like 'log_bin' +-+-+ | Variable_name | Value | +-+-+ | log_bin | OFF | +-+-+ 1 row in set (0.00 sec) mysql > show variables like 'server_id' +-+-+ | Variable_name | Value | +-+-+ | server_id | 3 | +-+-+ restore MySQLdump data [root@Mysql-server_02 backup] # cd / server/backup/ [root@Mysql-server_02] Backup] # gzip-d mysql_bak.2017-03-23.sql.gz [root@Mysql-server_02 backup] # mysql-uroot-pendant 199429'-S / data/3306/mysql.sock CHANGE MASTER TO-> MASTER_HOST='192.1.1.11' -> MASTER_PORT=3306,-> MASTER_USER='rep',-> MASTER_PASSWORD='199429',-> MASTER_LOG_FILE='Mysql-server-bin.000001',-> MASTER_LOG_POS=962 Login status execution method for fee: [root@Mysql-server_02 backup] # mysql-uroot-pendant 199429'-S / data/3306/mysql.sock start slave; Query OK, 0 rows affected (0.00 sec) mysql > show slave status\ G * * 1. Row * * Slave_IO_State: Waiting for master to send event Master_Host: 192.1.1.11 Master_User: rep Master_Port: 3306 Connect_Retry: 60 Master_Log_File: Mysql-server-bin.000001 Read_Master_Log_Pos: 962 Relay_Log_File: relay-bin.000002 Relay_Log_Pos: 260 Relay_Master_Log_File: Mysql-server-bin.000001 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 962 Relay_Log_Space: 410 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 11 row in set (0.00 sec) Test Master-Slave replication function (omitted)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report