MySQL主從複製配置

fiona8953發表於2015-05-06
Master
192.168.102.168 

[mysql@fiona bin]$ mysqladmin -uroot -p version
Enter password: 
mysqladmin  Ver 8.42 Distrib 5.5.39, for Linux on x86_64
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Server version          5.5.39-log
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /usr/local/mysql/mysql.sock
Uptime:                 44 min 15 sec

Threads: 1  Questions: 9  Slow queries: 0  Opens: 33  Flush tables: 1  Open tables: 26  Queries per second avg: 0.003

Slave
192.168.102.130
[root@fiona2 home]# mysqladmin -uroot -p version
mysqladmin  Ver 8.42 Distrib 5.1.71, for redhat-linux-gnu on x86_64
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.

Server version          5.5.39-log
Protocol version        10
Connection              Localhost via UNIX socket
UNIX socket             /usr/local/mysql/mysql.sock
Uptime:                 5 min 2 sec

Threads: 1  Questions: 2  Slow queries: 0  Opens: 33  Flush tables: 1  Open tables: 26  Queries per second avg: 0.006

Steps:
//檢視是否啟用了日誌
mysql> show variables like 'log_bin' ;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | ON    |
+---------------+-------+
1 row in set (0.01 sec)

//檢視master的status
mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000019 |      107 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

//切換到data下面用mysqlbinlog檢視bin log
[root@fiona ~]# cd /usr/local/mysql/data
[root@fiona data]# mysqlbinlog mysql-bin.000002 | tail -20
SET TIMESTAMP=1408843507/*!*/;
COMMIT
/*!*/;
# at 1070530
#140824  9:25:07 server id 1  end_log_pos 1070549       Stop
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;

mysql> use test
Database changed
mysql> show tables;
Empty set (0.00 sec)


mysql> create table TEST(
    -> ID bigint not null primary key,
    -> NAME varchar(15) not null,
    -> EMAIL varchar(128) not null);
Query OK, 0 rows affected (0.04 sec)
mysql> insert into TEST (ID,NAME,EMAIL) values ('001','AAA','aaa@163.com');
Query OK, 1 row affected (0.03 sec)
mysql> insert TEST (ID,NAME,EMAIL) values ('003','CCC','ccc@163.com'),('002','BBB','bbb@163.com');
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0



有個小技巧跟大家介紹下,我在準備轉換的時候發現日誌檔案有2G多,尋思著為什麼mysql為什麼不把日誌按日誌定期的分多個檔案放呢。結果發現mysql有個更好的方法,可以透過時間引數獲取某個時間段的資料,例子如下:
mysqlbinlog   --start-datetime="2010-11-20 00:00:00"  --stop-datetime="2010-11-21 00:00:00" 

Reference:
Mysql5.5配置主從複製
http://ylw6006.blog.51cto.com/470441/888523

MYSQL啟動後報:ERROR! The server quit without updating PID file錯誤的問題解決
Reference:http://blog.csdn.net/faye0412/article/details/7038290


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26477398/viewspace-1625815/,如需轉載,請註明出處,否則將追究法律責任。

相關文章