{"id":1841,"date":"2010-06-10T18:27:32","date_gmt":"2010-06-10T10:27:32","guid":{"rendered":"http:\/\/www.orczhou.com\/?p=1841"},"modified":"2010-11-10T12:57:08","modified_gmt":"2010-11-10T04:57:08","slug":"compile-mysql-from-source","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2010\/06\/compile-mysql-from-source\/","title":{"rendered":"\u7f16\u8bd1\u5b89\u88c5MySQL"},"content":{"rendered":"<p>\u4f7f\u7528rpm\u5305\uff0c\u6216\u8005apt-get\u3001yum\u7b49\u65b9\u5f0f\u5b89\u88c5MySQL\u5df2\u7ecf\u5f88\u65b9\u4fbf\u4e86\uff0c\u4e0d\u8fc7\u6211\u8fd8\u662f\u66f4\u559c\u6b22\u7f16\u8bd1\u5b89\u88c5\u3002\u7f16\u8bd1\u5b89\u88c5\u7684\u597d\u5904\uff1a\u5e73\u53f0\u65e0\u5173\u3001\u5b89\u88c5\u7684MySQL\u76ee\u5f55\u72ec\u7acb\uff08\u65b9\u4fbf\u6e05\u695a\uff09\uff0c\u636e\u8bf4\u6709\u66f4\u597d\u7684\u6027\u80fd\u548c\u5e73\u53f0\u8026\u5408\u3002\u7f3a\u70b9\uff0c\u7f16\u8bd1\u5b89\u88c5\u8f83\u6162\uff08\u4e0d\u8fc7\u73b0\u57288\u6838CPU\u7f16\u8bd1\u8d77\u6765\u4e5f\u5f88\u5feb\u4e86\uff09\u3002<\/p>\n<p><font color=\"red\">1. MySQL\u7f16\u8bd1\u53c2\u6570<\/font><\/p>\n<p>\u5e38\u7528\u7684\u53c2\u6570\u6709\uff1a<\/p>\n<pre><div class=\"mycode\">CFLAGS=\"-O3\" CXX=gcc CXXFLAGS=\"-O3 -felide-constructors \\\r\n-fno-exceptions -fno-rtti\" .\/configure \\\r\n--prefix=\/data\/mysql --with-extra-charsets=latin1,gbk,utf8 \\\r\n--with-plugins=partition,heap,innobase,myisam,myisammrg,csv \\\r\n--enable-assembler\r\nmake\r\nmake install\r\n<\/div><\/pre>\n<p>\u201cIf you are using a version of gcc recent enough to understand the -fno-exceptions option, it is very important that you use this option. Otherwise, you may compile a binary that crashes randomly. Also use -felide-constructors and -fno-rtti along with -fno-exceptions.\u201d<!--more--><\/p>\n<p>\u53c2\u8003\uff1a<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/installing-source.html\">MySQL Installation Using a Source Distribution<\/a><\/p>\n<p><font color=\"red\">2. \u591a\u6838\u7f16\u8bd1<\/font><\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7 -j \u53c2\u6570\u6307\u5b9a\u7f16\u8bd1\u4f7f\u7528\u7684CPU\u6570\u91cf\uff0c\u4e4b\u524d\u4e00\u76f4\u6ca1\u6709\u6ce8\u610f\u4f7f\u7528\u8fd9\u4e2a\u9009\u9879\uff0c\u4ee5\u4e0b\u662f\u5bf9\u6bd4\u6d4b\u8bd5\uff1a<\/p>\n<pre><div class=\"mycode\">$date &amp;&amp; make &gt; make.log 2&gt;&amp;1 &amp;&amp; date \r\nFri Apr 16 16:32:00 CST 2010\r\nFri Apr 16 16:39:37 CST 2010\r\n\r\n$date && make -j 8 &gt; make.log 2&gt;&amp;1 &amp;&amp; date\r\nFri Apr 16 16:27:10 CST 2010\r\nFri Apr 16 16:28:30 CST 2010\r\n\r\n$date && make -j 15 &gt; make.log 2&gt;&amp;1 &amp;&amp; date\r\nFri Apr 16 16:50:23 CST 2010\r\nFri Apr 16 16:51:41 CST 2010\r\n<\/div><\/pre>\n<p>\u770b\u5230\uff0c\u5355\u6838\u7f16\u8bd1\u82b1\u4e86457\u79d2\uff0c\u516b\u6838\u7f16\u8bd1\u82b1\u4e8680\u79d2\uff0c\u5341\u4e94\u6838\u7f16\u8bd1\u82b1\u4e8678\u79d2\u3002<\/p>\n<p><font color=\"red\">3. \u76ee\u5f55\u7ed3\u6784<\/font><\/p>\n<p><a href=\"http:\/\/www.ningoo.net\/\">\u6700\u521d\u5b89\u88c5<\/a>MySQL\uff0c\u4e0d\u7528RPM\u5305\u7684\u53e6\u4e00\u4e2a\u91cd\u8981\u539f\u56e0\u5c31\u662f\uff0c\u7f16\u8bd1\u5b89\u88c5\u6211\u4eec\u53ef\u4ee5\u83b7\u5f97\u76f8\u5bf9\u72ec\u7acb\u7684MySQL\u76ee\u5f55\uff0c\u5305\u62ecServer\u3001Client\u3001Data File\u7b49\u90fd\u53ef\u4ee5\u6bd4\u8f83\u597d\u7684\u89c4\u5212\u5728\u4e00\u4e2a\u76ee\u5f55\u4e2d\u3002<\/p>\n<p>\u5728\u7f16\u8bd1\u65f6\uff0c\u4f7f\u7528&#8211;prefix=\/data\/mysql\u5219\u53ef\u4ee5\u4fdd\u8bc1\uff0cServer\uff08mysqld_safe\uff09\u3001Client\uff08mysql\uff09\u7b49\u7edf\u4e00\u5728prefix\u6240\u5236\u5b9a\u7684\u76ee\u5f55\u4e0b\uff1b\u5728\/etc\/my.cnf\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u518d\u7ee7\u7eed\u6307\u5b9aData File\u76ee\u5f55\u3001sock\u6587\u4ef6\u76ee\u5f55\u3001pid\u6587\u4ef6\u76ee\u5f55\u3001\u65e5\u5fd7\u76ee\u5f55\u3001tmp\u76ee\u5f55\uff0c\u8fd9\u6837\u57fa\u672c\u4e0a\u5c31\u4fdd\u8bc1\u4e86\u6574\u4e2aMySQL\u7684\u72ec\u7acb\u6027\u3002<\/p>\n<p>\u4f60\u751a\u81f3\u53ef\u4ee5\u628a\/etc\u4e0b\u7684my.cnf\u6587\u4ef6\u90fd\u8f6c\u79fb\u5230prefix\u6307\u5b9a\u7684\u76ee\u5f55\u4e0b\uff0c\u8fd9\u6837\u4f60\u5c31\u62e5\u6709\u4e00\u4e2a\u5b8c\u6574\u800c\u4e14\u72ec\u7acb\u7684MySQL\u76ee\u5f55\u4e86\u3002<\/p>\n<p><font color=\"red\">4. \u9700\u8981\u6ce8\u610f\u7684\u95ee\u9898<\/font><\/p>\n<p>\u4e00\u822c\u7f16\u8bd1\u5b89\u88c5\u4e4b\u540e\uff0c\u5f88\u591a\u751f\u6210\u7684\u811a\u672c\u4e2d\u90fd\u4f1a\u5199\u6b7b\u76ee\u5f55\uff08prefix\u6307\u5b9a\u7684\u76ee\u5f55\uff09\uff0c\u8fd9\u6837\u7f16\u8bd1\u597d\u7684\u811a\u672c\uff08\u4e8c\u8fdb\u5236\u3001shell\u3001perl\uff09\u5982\u679c\u8f6c\u79fb\u5230\u522b\u7684\u76ee\u5f55\u53ef\u80fd\u4f1a\u5bfc\u81f4\u65e0\u6cd5\u8fd0\u884c\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u7f16\u8bd1\u65f6\u6307\u5b9aprefix=<strong>\/data\/<\/strong>mysql\uff0c\u5982\u679c\u6700\u540e\u4f60\u628a\u7f16\u8bd1\u597d\u7684\u6587\u4ef6\u8f6c\u79fb\u5230<strong>\/opt\/<\/strong>mysql\uff0c\u5f88\u591a\u811a\u672c\u53ef\u80fd\u4f1a\u65e0\u6cd5\u8fd0\u884c\uff0c\u751a\u81f3\u4f1a\u53d1\u751f\u5f88\u591a\u602a\u5f02\u7684\u73b0\u8c61:-(<\/p>\n<p><font color=\"red\">5. \u5b89\u88c5\u5b9e\u8df5 step by step<\/font><\/p>\n<p>\u4e0b\u9762\u662f\u5c06MySQL\u5b89\u88c5\u5728\/home\/mysql\u76ee\u5f55\u4e0b\u7684\u4e00\u4e2a\u5b9e\u9645\u64cd\u4f5c\u8fc7\u7a0b\uff0c\u8fd9\u91cc\u7684prefix\u5c06\u6307\u5b9a\u76ee\u5f55\/home\/mysql\/mysql\uff08\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u4fee\u6539\u4e3a\u81ea\u5df1\u9700\u8981\u6307\u5b9a\u7684\u4f4d\u7f6e\uff09<\/p>\n<pre><div class=\"mycode\"># # # \u65b0\u5efa\u8fd0\u884cMySQL\u7684\u7528\u6237\r\ngroupadd dba\r\nuseradd -g dba mysql\r\ncp mysql-5.0.86.tar.gz \/home\/mysql\/\r\nchown -R mysql:dba \/home\/mysql\/mysql-5.0.86.tar.gz\r\n\r\n# # # \u5f00\u59cb\u7f16\u8bd1\u3001\u5b89\u88c5\r\nsu - mysql\r\ntar zxvf \/home\/mysql\/mysql-5.0.86.tar.gz\r\ncd mysql-5.0.86\r\n.\/configure \\\r\n--prefix=\/home\/mysql\/mysql --with-extra-charsets=latin1,gbk,utf8 \\\r\n--with-plugins=partition,heap,innobase,myisam,myisammrg,csv\r\nmake -j 8 && make install   #-j \u8868\u793a\u5e0c\u671b\u4f7f\u7528cpu\u6838\u6570\r\n\r\n# # # \u5efa\u7acb\u914d\u7f6e\u6587\u4ef6\r\ncd \/home\/mysql\/mysql\r\nsu - root\r\ncp mysql\/share\/mysql\/my-medium.cnf \/etc\/my.cnf\r\nchown -R mysql:dba \/etc\/my.cnf\r\n\r\n# # # \u4fee\u6539\u914d\u7f6e\u6587\u4ef6 \u914d\u7f6e\u6570\u636e\u6587\u4ef6\u3001\u65e5\u5fd7\u7684\u8def\u5f84\r\nsu - mysql\r\nvi \/etc\/my.cnf\r\nbasedir = \/home\/mysql\/mysql\r\ndatadir = \/home\/mysql\/mysql\/data\r\nsocket = \/home\/mysql\/mysql\/run\/mysql.sock\r\nlog-error = \/home\/mysql\/mysql\/log\/alert.log\r\nlog_slow_queries = \/home\/mysql\/mysql\/log\/slow.log\r\n\r\nmkdir log run data tmp\r\n\r\n# # # \u521d\u59cbMySQL\u914d\u7f6e\u8868\uff08\u7528\u6237\u8868 \u6743\u9650\u8868\u7b49\uff09\r\n.\/bin\/mysql_install_db --basedir=\/home\/mysql\/mysql  --datadir=\/home\/mysql\/mysql\/data --user=mysql --force\r\n\r\n# # # \u542f\u52a8MySQL\r\n.\/bin\/mysqld_safe &<\/div><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528rpm\u5305\uff0c\u6216\u8005apt-get\u3001yum\u7b49\u65b9\u5f0f\u5b89\u88c5MySQL\u5df2\u7ecf\u5f88\u65b9\u4fbf\u4e86\uff0c\u4e0d\u8fc7\u6211\u8fd8\u662f\u66f4\u559c\u6b22\u7f16\u8bd1\u5b89\u88c5\u3002\u7f16\u8bd1\u5b89\u88c5\u7684\u597d\u5904\uff1a\u5e73\u53f0\u65e0\u5173\u3001\u5b89\u88c5\u7684MySQL\u76ee\u5f55\u72ec\u7acb\uff08\u65b9\u4fbf\u6e05\u695a\uff09\uff0c\u636e\u8bf4\u6709\u66f4\u597d\u7684\u6027\u80fd\u548c\u5e73\u53f0\u8026\u5408\u3002\u7f3a\u70b9\uff0c\u7f16\u8bd1\u5b89\u88c5\u8f83\u6162\uff08\u4e0d\u8fc7\u73b0\u57288\u6838CPU\u7f16\u8bd1\u8d77\u6765\u4e5f\u5f88\u5feb\u4e86\uff09\u3002 1. MySQL\u7f16\u8bd1\u53c2\u6570 \u5e38\u7528\u7684\u53c2\u6570\u6709\uff1a CFLAGS=&#8221;-O3&#8243; CXX=gcc CXXFLAGS=&#8221;-O3 -felide-constructors \\ -fno-exceptions -fno-rtti&#8221; .\/configure \\ &#8211;prefix=\/data\/mysql &#8211;with-extra-charsets=latin1,gbk,utf8 \\ &#8211;with-plugins=partition,heap,innobase,myisam,myisammrg,csv \\ &#8211;enable-assembler make make install \u201cIf you are using a version of gcc recent enough to understand the -fno-exceptions option, it is very important that you use this option. Otherwise, you may compile a binary that crashes randomly. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","inline_featured_image":false,"_tocer_settings":[],"footnotes":""},"categories":[6],"tags":[54],"class_list":["post-1841","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-mysql-install"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/1841","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/comments?post=1841"}],"version-history":[{"count":29,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/1841\/revisions"}],"predecessor-version":[{"id":2679,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/1841\/revisions\/2679"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=1841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=1841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=1841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}