{"id":8254,"date":"2021-09-06T12:09:50","date_gmt":"2021-09-06T04:09:50","guid":{"rendered":"https:\/\/blog.hoyo.idv.tw\/?p=8254"},"modified":"2023-02-07T14:31:05","modified_gmt":"2023-02-07T06:31:05","slug":"mysql-%e6%96%b7%e9%9b%bb%e8%b3%87%e6%96%99%e5%ba%ab%e7%84%a1%e6%b3%95%e5%95%9f%e5%8b%95%e4%bf%ae%e5%be%a9%e9%81%8e%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/blog.hoyo.idv.tw\/?p=8254","title":{"rendered":"MariaDB - \u65b7\u96fb\u8cc7\u6599\u5eab\u7121\u6cd5\u555f\u52d5\u4fee\u5fa9\u904e\u7a0b"},"content":{"rendered":"<p>--<\/p>\n<p>MariaDB \u7248\u672c 10.3.25 \u5176\u4ed6\u7248\u672c\u76f8\u95dc\u6307\u4ee4\u3001\u64cd\u4f5c\u4e0d\u4fdd\u8b49\u6210\u529f<\/p>\n<p>--<\/p>\n<p>\u7576\u9047\u5230 MariaDB \u8cc7\u6599\u5eab\u6bc0\u640d\u6642\uff0cHoyo \u4f7f\u7528\u4e86\u4ee5\u4e0b\u6b65\u9a5f\u6062\u5fa9\u904b\u4f5c\uff0c\u6b64\u65b9\u6cd5\u4f7f\u7528\u7684\u662f\u91cd\u5efa mysql \u8cc7\u6599\u5eab\u7684\u65b9\u5f0f\uff0c\u4f7f\u7528\u8005\u7684\u8cc7\u6599\u5eab\u5fc5\u9808\u6709\u5099\u4efd\uff0c\u7b49\u91cd\u5efa\u5b8c\u6210\u4e4b\u5f8c\u518d\u6062\u5fa9\u4f7f\u7528\u8005\u5e33\u865f\u4ee5\u53ca\u532f\u5165\u8cc7\u6599\u5eab\u5099\u4efd<\/p>\n<pre class=\"lang:default decode:true \"># mv \/var\/lib\/mysql \/var\/lib\/mysql0\r\n# mysql_install_db\r\n# systemctl restart mysql\r\n# mysql_secure_installation\r\n# mysql -u root -p\r\n\r\nCREATE USER 'user'@'%' IDENTIFIED BY 'password';\r\nGRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;\r\nFLUSH PRIVILEGES;\r\n\r\n# mysql -u username -p database_name &lt; file.sql<\/pre>\n<p>\u9019\u500b\u65b9\u6cd5\u53ef\u884c\u662f\u53ef\u884c\uff0c\u4e0d\u904e\u00a0mysql_secure_installation \u9019\u500b\u6307\u4ee4\u9700\u8981\u4eba\u5de5\u5e72\u6d89\uff0c\u6240\u4ee5\u8981\u5c07\u6d41\u7a0b\u81ea\u52d5\u5316\u9084\u9700\u8981\u8abf\u6574<\/p>\n<p>\u4ee5\u4e0b\u81ea\u52d5\u5316\u53c3\u8003\u4e86 \/usr\/bin\/mysql_secure_installation \u5167\u4f5c\u6cd5<\/p>\n<p>--<\/p>\n<h2>\u6307\u5b9a mysql \u57f7\u884c\u6642\u5e33\u865f\u3001\u5bc6\u78bc<\/h2>\n<p>.my.cnf<\/p>\n<pre class=\"lang:default decode:true\">[mysql]\r\nuser=root\r\npassword='password'<\/pre>\n<p>--<\/p>\n<h2>\u8cc7\u6599\u5eab\u6574\u7406<\/h2>\n<p>\u522a\u9664\u533f\u540d\u5e33\u865f\u4ee5\u53ca test \u8cc7\u6599\u5eab\uff0c\u63a5\u4e0b\u4f86\u5c31\u662f\u81ea\u5df1\u7684\u4f7f\u7528\u8005\u5e33\u865f\u4ee5\u53ca\u8cc7\u6599\u5eab<\/p>\n<p>fix.sql<\/p>\n<pre class=\"lang:default decode:true\">DELETE FROM mysql.user WHERE User='';\r\nDELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');\r\nDELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%';\r\nDROP DATABASE IF EXISTS test;\r\nFLUSH PRIVILEGES;\r\n\r\nCREATE DATABASE `table` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci;\r\nCREATE USER 'user'@'%' IDENTIFIED BY 'password';\r\nGRANT ALL PRIVILEGES ON *.* TO 'DAE'@'%' WITH GRANT OPTION;\r\nFLUSH PRIVILEGES;\r\n<\/pre>\n<p>--<\/p>\n<h2>\u91cd\u5efa\u53ca\u532f\u5165<\/h2>\n<p>fix.sh<\/p>\n<pre class=\"lang:default decode:true\"># chmod +x fix.sh<\/pre>\n<ol>\n<li>\u5c07\u8cc7\u6599\u5eab\u505c\u6b62\u670d\u52d9<\/li>\n<li>\u522a\u9664\u6574\u500b\u8cc7\u6599\u5eab\u76ee\u9304<\/li>\n<li>\u57f7\u884c\u00a0mysql_install_db \u4e0d\u80fd\u52a0\u53c3\u6578\uff0cHoyo \u6e2c\u8a66\u7684\u7d50\u679c\u662f\u589e\u52a0\u53c3\u6578\u5c31\u7121\u6cd5\u6b63\u5e38\u57f7\u884c<\/li>\n<li>\u555f\u52d5\u8cc7\u6599\u5eab\u670d\u52d9<\/li>\n<li>\u4fee\u6539 root \u5bc6\u78bc<\/li>\n<li>\u5c07\u525b\u525b\u7de8\u8f2f\u7684 fix.sql \u532f\u5165<\/li>\n<li>\u89e3\u58d3\u7e2e\u539f\u5148\u5099\u4efd\u8cc7\u6599\u5eab<\/li>\n<li>\u5c07\u5099\u4efd\u8cc7\u6599\u5eab\u532f\u5165<\/li>\n<\/ol>\n<pre class=\"lang:default decode:true\">#!\/usr\/bin\/env bash\r\nsystemctl stop mysql\r\nrm -r \/var\/lib\/mysql\r\nmysql_install_db\r\nsystemctl start mysql\r\nmysqladmin -u root password 'password'\r\nmysql --defaults-file=\/opt\/Server\/WWW\/.my.cnf &lt; \/opt\/Server\/WWW\/fix.sql\r\ntar zxf \/backup\/db_backup.tgz -C \/\r\nmysql --defaults-file=\/opt\/Server\/WWW\/.my.cnf table &lt; \/backup\/db_backup.sql\r\n<\/pre>\n<p>--<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"8254\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;2,123&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>-- MariaDB \u7248\u672c 1...<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p class=\"pvc_stats all \" data-element-id=\"8254\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> &nbsp;2,123&nbsp;total views<\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[258],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/8254"}],"collection":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8254"}],"version-history":[{"count":9,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/8254\/revisions"}],"predecessor-version":[{"id":8711,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/8254\/revisions\/8711"}],"wp:attachment":[{"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hoyo.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}