{"id":651,"date":"2023-02-26T13:42:09","date_gmt":"2023-02-26T05:42:09","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=651"},"modified":"2023-04-29T19:24:26","modified_gmt":"2023-04-29T11:24:26","slug":"modify-mysql-database-storage-location-under-centos-7","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/26\/modify-mysql-database-storage-location-under-centos-7\/","title":{"rendered":"CentOS 7 \u4e0b\u4fee\u6539 MySQL \u6570\u636e\u5e93\u5b58\u653e\u4f4d\u7f6e"},"content":{"rendered":"<p>MySQL \u5b89\u88c5\u540e\u6709\u9ed8\u8ba4\u7684\u6570\u636e\u5e93\u5b58\u50a8\u8def\u5f84\uff0c\u6709\u65f6\u5019\u56e0\u6570\u636e\u76d8\u7a7a\u95f4\u9650\u5236\u95ee\u9898\uff0c\u6211\u4eec\u9700\u8981\u5c06\u6570\u636e\u5b58\u50a8\u5230\u7a7a\u95f4\u8f83\u5927\u7684\u78c1\u76d8\u6216\u76ee\u5f55\u4e0b\uff0c\u56e0\u6b64\u9700\u8981\u4fee\u6539 MySQL \u6570\u636e\u5b58\u50a8\u8def\u5f84\u3002\u73b0\u5c06 MySQL \u6570\u636e\u5e93\u5b58\u653e\u5728 \/data\/mysql \u4e0b\u3002<\/p>\n<p><!-- more --><\/p>\n<pre><code>[root@localhost ~]# mysql -uroot -p\nEnter password: \nWelcome to the MySQL monitor.  Commands end with ; or \\g.\nYour MySQL connection id is 52795\nServer version: 5.7.18 MySQL Community Server (GPL)\n\nCopyright (c) 2000, 2017, Oracle and\/or its affiliates. All rights reserved.\n\nOracle is a registered trademark of Oracle Corporation and\/or its\naffiliates. Other names may be trademarks of their respective\nowners.\n\nType &#039;help;&#039; or &#039;\\h&#039; for help. Type &#039;\\c&#039; to clear the current input statement.\n\nmysql&gt; show variables like &#039;%datadir%&#039;;    \/\/\u67e5\u8be2\u5f53\u524d\u6570\u636e\u5e93\u5728\u78c1\u76d8\u4e0a\u7684\u5b58\u50a8\u8def\u5f84\n+---------------+-----------------+\n| Variable_name | Value           |\n+---------------+-----------------+\n| datadir       | \/var\/lib\/mysql\/ |\n+---------------+-----------------+\n1 row in set (0.03 sec)\n\nmysql&gt; quit\nBye\n[root@localhost ~]# ls \/var\/lib\/mysql\/\nauto.cnf     ib_logfile1                mysql               RPM_UPGRADE_HISTORY\nibdata1      localhost.localdomain.err  mysql.sock          RPM_UPGRADE_MARKER-LAST\nib_logfile0  localhost.localdomain.pid  performance_schema  test\n[root@localhost ~]# systemctl stop mysqld    \/\/\u505c\u6b62MySQL\u670d\u52a1\n[root@localhost ~]# cp -R \/var\/lib\/mysql \/data\/    \/\/\u590d\u5236\u6570\u636e\u81f3\u76ee\u6807\u76ee\u5f55\n[root@localhost ~]# find \/ -name &#039;my.cnf&#039;    \/\/\u67e5\u627e\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6\n\/usr\/my.cnf\n[root@localhost ~]# vim \/usr\/my.cnf\n\ndatadir = &quot;\/data\/mysql&quot;    \/\/\u4fee\u6539\u6570\u636e\u5e93\u5b58\u50a8\u8def\u5f84\n\n:wq! #\u4fdd\u5b58\u9000\u51fa\n\n[root@localhost ~]# systemctl start mysqld\nStarting MySQL. ERROR! The server quit without updating PID file (\/data\/mysql\/localhost.localdomain.pid).\n[root@localhost ~]#<\/code><\/pre>\n<p>\u95ee\u9898\uff1aStarting MySQL. ERROR! The server quit without updating PID file\u3002\u53ef\u80fd\u7684\u539f\u56e0\uff1a<\/p>\n<p>1.\u53ef\u80fd\u662f \/data\/mysql\/localhost.localdomain.pid \u6587\u4ef6\u6ca1\u6709\u5199\u7684\u6743\u9650<br \/>\n\u89e3\u51b3\u65b9\u6cd5\uff1a\u7ed9\u4e88\u6743\u9650\uff0c\u6267\u884c \u201cchown -R mysql:mysql \/data\/mysql\u201d \u548c \u201cchmod -R 755 \/data\/mysql\u201d \u7136\u540e\u91cd\u65b0\u542f\u52a8 MySQL\u3002<\/p>\n<p>2.\u53ef\u80fd\u8fdb\u7a0b\u91cc\u5df2\u7ecf\u5b58\u5728 MySQL \u8fdb\u7a0b<br \/>\n\u89e3\u51b3\u65b9\u6cd5\uff1a\u7528\u547d\u4ee4 \u201cps -ef | grep mysqld\u201d \u67e5\u770b\u662f\u5426\u6709mysqld\u8fdb\u7a0b\uff0c\u5982\u679c\u6709\u4f7f\u7528 \u201ckill -9 \u8fdb\u7a0b\u53f7\u201d \u6740\u6b7b\uff0c\u7136\u540e\u91cd\u65b0\u542f\u52a8 MySQL\u3002<\/p>\n<p>3.\u53ef\u80fd\u662f\u7b2c\u4e8c\u6b21\u5728\u673a\u5668\u4e0a\u5b89\u88c5 MySQL\uff0c\u6709\u6b8b\u4f59\u6570\u636e\u5f71\u54cd\u670d\u52a1\u7684\u542f\u52a8\u3002<br \/>\n\u89e3\u51b3\u65b9\u6cd5\uff1a\u6253\u5f00 MySQL \u7684\u6570\u636e\u76ee\u5f55\u770b\u770b\uff0c\u5982\u679c\u5b58\u5728 mysql-bin.index\uff0c\u5220\u9664\u5373\u53ef\u3002<\/p>\n<p>4.SELinux \u60f9\u7684\u7978\uff0c\u5982\u679c\u662f CentOS \u7cfb\u7edf\uff0c\u9ed8\u8ba4\u4f1a\u5f00\u542f SELinux<br \/>\n\u89e3\u51b3\u65b9\u6cd5\uff1a\u5173\u95ed SELinux\uff0c\u6253\u5f00 \/etc\/selinux\/config\uff0c\u628a SELINUX=enforcing \u6539\u4e3a SELINUX=disabled \u540e\u4fdd\u5b58\u9000\u51fa\u91cd\u542f\u3002<\/p>\n<p>\u672c\u6587\u7684\u95ee\u9898\u5c31\u5728 SELinux \u4e0a\uff0c\u5728CentOS 7\u53ca\u4ee5\u4e0a\u66f4\u6539 MySQL \u7684\u6570\u636e\u76ee\u5f55\uff0c\u5fc5\u987b\u7981\u7528 SELinux\uff0c\u5426\u5219 MySQL \u65e0\u6cd5\u542f\u52a8\u3002<\/p>\n<p>\u89e3\u51b3\u529e\u6cd5\uff1a<\/p>\n<pre><code># vim \/etc\/selinux\/config\n\n#SELINUX=enforcing #\u6ce8\u91ca\n#SELINUXTYPE=targeted #\u6ce8\u91ca\nSELINUX=disabled #\u589e\u52a0\n\n:wq! #\u4fdd\u5b58\u9000\u51fa\n\n# setenforce 0 #\u4f7f\u914d\u7f6e\u7acb\u5373\u751f\u6548<\/code><\/pre>\n<pre><code>[root@localhost ~]# systemctl start mysqld\nStarting MySQL.. SUCCESS!\n[root@localhost ~]# mysql -u root -p\nEnter password: \nWelcome to the MySQL monitor.  Commands end with ; or \\g.\nYour MySQL connection id is 52796\nServer version: 5.7.18 MySQL Community Server (GPL)\n\nCopyright (c) 2000, 2017, Oracle and\/or its affiliates. All rights reserved.\n\nOracle is a registered trademark of Oracle Corporation and\/or its\naffiliates. Other names may be trademarks of their respective\nowners.\n\nType &#039;help;&#039; or &#039;\\h&#039; for help. Type &#039;\\c&#039; to clear the current input statement.\n\nmysql&gt; show variables like &#039;%datadir%&#039;;    \/\/\u53ef\u4ee5\u770b\u5230\u5f53\u524d\u6570\u636e\u5e93\u5728\u78c1\u76d8\u4e0a\u7684\u5b58\u50a8\u8def\u5f84\u5df2\u66f4\u65b0\n+---------------+--------------+\n| Variable_name | Value        |\n+---------------+--------------+\n| datadir       | \/data\/mysql\/ |\n+---------------+--------------+\n1 row in set (0.03 sec)\n\nmysql&gt; <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>MySQL \u5b89\u88c5\u540e\u6709\u9ed8\u8ba4\u7684\u6570\u636e\u5e93\u5b58\u50a8\u8def\u5f84\uff0c\u6709\u65f6\u5019\u56e0\u6570\u636e\u76d8\u7a7a\u95f4\u9650\u5236\u95ee\u9898\uff0c\u6211\u4eec\u9700\u8981\u5c06\u6570\u636e\u5b58\u50a8\u5230\u7a7a\u95f4\u8f83\u5927\u7684\u78c1\u76d8\u6216\u76ee\u5f55 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[20],"class_list":["post-651","post","type-post","status-publish","format-standard","hentry","category-devops-base","tag-mysql"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=651"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/651\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}