查看: 41|回复: 0

[Mysql数据库] mysql主从复制

发表于 2018-4-28 08:00:00
  1. [root@db02 data]# mysql -S /data/3306/mysql.sock
  2. 查看变量:
  3. mysql> show variables like 'log_bin%';
  4. +---------------------------------+----------------------------+
  5. | Variable_name | Value |
  6. +---------------------------------+----------------------------+
  7. | log_bin | ON |
  8. | log_bin_basename | /data/3306/mysql-bin |
  9. | log_bin_index | /data/3306/mysql-bin.index |
  10. | log_bin_trust_function_creators | OFF |
  11. | log_bin_use_v1_row_events | OFF |
  12. +---------------------------------+----------------------------+
  13. 5 rows in set (0.00 sec)
  14. 2、建账号授权【主库】
  15. grant replication slave on *.* to 'rep'@'172.16.1.%' identified by 'oldboy123';
  16. flush privileges;
  17. 3、锁表导出数据
  18. mysql> flush table with read lock;
  19. Query OK, 0 rows affected (0.00 sec)
  20. 查看位置:
  21. mysql> show master status;
  22. +-------------------+----------+--------------+------------------+-------------------+
  23. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
  24. +-------------------+----------+--------------+------------------+-------------------+
  25. | oldboy-bin.000001 | 405 | | | |
  26. +-------------------+----------+--------------+------------------+-------------------+
  27. 1 row in set (0.00 sec)
复制代码

  


查看变量:
mysql> show variables like 'log_bin%';
+---------------------------------+----------------------------+
| Variable_name | Value |
+---------------------------------+----------------------------+
| log_bin | ON |
| log_bin_basename | /data/3306/mysql-bin |
| log_bin_index | /data/3306/mysql-bin.index |
| log_bin_trust_function_creators | OFF |
| log_bin_use_v1_row_events | OFF |
+---------------------------------+----------------------------+
5 rows in set (0.00 sec)


2、建账号授权【主库】
grant replication slave on *.* to 'rep'@'172.16.1.%' identified by 'oldboy123';
flush privileges;


3、锁表导出数据
mysql> flush table with read lock;
Query OK, 0 rows affected (0.00 sec)

查看位置:
mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| oldboy-bin.000001 | 405 | | | |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)




上一篇:MySQL(一)
下一篇:MySQL(三)
回复

使用道具 举报