{"id":127462,"date":"2018-11-20T09:42:11","date_gmt":"2018-11-20T01:42:11","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=127462"},"modified":"2018-11-12T09:44:25","modified_gmt":"2018-11-12T01:44:25","slug":"mysql-backup-database","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/mysql-backup-database.html","title":{"rendered":"mysql\u5b9e\u73b0\u4e3b\u4ece\u590d\u5236"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | Mysql\u7684 Replication \u662f\u4e00\u4e2a\u5f02\u6b65\u7684\u590d\u5236\u8fc7\u7a0b\uff08mysql5.1.7\u4ee5\u4e0a\u7248\u672c\u5206\u4e3a\u5f02\u6b65\u590d\u5236\u548c\u534a\u540c\u6b65\u4e24\u79cd\u6a21\u5f0f\uff09\uff0c\u4ece\u4e00\u4e2a Mysql instace(\u6211\u4eec\u79f0\u4e4b\u4e3a Master)\u590d\u5236\u5230\u53e6\u4e00\u4e2a Mysql instance(\u6211\u4eec\u79f0\u4e4b Slave)\u3002\u5728 Master \u4e0e Slave \u4e4b\u95f4\u7684\u5b9e\u73b0\u6574\u4e2a\u590d\u5236\u8fc7\u7a0b\u4e3b\u8981\u7531\u4e09\u4e2a\u7ebf\u7a0b\u6765\u5b8c\u6210\uff0c\u5176\u4e2d\u4e24\u4e2a\u7ebf\u7a0b(Sql\u7ebf\u7a0b\u548cIO\u7ebf\u7a0b)\u5728 Slave \u7aef\uff0c\u53e6\u5916\u4e00\u4e2a\u7ebf\u7a0b(IO\u7ebf\u7a0b)\u5728 Master \u7aef\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n <\/p>\n 1.1. mysql\u4e3b\u4ece\u7684\u539f\u7406<\/strong><\/div>\n 1.1.1. Replication \u7ebf\u7a0b<\/strong><\/span><\/div>\n Mysql\u7684 Replication \u662f\u4e00\u4e2a\u5f02\u6b65\u7684\u590d\u5236\u8fc7\u7a0b\uff08mysql5.1.7\u4ee5\u4e0a\u7248\u672c\u5206\u4e3a\u5f02\u6b65\u590d\u5236\u548c\u534a\u540c\u6b65\u4e24\u79cd\u6a21\u5f0f\uff09\uff0c\u4ece\u4e00\u4e2a Mysql instace(\u6211\u4eec\u79f0\u4e4b\u4e3a Master)\u590d\u5236\u5230\u53e6\u4e00\u4e2a Mysql instance(\u6211\u4eec\u79f0\u4e4b Slave)\u3002\u5728 Master \u4e0e Slave \u4e4b\u95f4\u7684\u5b9e\u73b0\u6574\u4e2a\u590d\u5236\u8fc7\u7a0b\u4e3b\u8981\u7531\u4e09\u4e2a\u7ebf\u7a0b\u6765\u5b8c\u6210\uff0c\u5176\u4e2d\u4e24\u4e2a\u7ebf\u7a0b(Sql\u7ebf\u7a0b\u548cIO\u7ebf\u7a0b)\u5728 Slave \u7aef\uff0c\u53e6\u5916\u4e00\u4e2a\u7ebf\u7a0b(IO\u7ebf\u7a0b)\u5728 Master \u7aef\u3002<\/p>\n \u8981\u5b9e\u73b0 MySQL \u7684 Replication \uff0c\u9996\u5148\u5fc5\u987b\u6253\u5f00 Master \u7aef\u7684Binary Log(mysql-bin.xxxxxx)\u529f\u80fd\uff0c\u5426\u5219\u65e0\u6cd5\u5b9e\u73b0\u3002\u56e0\u4e3a\u6574\u4e2a\u590d\u5236\u8fc7\u7a0b\u5b9e\u9645\u4e0a\u5c31\u662fSlave\u4eceMaster\u7aef\u83b7\u53d6\u8be5\u65e5\u5fd7\u7136\u540e\u518d\u5728\u81ea\u5df1\u8eab\u4e0a\u5b8c\u5168 \u987a\u5e8f\u7684\u6267\u884c\u65e5\u5fd7\u4e2d\u6240\u8bb0\u5f55\u7684\u5404\u79cd\u64cd\u4f5c\u3002\u6253\u5f00 MySQL \u7684 Binary Log \u53ef\u4ee5\u901a\u8fc7\u5728\u542f\u52a8 MySQL Server \u7684\u8fc7\u7a0b\u4e2d\u4f7f\u7528 \u201c\u2014log-bin\u201d \u53c2\u6570\u9009\u9879\uff0c\u6216\u8005\u5728 my.cnf \u914d\u7f6e\u6587\u4ef6\u4e2d\u7684 mysqld \u53c2\u6570\u7ec4([mysqld]\u6807\u8bc6\u540e\u7684\u53c2\u6570\u90e8\u5206)\u589e\u52a0 \u201clog-bin\u201d \u53c2\u6570\u9879\u3002<\/p>\n 1.1.2. MySQL \u590d\u5236\u7684\u57fa\u672c\u8fc7\u7a0b\uff1a<\/strong><\/span><\/div>\n 1.Slave \u4e0a\u9762\u7684IO\u7ebf\u7a0b\u8fde\u63a5\u4e0a Master\uff0c\u5e76\u8bf7\u6c42\u4ece\u6307\u5b9a\u65e5\u5fd7\u6587\u4ef6\u7684\u6307\u5b9a\u4f4d\u7f6e(\u6216\u8005\u4ece\u6700\u5f00\u59cb\u7684\u65e5\u5fd7)\u4e4b\u540e\u7684\u65e5\u5fd7\u5185\u5bb9\uff1b<\/p>\n Master \u63a5\u6536\u5230\u6765\u81ea Slave \u7684 IO \u7ebf\u7a0b\u7684\u8bf7\u6c42\u540e\uff0c\u901a\u8fc7\u8d1f\u8d23\u590d\u5236\u7684 IO \u7ebf\u7a0b\u6839\u636e\u8bf7\u6c42\u4fe1\u606f\u8bfb\u53d6\u6307\u5b9a\u65e5\u5fd7\u6307\u5b9a\u4f4d\u7f6e\u4e4b\u540e\u7684\u65e5\u5fd7\u4fe1\u606f\uff0c\u8fd4\u56de\u7ed9 Slave \u7aef\u7684 IO \u7ebf\u7a0b\u3002\u8fd4\u56de\u4fe1\u606f\u4e2d\u9664\u4e86\u65e5\u5fd7\u6240\u5305\u542b\u7684\u4fe1\u606f\u4e4b\u5916\uff0c\u8fd8\u5305\u62ec\u672c\u6b21\u8fd4\u56de\u7684\u4fe1\u606f\u5728 Master \u7aef\u7684 Binary Log \u6587\u4ef6\u7684\u540d\u79f0\u4ee5\u53ca\u5728 Binary Log \u4e2d\u7684\u4f4d\u7f6e\uff1b<\/p>\n Slave \u7684 IO \u7ebf\u7a0b\u63a5\u6536\u5230\u4fe1\u606f\u540e\uff0c\u5c06\u63a5\u6536\u5230\u7684\u65e5\u5fd7\u5185\u5bb9\u4f9d\u6b21\u5199\u5165\u5230 Slave \u7aef\u7684Relay Log\u6587\u4ef6(mysql-relay-bin.xxxxxx)\u7684\u6700\u672b\u7aef\uff0c\u5e76\u5c06\u8bfb\u53d6\u5230\u7684Master\u7aef\u7684bin-log\u7684\u6587\u4ef6\u540d\u548c\u4f4d\u7f6e\u8bb0\u5f55\u5230master- info\u6587\u4ef6\u4e2d\uff0c\u4ee5\u4fbf\u5728\u4e0b\u4e00\u6b21\u8bfb\u53d6\u7684\u65f6\u5019\u80fd\u591f\u6e05\u695a\u7684\u9ad8\u901fMaster\u201c\u6211\u9700\u8981\u4ece\u67d0\u4e2abin-log\u7684\u54ea\u4e2a\u4f4d\u7f6e\u5f00\u59cb\u5f80\u540e\u7684\u65e5\u5fd7\u5185\u5bb9\uff0c\u8bf7\u53d1\u7ed9\u6211\u201d<\/p>\n Slave \u7684 SQL \u7ebf\u7a0b\u68c0\u6d4b\u5230 Relay Log \u4e2d\u65b0\u589e\u52a0\u4e86\u5185\u5bb9\u540e\uff0c\u4f1a\u9a6c\u4e0a\u89e3\u6790\u8be5 Log \u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u6210\u4e3a\u5728 Master \u7aef\u771f\u5b9e\u6267\u884c\u65f6\u5019\u7684\u90a3\u4e9b\u53ef\u6267\u884c\u7684 Query \u8bed\u53e5\uff0c\u5e76\u5728\u81ea\u8eab\u6267\u884c\u8fd9\u4e9b Query\u3002\u8fd9\u6837\uff0c\u5b9e\u9645\u4e0a\u5c31\u662f\u5728 Master \u7aef\u548c Slave \u7aef\u6267\u884c\u4e86\u540c\u6837\u7684 Query\uff0c\u6240\u4ee5\u4e24\u7aef\u7684\u6570\u636e\u662f\u5b8c\u5168\u4e00\u6837\u7684\u3002<\/p>\n 1.2. db01<\/strong><\/div>\n 1.2.1. \u5728\u4e3b\u5e93\u4e0a\u5f00\u542f\u7684binlog\u65e5\u5fd7<\/strong><\/span><\/div>\n [root@db01 ~]# cat \/etc\/my.cnf\r\n[mysqld]\r\nlog-bin\r\nserver-id=160<\/pre>\n |