{"id":757,"date":"2016-05-01T13:47:21","date_gmt":"2016-05-01T04:47:21","guid":{"rendered":"http:\/\/gomocool.net\/gomokulog\/?p=757"},"modified":"2016-05-01T13:47:21","modified_gmt":"2016-05-01T04:47:21","slug":"mysql%e3%81%a7%e3%83%ad%e3%83%bc%e3%83%86%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3%e3%83%90%e3%83%83%e3%82%af%e3%82%a2%e3%83%83%e3%83%97","status":"publish","type":"post","link":"https:\/\/gomokulog.gomocool.net\/?p=757","title":{"rendered":"MySQL\u3067\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u30d0\u30c3\u30af\u30a2\u30c3\u30d7"},"content":{"rendered":"<p>MySQL\u3067\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30c7\u30fc\u30bf\u3092\u3068\u3063\u3066\u3001\u53e4\u3044\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3057\u3066\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3055\u305b\u308b\u3002<\/p>\n<h2>mysqldump\u304c\u53ef\u80fd\u306a\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u6210\u3059\u308b\u3002<\/h2>\n<p>\u30e6\u30fc\u30b6\u30fc\u540d\u306f[backup]\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u306f[secret]\u3001\u5bfe\u8c61\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u540d\u3092[test]\u3068\u3059\u308b\u3002<\/p>\n<p>mysql\u306broot\u3067\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3001grant\u30b3\u30de\u30f3\u30c9\u3067\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u308b\u3002<\/p>\n<pre class=\"lang:mysql decode:true\">grant select, trigger, lock tables on *.* to backup@localhost;<\/pre>\n<p>\u4f5c\u3063\u305f\u30e6\u30fc\u30b6\u30fc\u306b\u30d1\u30b9\u30ef\u30fc\u30c9\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n<pre class=\"lang:mysql decode:true\">set password for backup@localhost=password('secret');<\/pre>\n<p>\u4e00\u5fdc\u78ba\u8a8d<\/p>\n<pre class=\"lang:mysql decode:true\"> select host, user from mysql.user;<\/pre>\n<p>\u4e00\u5ea6MySQL\u30b3\u30de\u30f3\u30c9\u304b\u3089\u3067\u3066\u3001mysqldump\u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3063\u3066\u307f\u3066test.dmp\u304c\u3067\u308c\u3070OK<\/p>\n<pre class=\"lang:sh decode:true\">mysqldump -u backup -psecret test &gt; test.dmp;<\/pre>\n<h2>\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u308b<\/h2>\n<p>\u6b21\u306b\u3001\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3092\u884c\u3046\u305f\u3081\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u308b\u3002<\/p>\n<pre class=\"lang:sh decode:true\">vim mysql-bk.sh<\/pre>\n<pre class=\"lang:sh decode:true\">#!\/bin\/bash\r\n\r\nbkpath='\/root\/dbbk'\r\n\r\nterm=7\r\n\r\nfilename=`date +%Y%m%d`\r\n\r\nmkdir -p $bkpath\r\n\r\nmysqldump -u backup -psecret test &gt; $bkpath\/$filename.dmp\r\n\r\nchmod 700 $bkpath\/$filename.dmp\r\n\r\noldfile=`date --date \"$term days ago\" +%Y%m%d`\r\nrm -f $dirpath\/$oldfile.dmp<\/pre>\n<p>\u6b21\u306b\u3001\u30d1\u30fc\u30df\u30c3\u30b7\u30e7\u30f3\u3092\u4f5c\u6210\u8005\u306e\u307f\u5b9f\u884c\u6a29\u9650\u304c\u3042\u308b\u3088\u3046\u306b\u8a2d\u5b9a<\/p>\n<pre class=\"lang:default decode:true \">chomod 700 mysql-bk.sh<\/pre>\n<p>\u8a66\u3057\u306b\u52d5\u304b\u3057\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"lang:sh decode:true \">.\/mysql-bk.sh<\/pre>\n<p>\u4efb\u610f\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u304c\u53d6\u308c\u3066\u3044\u308c\u3070OK\u3002<\/p>\n<h2>cron\u306b\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u8a2d\u5b9a<\/h2>\n<p>\u4f5c\u6210\u8005\u306ecron\u306b\u767b\u9332\u3059\u308b\u3002<\/p>\n<pre class=\"lang:sh decode:true\">crontab -e<\/pre>\n<pre class=\"lang:default decode:true\">0 4 * * * \/root\/mysql-bk.sh<\/pre>\n<p>\u6bce\u65e5\u3001\u5348\u524d4\u6642\u306b\u52d5\u304f\u3088\u3046\u306b\u8a2d\u5b9a\u3002<\/p>\n<h2>\u5225\u30b5\u30fc\u30d0\u30fc\u3078\u540c\u671f<\/h2>\n<p>\u3042\u3068\u306f\u3001\u3046\u307e\u304f\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u304c\u53d6\u308c\u3066\u3044\u308c\u3070\u3001\u5225\u30b5\u30fc\u30d0\u30fc\u3078rsync\u7b49\u3067\u540c\u671f\u3059\u308b\u3002<\/p>\n<p><a href=\"http:\/\/gomocool.net\/gomokulog\/?p=622\">rsync\u3068cron\u3067\u5b9a\u671f\u7684\u306b\u306b\u30c7\u30fc\u30bf\u3092\u540c\u671f\u3059\u308b<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL\u3067\u30d0\u30c3\u30af\u30a2\u30c3\u30d7\u30c7\u30fc\u30bf\u3092\u3068\u3063\u3066\u3001\u53e4\u3044\u30c7\u30fc\u30bf\u3092\u524a\u9664\u3057\u3066\u30ed\u30fc\u30c6\u30fc\u30b7\u30e7\u30f3\u3055\u305b\u308b\u3002 mysqldump\u304c\u53ef\u80fd\u306a\u30e6\u30fc\u30b6\u30fc\u3092\u4f5c\u6210\u3059\u308b\u3002 \u30e6\u30fc\u30b6\u30fc\u540d\u306f[backup]\u3001\u30d1\u30b9\u30ef\u30fc\u30c9\u306f[secret]\u3001\u5bfe\u8c61\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u540d\u3092[te&hellip;  <a href=\"https:\/\/gomokulog.gomocool.net\/?p=757\" class=\"more-link\">more <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-757","post","type-post","status-publish","format-standard","hentry","category-server"],"_links":{"self":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=757"}],"version-history":[{"count":3,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/757\/revisions"}],"predecessor-version":[{"id":760,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=\/wp\/v2\/posts\/757\/revisions\/760"}],"wp:attachment":[{"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gomokulog.gomocool.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}