[{"data":1,"prerenderedAt":452},["ShallowReactive",2],{"post-\u002Fblog\u002F2020-05-12-mysql-binlog":3,"surround-\u002Fblog\u002F2020-05-12-mysql-binlog":445},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"tags":11,"cover":16,"source":17,"body":18,"_type":439,"_id":440,"_source":441,"_file":442,"_stem":443,"_extension":444},"\u002Fblog\u002F2020-05-12-mysql-binlog","blog",false,"","MySQL 开启 binlog","MySQL 5.7 中开启和配置 binlog 的完整教程，包括 binlog 概念、配置步骤、验证方法及常用查询命令。","2020-05-12",[12,13,14,15],"简书","历史归档","MySQL","binlog","https:\u002F\u002Fupload-images.jianshu.io\u002Fupload_images\u002F16281566-0899fc5e6f40a67a.png","https:\u002F\u002Fwww.jianshu.com\u002Fp\u002Ffd56514e3a0c",{"type":19,"children":20,"toc":434},"root",[21,29,35,40,66,71,81,133,141,167,183,218,226,242,249,265,296,303,317,331,338,347,371,378,387,416,423,428],{"type":22,"tag":23,"props":24,"children":26},"element","h2",{"id":25},"前言",[27],{"type":28,"value":25},"text",{"type":22,"tag":30,"props":31,"children":32},"p",{},[33],{"type":28,"value":34},"本文章用到的 mysql 版本为 5.7",{"type":22,"tag":23,"props":36,"children":38},{"id":37},"介绍",[39],{"type":28,"value":37},{"type":22,"tag":30,"props":41,"children":42},{},[43,49,51,57,59,64],{"type":22,"tag":44,"props":45,"children":47},"code",{"className":46},[],[48],{"type":28,"value":15},{"type":28,"value":50}," 就是 ",{"type":22,"tag":44,"props":52,"children":54},{"className":53},[],[55],{"type":28,"value":56},"binary log",{"type":28,"value":58}," ，二进制日志文件，这个文件记录了mysql所有的dml操作。通过 ",{"type":22,"tag":44,"props":60,"children":62},{"className":61},[],[63],{"type":28,"value":15},{"type":28,"value":65}," 日志我们可以做数据恢复，做主住复制和主从复制等等。对于开发者可能对`binlog 并不怎么关注，但是对于运维或者架构人员来讲是非常重要的。",{"type":22,"tag":23,"props":67,"children":69},{"id":68},"配置",[70],{"type":28,"value":68},{"type":22,"tag":72,"props":73,"children":74},"ol",{},[75],{"type":22,"tag":76,"props":77,"children":78},"li",{},[79],{"type":28,"value":80},"在my.inf主配置文件中直接添加三行",{"type":22,"tag":82,"props":83,"children":87},"pre",{"className":84,"code":85,"language":86,"meta":7,"style":7},"language-shell shiki shiki-themes github-light github-dark","log-bin=mysql-bin\nserver-id=1\n","shell",[88],{"type":22,"tag":44,"props":89,"children":90},{"__ignoreMap":7},[91,115],{"type":22,"tag":92,"props":93,"children":96},"span",{"class":94,"line":95},"line",1,[97,103,109],{"type":22,"tag":92,"props":98,"children":100},{"style":99},"--shiki-default:#24292E;--shiki-dark:#E1E4E8",[101],{"type":28,"value":102},"log-bin",{"type":22,"tag":92,"props":104,"children":106},{"style":105},"--shiki-default:#D73A49;--shiki-dark:#F97583",[107],{"type":28,"value":108},"=",{"type":22,"tag":92,"props":110,"children":112},{"style":111},"--shiki-default:#032F62;--shiki-dark:#9ECBFF",[113],{"type":28,"value":114},"mysql-bin\n",{"type":22,"tag":92,"props":116,"children":118},{"class":94,"line":117},2,[119,124,128],{"type":22,"tag":92,"props":120,"children":121},{"style":99},[122],{"type":28,"value":123},"server-id",{"type":22,"tag":92,"props":125,"children":126},{"style":105},[127],{"type":28,"value":108},{"type":22,"tag":92,"props":129,"children":130},{"style":111},[131],{"type":28,"value":132},"1\n",{"type":22,"tag":72,"props":134,"children":135},{"start":117},[136],{"type":22,"tag":76,"props":137,"children":138},{},[139],{"type":28,"value":140},"重启 MySQL",{"type":22,"tag":82,"props":142,"children":144},{"className":84,"code":143,"language":86,"meta":7,"style":7},"systemctl restart mysqld\n",[145],{"type":22,"tag":44,"props":146,"children":147},{"__ignoreMap":7},[148],{"type":22,"tag":92,"props":149,"children":150},{"class":94,"line":95},[151,157,162],{"type":22,"tag":92,"props":152,"children":154},{"style":153},"--shiki-default:#6F42C1;--shiki-dark:#B392F0",[155],{"type":28,"value":156},"systemctl",{"type":22,"tag":92,"props":158,"children":159},{"style":111},[160],{"type":28,"value":161}," restart",{"type":22,"tag":92,"props":163,"children":164},{"style":111},[165],{"type":28,"value":166}," mysqld\n",{"type":22,"tag":72,"props":168,"children":170},{"start":169},3,[171],{"type":22,"tag":76,"props":172,"children":173},{},[174,176,181],{"type":28,"value":175},"查看 ",{"type":22,"tag":44,"props":177,"children":179},{"className":178},[],[180],{"type":28,"value":15},{"type":28,"value":182}," 开启状态",{"type":22,"tag":82,"props":184,"children":186},{"className":84,"code":185,"language":86,"meta":7,"style":7},"show variables like '%log_bin%';\n",[187],{"type":22,"tag":44,"props":188,"children":189},{"__ignoreMap":7},[190],{"type":22,"tag":92,"props":191,"children":192},{"class":94,"line":95},[193,198,203,208,213],{"type":22,"tag":92,"props":194,"children":195},{"style":153},[196],{"type":28,"value":197},"show",{"type":22,"tag":92,"props":199,"children":200},{"style":111},[201],{"type":28,"value":202}," variables",{"type":22,"tag":92,"props":204,"children":205},{"style":111},[206],{"type":28,"value":207}," like",{"type":22,"tag":92,"props":209,"children":210},{"style":111},[211],{"type":28,"value":212}," '%log_bin%'",{"type":22,"tag":92,"props":214,"children":215},{"style":99},[216],{"type":28,"value":217},";\n",{"type":22,"tag":30,"props":219,"children":220},{},[221],{"type":22,"tag":222,"props":223,"children":225},"img",{"alt":7,"src":224},"https:\u002F\u002Fupload-images.jianshu.io\u002Fupload_images\u002F16281566-0899fc5e6f40a67a.png?imageMogr2\u002Fauto-orient\u002Fstrip%7CimageView2\u002F2\u002Fw\u002F986\u002Fformat\u002Fwebp",[],{"type":22,"tag":72,"props":227,"children":229},{"start":228},4,[230],{"type":22,"tag":76,"props":231,"children":232},{},[233,234,240],{"type":28,"value":175},{"type":22,"tag":44,"props":235,"children":237},{"className":236},[],[238],{"type":28,"value":239},"\u002Fvar\u002Flib\u002Fmysql",{"type":28,"value":241}," 目录",{"type":22,"tag":30,"props":243,"children":244},{},[245],{"type":22,"tag":222,"props":246,"children":248},{"alt":7,"src":247},"https:\u002F\u002Fupload-images.jianshu.io\u002Fupload_images\u002F16281566-34937b22ecd97b13.png?imageMogr2\u002Fauto-orient\u002Fstrip%7CimageView2\u002F2\u002Fw\u002F1092\u002Fformat\u002Fwebp",[],{"type":22,"tag":72,"props":250,"children":252},{"start":251},5,[253],{"type":22,"tag":76,"props":254,"children":255},{},[256,258,263],{"type":28,"value":257},"查看当前正在写入的 ",{"type":22,"tag":44,"props":259,"children":261},{"className":260},[],[262],{"type":28,"value":15},{"type":28,"value":264}," 文件",{"type":22,"tag":82,"props":266,"children":270},{"className":267,"code":268,"language":269,"meta":7,"style":7},"language-sql shiki shiki-themes github-light github-dark","show master status;\n","sql",[271],{"type":22,"tag":44,"props":272,"children":273},{"__ignoreMap":7},[274],{"type":22,"tag":92,"props":275,"children":276},{"class":94,"line":95},[277,282,287,292],{"type":22,"tag":92,"props":278,"children":279},{"style":99},[280],{"type":28,"value":281},"show ",{"type":22,"tag":92,"props":283,"children":284},{"style":105},[285],{"type":28,"value":286},"master",{"type":22,"tag":92,"props":288,"children":289},{"style":105},[290],{"type":28,"value":291}," status",{"type":22,"tag":92,"props":293,"children":294},{"style":99},[295],{"type":28,"value":217},{"type":22,"tag":30,"props":297,"children":298},{},[299],{"type":22,"tag":222,"props":300,"children":302},{"alt":7,"src":301},"https:\u002F\u002Fupload-images.jianshu.io\u002Fupload_images\u002F16281566-54e02b4a25f3e040.png?imageMogr2\u002Fauto-orient\u002Fstrip%7CimageView2\u002F2\u002Fw\u002F964\u002Fformat\u002Fwebp",[],{"type":22,"tag":72,"props":304,"children":306},{"start":305},6,[307],{"type":22,"tag":76,"props":308,"children":309},{},[310,311],{"type":28,"value":175},{"type":22,"tag":44,"props":312,"children":314},{"className":313},[],[315],{"type":28,"value":316},"binlog events",{"type":22,"tag":82,"props":318,"children":320},{"className":267,"code":319,"language":269,"meta":7,"style":7},"show binlog events;\n",[321],{"type":22,"tag":44,"props":322,"children":323},{"__ignoreMap":7},[324],{"type":22,"tag":92,"props":325,"children":326},{"class":94,"line":95},[327],{"type":22,"tag":92,"props":328,"children":329},{"style":99},[330],{"type":28,"value":319},{"type":22,"tag":30,"props":332,"children":333},{},[334],{"type":22,"tag":222,"props":335,"children":337},{"alt":7,"src":336},"https:\u002F\u002Fupload-images.jianshu.io\u002Fupload_images\u002F16281566-eb7d716e345c90ca.png?imageMogr2\u002Fauto-orient\u002Fstrip%7CimageView2\u002F2\u002Fw\u002F1079\u002Fformat\u002Fwebp",[],{"type":22,"tag":72,"props":339,"children":341},{"start":340},7,[342],{"type":22,"tag":76,"props":343,"children":344},{},[345],{"type":28,"value":346},"查看指定的文件",{"type":22,"tag":82,"props":348,"children":350},{"className":267,"code":349,"language":269,"meta":7,"style":7},"show binary logs;\n",[351],{"type":22,"tag":44,"props":352,"children":353},{"__ignoreMap":7},[354],{"type":22,"tag":92,"props":355,"children":356},{"class":94,"line":95},[357,361,366],{"type":22,"tag":92,"props":358,"children":359},{"style":99},[360],{"type":28,"value":281},{"type":22,"tag":92,"props":362,"children":363},{"style":105},[364],{"type":28,"value":365},"binary",{"type":22,"tag":92,"props":367,"children":368},{"style":99},[369],{"type":28,"value":370}," logs;\n",{"type":22,"tag":30,"props":372,"children":373},{},[374],{"type":22,"tag":222,"props":375,"children":377},{"alt":7,"src":376},"https:\u002F\u002Fupload-images.jianshu.io\u002Fupload_images\u002F16281566-180ed6ae2aaa64c0.png?imageMogr2\u002Fauto-orient\u002Fstrip%7CimageView2\u002F2\u002Fw\u002F1031\u002Fformat\u002Fwebp",[],{"type":22,"tag":72,"props":379,"children":381},{"start":380},8,[382],{"type":22,"tag":76,"props":383,"children":384},{},[385],{"type":28,"value":386},"查看binlog相关参数",{"type":22,"tag":82,"props":388,"children":390},{"className":267,"code":389,"language":269,"meta":7,"style":7},"show variables like \"%binlog%\";\n",[391],{"type":22,"tag":44,"props":392,"children":393},{"__ignoreMap":7},[394],{"type":22,"tag":92,"props":395,"children":396},{"class":94,"line":95},[397,402,407,412],{"type":22,"tag":92,"props":398,"children":399},{"style":99},[400],{"type":28,"value":401},"show variables ",{"type":22,"tag":92,"props":403,"children":404},{"style":105},[405],{"type":28,"value":406},"like",{"type":22,"tag":92,"props":408,"children":409},{"style":111},[410],{"type":28,"value":411}," \"%binlog%\"",{"type":22,"tag":92,"props":413,"children":414},{"style":99},[415],{"type":28,"value":217},{"type":22,"tag":30,"props":417,"children":418},{},[419],{"type":22,"tag":222,"props":420,"children":422},{"alt":7,"src":421},"https:\u002F\u002Fupload-images.jianshu.io\u002Fupload_images\u002F16281566-873cceb50e1ead5f.png?imageMogr2\u002Fauto-orient\u002Fstrip%7CimageView2\u002F2\u002Fw\u002F1064\u002Fformat\u002Fwebp",[],{"type":22,"tag":30,"props":424,"children":425},{},[426],{"type":28,"value":427},"标红的都是我目前知道的，比较重要的参数。",{"type":22,"tag":429,"props":430,"children":431},"style",{},[432],{"type":28,"value":433},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":7,"searchDepth":169,"depth":169,"links":435},[436,437,438],{"id":25,"depth":117,"text":25},{"id":37,"depth":117,"text":37},{"id":68,"depth":117,"text":68},"markdown","content:blog:2020-05-12-mysql-binlog.md","content","blog\u002F2020-05-12-mysql-binlog.md","blog\u002F2020-05-12-mysql-binlog","md",[446,449],{"_path":447,"title":448},"\u002Fblog\u002F2020-05-12-centos-mysql80","Centos 7.3 安装 MySQL 8.0",{"_path":450,"title":451},"\u002Fblog\u002F2020-05-10-leetcode-vscode","力扣(LeetCode)刷题神器之Vs Code",1796523532994]