您好,登錄后才能下訂單哦!
配置主數據庫: my.cnf: server-id = 1 log-bin 重啟數據庫 登錄并查看: [root@Mysql-server ~]# mysql -uroot -p199429 mysql> show variables like 'log_bin'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | log_bin | ON | +---------------+-------+ mysql> show variables like 'server_id'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | server_id | 1 | +---------------+-------+ 建立主從復制賬號: 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.% | | rep | 192.1.1.% | | wordpress | 192.1.1.% | | root | localhost | +-----------+-----------+ 實現對主數據庫鎖表只讀: 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) 查看主庫狀態: mysql> show master status; +-------------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-------------------------+----------+--------------+------------------+ | Mysql-server-bin.000001 | 962 | | | +-------------------------+----------+--------------+------------------+ 1 row in set (0.00 sec) 新開窗口備份導出數據: [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 在此查看主庫狀態是否變化: mysql> show master status; +-------------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +-------------------------+----------+--------------+------------------+ | Mysql-server-bin.000001 | 962 | | | +-------------------------+----------+--------------+------------------+ 1 row in set (0.00 sec) 從數據庫: 配置文件my.cnf server-id = 2 ####保證唯一性 重啟從數據庫 登錄從數據庫: [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 | +---------------+-------+ 恢復MySQLdump的數據 [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 -p'199429' -S /data/3306/mysql.sock <mysql_bak.2017-03-23.sql 登錄數據庫配置復制參數 [root@Mysql-server_02 backup]# mysql -uroot -p'199429' -S /data/3306/mysql.sock mysql> 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; 費登錄狀態執行方法: [root@Mysql-server_02 backup]# mysql -uroot -p'199429' -S /data/3306/mysql.sock<< EOF 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; EOF 實際修改從庫中的master.info文件 [root@Mysql-server_02 backup]# cat /data/3306/data/master.info 18 mysql-server-bin.000001 962 192.1.1.11 rep 199429 3306 60 0 ,。。。。。。。。 啟動主從復制: mysql> 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: 0 Master_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: 1 1 row in set (0.00 sec) 測試主從復制功能(省略)
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。