mysql5.5 Replication 主从同步

mysql5.5 Replication 主从同步


------------------[主]------------------
[mysqld]
server-id=1
log-bin=mysql-bin
binlog-do-db=testdb

mysql>create user [email protected];
mysql>grant replication slave on *.* to [email protected] identified by '123456';

mysql>flush tables with read lock;
mysqldump testdb -uroot  -pklasdjfa --opt | mysql testdb -uroot -pklasdjfa -h 192.168.1.144
mysql>unlock tables;


重启



------------------[存]------------------
[mysqld]
server-id=2
log-bin=mysql-bin
replicate-do-db=testdb

重启

mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000001 |      107 |              |                  |
+------------------+----------+--------------+------------------+

mysql> slave stop;

mysql> change master to master_host='192.168.1.145',
    master_user='repl_user',
    master_password='123456',
    master_log_file='mysql-bin.000001',
    master_log_pos=107;

mysql> slave start;

mysql> show slave status\G

你可能感兴趣的:(Replication)