{"id":2904,"date":"2016-09-28T13:25:01","date_gmt":"2016-09-28T05:25:01","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=2904"},"modified":"2016-09-28T13:25:01","modified_gmt":"2016-09-28T05:25:01","slug":"mysql%e6%95%b0%e6%8d%ae%e7%9b%ae%e5%bd%95%e7%9a%84%e4%bf%ae%e6%94%b9centos","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/2904.html","title":{"rendered":"MySQL\u6570\u636e\u76ee\u5f55\u7684\u4fee\u6539(CentOS)"},"content":{"rendered":"<p>=Start=<\/p>\n<h4>\u7f18\u7531\uff1a<\/h4>\n<p>MySQL\u9ed8\u8ba4\u7684\u6570\u636e\u76ee\u5f55\u6240\u5728\u78c1\u76d8\u7a7a\u95f4\u4e0d\u591f\u5927\uff0c\u5728\u6570\u636e\u91cf\u5927\/\u589e\u957f\u8f83\u5feb\u7684\u65f6\u5019\u5bb9\u6613\u5bfc\u81f4\u78c1\u76d8\u62a5\u8b66\uff0c\u6240\u4ee5\u9700\u8981\u4fee\u6539MySQL\u7684\u6570\u636e\u76ee\u5f55\u5230\u53e6\u4e00\u4e2a\u78c1\u76d8\u7a7a\u95f4\u5145\u8db3\u7684\u76ee\u5f55\u4e0b\u3002<\/p>\n<h4>\u53c2\u8003\u89e3\u7b54\uff1a<\/h4>\n<h5>1.\u51c6\u5907\u5de5\u4f5c<\/h5>\n<pre class=\"lang:default decode:true\">$ ps aux | grep --color -i \"mysql\"\nroot 18452 0.0 0.0 110364 1636 pts\/3 S 17:25 0:00 \/bin\/sh \/usr\/bin\/mysqld_safe --datadir=\/var\/lib\/mysql --pid-file=\/var\/lib\/mysql\/`hostname`.pid\nmysql 18674 0.3 2.4 679308 193832 pts\/3 Sl 17:25 0:27 \/usr\/sbin\/mysqld --basedir=\/usr --datadir=\/var\/lib\/mysql --plugin-dir=\/usr\/lib64\/mysql\/plugin --user=mysql --log-error=\/var\/lib\/mysql\/`hostname`.err --pid-file=\/var\/lib\/mysql\/`hostname`.pid\n\n\n$ file \/usr\/bin\/mysqld_safe\n$ vim \/usr\/bin\/mysqld_safe\n...\nDATADIR=\/var\/lib\/mysql\n--datadir=$DATADIR\n--log-error=$DATADIR\/`hostname`.err\n--pid-file=$DATADIR\/`hostname`.pid\n...\n\n$ file \/etc\/init.d\/mysql\n$ vim \/etc\/init.d\/mysql<\/pre>\n<h5>2.\u5b9e\u9645\u64cd\u4f5c<\/h5>\n<pre class=\"lang:default decode:true\">1.\u5148\u505c\u6389MySQL\u670d\u52a1\n# \/etc\/init.d\/mysql status\n# \/etc\/init.d\/mysql stop\n\n2.\u5207\u6362MySQL\u6570\u636e\u76ee\u5f55 &amp; \u540c\u65f6\u4fee\u6539MySQL\u914d\u7f6e\u6587\u4ef6\u7684\u5bf9\u5e94\u90e8\u5206\n# cp -rap \/var\/lib\/mysql \/data\/mysql\n# chown mysql.mysql \/data\/mysql\n\n# vim \/etc\/my.cnf\nChange From:\ndatadir=\/var\/lib\/mysql\nsocket=\/var\/lib\/mysql\/mysql.sock #\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u51b3\u5b9a\u662f\u5426\u6dfb\u52a0\uff0c\u6709\u7684\u53ea\u662f\u7528\u7684`port`\u800c\u4e0d\u662f`socket`\n\nChange To:\ndatadir = \/data\/mysql\npid-file = \/data\/mysql\/`hostname`.pid #\u8bb0\u5f97\u5c06`hostname`\u66ff\u6362\u6210\u5b9e\u9645\u7684 \u4e3b\u673a\u540d\nsocket = \/data\/mysql\/mysql.sock #\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u51b3\u5b9a\u662f\u5426\u6dfb\u52a0\uff0c\u6709\u7684\u53ea\u662f\u7528\u7684`port`\u800c\u4e0d\u662f`socket`\n\n3.\u542f\u52a8MySQL\u670d\u52a1\n# \/etc\/init.d\/mysql status\n# \/etc\/init.d\/mysql start<\/pre>\n<h5>3.\u53ef\u80fd\u4f1a\u9047\u5230\u7684\u95ee\u9898<\/h5>\n<h6>\u95ee\u9898\u4e00\uff1aERROR 2002 (HY000): Can&#8217;t connect to local MySQL server through socket &#8216;\/var\/lib\/mysql\/mysql.sock&#8217; (2)<\/h6>\n<p>\u89e3\u51b3\u529e\u6cd5\uff1a<\/p>\n<pre class=\"lang:default decode:true\">\u65b9\u6cd5\u4e00\uff1a\n\u5c06\u5982\u4e0b\u5185\u5bb9\u6dfb\u52a0\u81f3MySQL\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d`\/etc\/my.cnf`\uff1a\n[client]\nsocket = \/data\/mysql\/mysql.sock\n\n\u65b9\u6cd5\u4e8c\uff1a\n\u5728\u547d\u4ee4\u884c\u4e2d\u624b\u52a8\u6307\u5b9a`IP:port`\u6216`socket`\uff1a\n$ mysql -uroot -p -h127.0.0.1 -P3306\n\u6216\n$ mysql -uroot -p --socket=\/opt\/mysql\/mysql.sock<\/pre>\n<h6>\u95ee\u9898\u4e8c\uff1aERROR! The server quit without updating PID file (xxx.pid).<\/h6>\n<p>\u53ef\u80fd\u7684\u539f\u56e0\uff1a<\/p>\n<ul>\n<li>\u6743\u9650\u95ee\u9898\uff1b\u300c\u5148\u67e5\u770blog-error\u6307\u5b9a\u7684\u6587\u4ef6\u4e2d\u8be6\u7ec6\u7684\u62a5\u9519\u4fe1\u606f\uff0c\u7136\u540e\u518d\u68c0\u67e5\u76ee\u5f55\u3001\u6587\u4ef6\u7684\u6743\u9650\u662f\u5426\u6b63\u786e\u300d<\/li>\n<li>\u5df2\u6709\u5b9e\u4f8b\u6b63\u5728\u8fd0\u884c\uff1b<\/li>\n<li>\u2026\u2026<\/li>\n<\/ul>\n<h4>\u53c2\u8003\u94fe\u63a5\uff1a<\/h4>\n<ul>\n<li><a href=\"http:\/\/tecadmin.net\/change-default-mysql-data-directory-in-linux\/\">http:\/\/tecadmin.net\/change-default-mysql-data-directory-in-linux\/<\/a><\/li>\n<li><a href=\"http:\/\/crashmag.net\/change-the-default-mysql-data-directory-with-selinux-enabled\">http:\/\/crashmag.net\/change-the-default-mysql-data-directory-with-selinux-enabled<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/11657829\/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-run\">http:\/\/stackoverflow.com\/questions\/11657829\/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-run<\/a><\/li>\n<li><a href=\"http:\/\/pein0119.github.io\/2015\/03\/25\/MySQL%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%90%AF%E5%8A%A8%E9%94%99%E8%AF%AF-The-server-quit-without-updating-PID-file\/\">http:\/\/pein0119.github.io\/2015\/03\/25\/MySQL%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%90%AF%E5%8A%A8%E9%94%99%E8%AF%AF-The-server-quit-without-updating-PID-file\/<\/a><\/li>\n<li><a href=\"http:\/\/blog.csdn.net\/leshami\/article\/details\/39759849\">http:\/\/blog.csdn.net\/leshami\/article\/details\/39759849<\/a><\/li>\n<\/ul>\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a MySQL\u9ed8\u8ba4\u7684\u6570\u636e\u76ee\u5f55\u6240\u5728\u78c1\u76d8\u7a7a\u95f4\u4e0d\u591f\u5927\uff0c\u5728\u6570\u636e\u91cf\u5927\/\u589e\u957f\u8f83\u5feb\u7684\u65f6\u5019\u5bb9\u6613\u5bfc\u81f4\u78c1\u76d8\u62a5\u8b66 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,23,11],"tags":[662,16],"class_list":["post-2904","post","type-post","status-publish","format-standard","hentry","category-database","category-knowledgebase-2","category-linux","tag-datadir","tag-mysql"],"views":2840,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=2904"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/2904\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=2904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=2904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=2904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}