{"id":3185,"date":"2021-04-29T22:06:39","date_gmt":"2021-04-29T14:06:39","guid":{"rendered":"https:\/\/learn-house.idv.tw\/?p=3185"},"modified":"2021-04-30T22:56:56","modified_gmt":"2021-04-30T14:56:56","slug":"ubuntu-20-04%e8%a8%ad%e5%ae%9adatadir%e6%94%b9%e8%ae%8amysql%e8%b3%87%e6%96%99%e5%ba%abdata%e8%b7%af%e5%be%91","status":"publish","type":"post","link":"https:\/\/learn-house.idv.tw\/?p=3185","title":{"rendered":"Ubuntu 20.04\u8a2d\u5b9adatadir\u6539\u8b8aMySQL\u8cc7\u6599\u5eabData\u8def\u5f91"},"content":{"rendered":"<p>\u60f3\u66f4\u6539MySQL\u7684\u8cc7\u6599\u8def\u5f91\uff0c\u60f3\u7576\u7136\u7684\u5c31\u662f\u4fee\u6539\/etc\/mysql\/mysql.conf.d\/mysqld.cnf<br \/>\n\u5c07datadir\u8a2d\u5b9a\u6210\u4f60\u8981\u7684\u8def\u5f91<br \/>\n[c]<br \/>\n\/\/mysqld.cnf<br \/>\n&#8230;<br \/>\ndatadir=\/home2\/mysql<br \/>\n&#8230;<br \/>\n[\/c]<br \/>\n\u4e4b\u524d\u4e0d\u77e5\u9053\u70ba\u4ec0\u9ebc\uff0c\u76f4\u63a5\u66f4\u6539\u5f8c\u91cd\u555fMySQL\u90fd\u6c92\u6709\u554f\u984c\uff0c\u8cc7\u6599\u4e5f\u90fd\u4e5f\u5beb\u5165\u5230\u6211\u6307\u5b9a\u7684\u8def\u5f91\uff0c\u4f46\u4e00\u76f4\u5230\u67d0\u5929\u7a81\u7136MySQL\u4e00\u76f4\u8d77\u4e0d\u4f86\uff0c\u800c\u4e00\u76f4\u51fa\u73fe\u4ee5\u4e0b\u932f\u8aa4<br \/>\n<!--more--><\/p>\n<blockquote><p>\nJob for mysql.service failed because the control process exited with error code.<br \/>\nSee &#8220;systemctl status mysql.service&#8221; and &#8220;journalctl -xe&#8221; for details.<\/p><\/blockquote>\n<p>\u57f7\u884csystemctl status mysql.service\uff0c\u4e5f\u770b\u4e0d\u51fa\u500b\u6240\u4ee5\u7136<\/p>\n<blockquote><p>\u25cf mysql.service &#8211; MySQL Community Server<br \/>\n     Loaded: loaded (\/lib\/systemd\/system\/mysql.service; enabled; vendor preset: enabled)<br \/>\n     Active: failed (Result: exit-code) since Fri 2021-04-30 22:53:39 CST; 4s ago<br \/>\n    Process: 8286 ExecStartPre=\/usr\/share\/mysql\/mysql-systemd-start pre (code=exited, status=0\/SUCCESS)<br \/>\n    Process: 8294 ExecStart=\/usr\/sbin\/mysqld (code=exited, status=1\/FAILURE)<br \/>\n   Main PID: 8294 (code=exited, status=1\/FAILURE)<br \/>\n     Status: &#8220;Server startup in progress&#8221;<br \/>\n      Error: 13 (\u62d2\u7d55\u4e0d\u7b26\u6b0a\u9650\u7684\u64cd\u4f5c)<\/p>\n<p> 4\u6708 30 22:53:39 yuchin-Revo-M1-601 systemd[1]: Failed to start MySQL Community Server.<br \/>\n 4\u6708 30 22:53:39 yuchin-Revo-M1-601 systemd[1]: mysql.service: Scheduled restart job, restart counter is at 5.<br \/>\n 4\u6708 30 22:53:39 yuchin-Revo-M1-601 systemd[1]: Stopped MySQL Community Server.<br \/>\n 4\u6708 30 22:53:39 yuchin-Revo-M1-601 systemd[1]: mysql.service: Start request repeated too quickly.<br \/>\n 4\u6708 30 22:53:39 yuchin-Revo-M1-601 systemd[1]: mysql.service: Failed with result &#8216;exit-code&#8217;.<br \/>\n 4\u6708 30 22:53:39 yuchin-Revo-M1-601 systemd[1]: Failed to start MySQL Community Server.<\/p><\/blockquote>\n<p>\u53c8\u504f\u504f\u4e0d\u77e5\u9053\u70ba\u4ec0\u9ebc\uff0c\u5f9e\/var\/log\/mysql\/error.log\u4e0b\u90fd\u6c92\u6709\u4efb\u4f55\u7d00\u9304\u3002\u6839\u672c\u5c31\u7121\u6cd5\u627e\u51fa\u554f\u984c\uff0c\u5728\u7121\u5948\u4e4b\u969b\u53ea\u597d\u91cd\u704c\u4e26\u91cd\u65b0\u5b89\u88ddMySQL<br \/>\n\u9019\u6b21\u91cd\u88dd\u5f8c\uff0c\u53ea\u8981\u4fee\u6539datadir\u8def\u5f91\uff0c\u5c31\u76f4\u63a5\u6703\u51fa\u73fe\u4e0a\u8ff0\u7684\u932f\u8aa4\uff1b\u4e0d\u904e\u597d\u5728\u9019\u6b21error.log\u88e1\u6709\u9032\u4e00\u6b65\u7684\u63cf\u8ff0\uff1a<\/p>\n<blockquote><p>mysqld: File &#8216;.\/binlog.index&#8217; not found (OS errno 13 &#8211; Permission denied)<br \/>\n2021-04-29T11:34:46.993237Z 0 [Warning] [MY-010091] [Server] Can&#8217;t create test file \/home2\/mysql\/mysqld_tmp_file_case_insensitive_test.lower-test<br \/>\n2021-04-29T11:34:46.993452Z 0 [System] [MY-010116] [Server] \/usr\/sbin\/mysqld (mysqld 8.0.23-0ubuntu0.20.04.1) starting as process 2483<br \/>\n2021-04-29T11:34:47.003975Z 0 [Warning] [MY-010091] [Server] Can&#8217;t create test file \/home2\/mysql\/mysqld_tmp_file_case_insensitive_test.lower-test<br \/>\n2021-04-29T11:34:47.004003Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for \/home2\/mysql\/ is case insensitive<br \/>\n2021-04-29T11:34:47.006374Z 0 [ERROR] [MY-010119] [Server] Aborting<br \/>\n2021-04-29T11:34:47.006726Z 0 [System] [MY-010910] [Server] \/usr\/sbin\/mysqld: Shutdown complete (mysqld 8.0.23-0ubuntu0.20.04.1)  (Ubuntu).<\/p><\/blockquote>\n<p>\u624d\u767c\u73fe\u770b\u8d77\u4f86\u662f\u6b0a\u9650\u7684\u554f\u984c\uff0c\u4f46\u5c31\u662f\u4e0d\u77e5\u9053\u662f\u4ec0\u9ebc\u6b0a\u9650\u554f\u984c\uff0c\u56e0\u70ba\u90fd\u8a2d\u6210777\u9084\u662f\u7121\u6cd5\u89e3\u6c7a<br \/>\n\u7db2\u8def\u4e0a\u89e3\u6cd5\u5f88\u591a\uff0c\u4f46\u90fd\u6c92\u6709\u6548\u3002\u5f8c\u4f86\u624d\u767c\u73fe\u539f\u4f86\u9084\u6709\u4e00\u500bAppArmor\u9700\u8981\u8a2d\u5b9a\uff0c\u4fee\u6539\/etc\/apparmor.d\/tunables\/alias\uff0c\u52a0\u5165<br \/>\n[c]<br \/>\nalias \/var\/lib\/mysql\/ -&gt; \/home2\/mysql\/,<br \/>\n[\/c]<br \/>\n\u91cd\u555fAppArmor<br \/>\n[c]sudo systemctl restart apparmor[\/c]<br \/>\n\u9019\u6a23\u5c31\u80fd\u6210\u529f\u555f\u52d5\u56c9~<\/p>\n<p>\u53c3\u8003\u8cc7\u6599\uff1ahttps:\/\/www.digitalocean.com\/community\/tutorials\/how-to-move-a-mysql-data-directory-to-a-new-location-on-ubuntu-16-04<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u60f3\u66f4\u6539MySQL\u7684\u8cc7\u6599\u8def\u5f91\uff0c\u60f3\u7576\u7136\u7684\u5c31\u662f\u4fee\u6539\/etc\/mysql\/mysql.conf.d\/mysqld.cn<span class=\"post-excerpt-end\">&hellip;<\/span><\/p>\n<p class=\"more-link\"><a href=\"https:\/\/learn-house.idv.tw\/?p=3185\" class=\"themebutton\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-3185","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3185"}],"version-history":[{"count":0,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/3185\/revisions"}],"wp:attachment":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}