{"id":1882,"date":"2012-06-15T08:42:00","date_gmt":"2012-06-15T12:42:00","guid":{"rendered":""},"modified":"2013-11-22T09:15:22","modified_gmt":"2013-11-22T01:15:22","slug":"mysql%e8%87%aa%e5%8a%a8%e5%a4%87%e4%bb%bd%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/1882.html","title":{"rendered":"MySql\u81ea\u52a8\u5907\u4efd\u811a\u672c"},"content":{"rendered":"<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncrontab -e\r\n0 11 * * * \/root\/mysql_backup.sh    #\u6bcf\u592911\u70b9\u6267\u884c\r\n\u683c\u5f0f\uff1a\u5206 \u5c0f\u65f6 \u5929 \u6708 \u661f\u671f\u51e0 \u811a\u672c\u6587\u4ef6\r\n<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/sh\r\n\r\nDBUser=root\r\n\r\nDBPass=test\r\n\r\nDBHost=`hostname -s`\r\n\r\n# make sure you already created the backup directory\r\n\r\nBackupPath=\/var\/bak\/mysql\r\n\r\n# the path of mysqld\r\nDBbinPath=\/usr\/opt\/local\/mysql-5.1.47\/bin\/mysqldump\r\n\r\n# error record log file\r\nErrorLog=${BackupPath}\/error.txt\r\n\r\nif ${DBbinPath} -u${DBUser} -p${DBPass} \u2013opt \u2013default-character-set=utf8 \u2013extended-insert=false \u2013triggers -R \u2013hex-blob \u2013all-databases \u2013flush-logs \u2013delete-master\r\n-logs \u2013delete-master-logs &gt; ${BackupPath}&quot;\/&quot;${DBHost}&quot;-&quot;`date &quot;+%Y-%m-%d&quot;`&quot;.sql&quot; ;\r\nthen\r\n     find ${BackupPath}&quot;\/&quot; -mtime +6 -exec rm {} \\;\r\nelse\r\n     echo &quot;\u2014\u2014\u2014\u2014\u2014\u2014-&quot; &gt;&gt; ${ErrorLog}\r\n     echo `date &quot;+%Y-%m-%d&quot;` &gt;&gt; ${ErrorLog}\r\n     echo &quot;\u2014\u2014\u2014\u2014\u2014\u2014-\\n&quot; &gt;&gt; ${ErrorLog}\r\n\r\n     exit\r\nfi\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>crontab -e 0 11 * * * \/root\/mysql_backup.sh #\u6bcf\u592911\u70b9\u6267\u884c \u683c\u5f0f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1882","post","type-post","status-publish","format-standard","hentry","category-skill"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1882","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=1882"}],"version-history":[{"count":2,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1882\/revisions"}],"predecessor-version":[{"id":5030,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1882\/revisions\/5030"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=1882"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=1882"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=1882"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}