{"id":274,"date":"2021-01-29T18:03:04","date_gmt":"2021-01-29T10:03:04","guid":{"rendered":"http:\/\/www.sttxx.com\/?p=274"},"modified":"2021-01-29T18:03:08","modified_gmt":"2021-01-29T10:03:08","slug":"linuxfuwuqimysqlzidongbeifen","status":"publish","type":"post","link":"http:\/\/www.sttxx.com\/index.php\/2021\/01\/29\/linuxfuwuqimysqlzidongbeifen\/","title":{"rendered":"Linux\u670d\u52a1\u5668mysql\u81ea\u52a8\u5907\u4efd"},"content":{"rendered":"\n<p>1\u3001\u73af\u5883<\/p>\n\n\n\n<ul><li>\u5907\u4efd\u8def\u5f84\uff1a\/xxxx\/<\/li><li>\u5907\u4efd\u811a\u672c\uff1a\/xxxx\/mysqlbak.sh<\/li><li>\u5907\u4efd\u65f6\u95f4\uff1a\u6bcf\u592923\uff1a59\u5907\u4efd<\/li><li>\u5907\u4efd\u8981\u6c42\uff1a\u6bd4\u5982\u5907\u4efd\u7684\u6570\u636e\u53ea\u4fdd\u75591\u5468<\/li><\/ul>\n\n\n\n<p>2\u3001\u4f7f\u7528<code>mysql_config_editor<\/code>\u6765\u8bbe\u7f6e\u52a0\u5bc6\u7684\u5bc6\u7801\u6587\u4ef6\uff0c\u5047\u8bbe\u7528\u6237\u540d\u662f\u201c db_user\u201d\u3002\u5728shell\u4e2d\u6267\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql_config_editor set --login-path=local --host=localhost --user=db_user --password\n<\/code><\/pre>\n\n\n\n<p>\u63d0\u793a\u8f93\u5165\u5bc6\u7801\uff0c\u8f93\u5165\u5bc6\u7801\u540e\uff0c\u767b\u9646MySQL\u670d\u52a1\u7684\u8ba4\u8bc1\u4fe1\u606f\u5c06\u52a0\u5bc6\u4fdd\u5b58\u5728.mylogin.cnf\u6587\u4ef6\uff08\u9ed8\u8ba4\u4f4d\u4e8e\u7528\u6237\u4e3b\u76ee\u5f55\uff09 \u3002\u4e4b\u540e\uff0cMySQL\u5ba2\u6237\u7aef\u5de5\u5177\u53ef\u901a\u8fc7\u8bfb\u53d6\u8be5\u52a0\u5bc6\u6587\u4ef6\u8fde\u63a5MySQL\uff0c\u907f\u514d\u91cd\u590d\u8f93\u5165\u767b\u5f55\u4fe1\u606f\uff0c\u907f\u514d\u654f\u611f\u4fe1\u606f\u66b4\u9732\u3002<\/p>\n\n\n\n<p><br>3\u3001mysqlbak.sh\u811a\u672c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n#\u6570\u636e\u5e93,\u5982\u6709\u591a\u4e2a\u5e93\u7528\u7a7a\u683c\u5206\u5f00\ndbname='xxxx'\n#\u5907\u4efd\u65f6\u95f4\nbacktime=`date +%Y%m%d`\n#\u5907\u4efd\u8f93\u51fa\u65e5\u5fd7\u8def\u5f84\nlogpath='\/xxxx\/xxxx'\n\necho \"################## ${backtime} #############################\"\necho \"\u5f00\u59cb\u5907\u4efd\"\n#\u65e5\u5fd7\u8bb0\u5f55\u5934\u90e8\necho \"\" &gt;&gt; ${logpath}\/log.log\necho \"-------------------------------------------------\" &gt;&gt; ${logpath}\/log.log\necho \"\u5907\u4efd\u65f6\u95f4\u4e3a${backtime},\u5907\u4efd\u6570\u636e\u5e93\u8868 ${dbname} \u5f00\u59cb\" &gt;&gt; ${logpath}\/log.log\n#\u6b63\u5f0f\u5907\u4efd\u6570\u636e\u5e93\n\/usr\/bin\/mysqldump --login-path=local ${dbname} &gt; ${logpath}\/${backtime}.sql 2&gt;&gt; ${logpath}\/log.log;\n#\u4e3a\u8282\u7ea6\u786c\u76d8\u7a7a\u95f4\uff0c\u5c06\u6570\u636e\u5e93\u538b\u7f29\ntar zcfP ${logpath}\/${dbname}${backtime}.tar.gz ${logpath}\/${backtime}.sql &gt; \/dev\/null\n#\u5220\u9664\u539f\u59cb\u6587\u4ef6\uff0c\u53ea\u7559\u538b\u7f29\u540e\u6587\u4ef6\nrm -rf ${backtime}.sql\n#\u5907\u4efd\u6210\u529f\u4ee5\u4e0b\u64cd\u4f5c\n#\u5220\u9664\u4e03\u5929\u524d\u5907\u4efd\uff0c\u4e5f\u5c31\u662f\u53ea\u4fdd\u5b587\u5929\u5185\u7684\u5907\u4efd\nfind -name \"*.tar.gz\" -type f -mtime +7 -exec rm -rf {} \\; &gt; \/dev\/null 2&gt;&amp;1\necho \"\u6570\u636e\u5e93\u8868 ${dbname} \u5907\u4efd\u6210\u529f!!\" &gt;&gt; ${logpath}\/log.log\necho \"\u5b8c\u6210\u5907\u4efd\"\necho \"################## ${backtime} #############################\"\n<\/code><\/pre>\n\n\n\n<p>4\u3001\u914d\u7f6e\u5b9a\u65f6\u4efb\u52a1\u6267\u884c\u811a\u672c<br><code>crontab -e<\/code>\u7f16\u8f91\u7528\u6237\u76ee\u524d\u7684crontab\uff0c<br>\u6dfb\u52a0<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>59 23 * * * \/xxxx\/mysqlbak.sh\n<\/code><\/pre>\n\n\n\n<p><code>crontab -l<\/code>\u8868\u793a\u5217\u51fa\u6240\u6709\u7684\u5b9a\u65f6\u4efb\u52a1<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux\u670d\u52a1\u5668mysql\u81ea\u52a8\u5907\u4efd<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[58,21],"tags":[69,59],"_links":{"self":[{"href":"http:\/\/www.sttxx.com\/index.php\/wp-json\/wp\/v2\/posts\/274"}],"collection":[{"href":"http:\/\/www.sttxx.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sttxx.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sttxx.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sttxx.com\/index.php\/wp-json\/wp\/v2\/comments?post=274"}],"version-history":[{"count":2,"href":"http:\/\/www.sttxx.com\/index.php\/wp-json\/wp\/v2\/posts\/274\/revisions"}],"predecessor-version":[{"id":276,"href":"http:\/\/www.sttxx.com\/index.php\/wp-json\/wp\/v2\/posts\/274\/revisions\/276"}],"wp:attachment":[{"href":"http:\/\/www.sttxx.com\/index.php\/wp-json\/wp\/v2\/media?parent=274"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sttxx.com\/index.php\/wp-json\/wp\/v2\/categories?post=274"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sttxx.com\/index.php\/wp-json\/wp\/v2\/tags?post=274"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}