{"id":4858,"date":"2012-05-01T10:10:10","date_gmt":"2012-05-01T08:10:10","guid":{"rendered":"http:\/\/code.openark.org\/blog\/?p=4858"},"modified":"2012-05-01T10:10:10","modified_gmt":"2012-05-01T08:10:10","slug":"installing-mysql-from-sourcebinary-tarball-as-a-linux-service","status":"publish","type":"post","link":"https:\/\/code.openark.org\/blog\/mysql\/installing-mysql-from-sourcebinary-tarball-as-a-linux-service","title":{"rendered":"Installing MySQL from source\/binary tarball as a Linux service"},"content":{"rendered":"<p>I&#8217;ve <a href=\"http:\/\/code.openark.org\/blog\/mysql\/to-not-yum-or-to-not-apt-get\">written before<\/a> I prefer to do a manual install of MySQL over a repository one. I still do: I typically install from binary tarball or by compiling from source.<\/p>\n<p>I&#8217;d like to share my setup procedure for Linux installation and service setup. I&#8217;ve done this dozens of times, on different Linux flavors, and it works well for me.<\/p>\n<h4>Installing from source<\/h4>\n<p>To get this straight: you sometimes have to compile the source files. I, for example, happen to use the Sphinx MySQLSE extension. You can only use it if compiled with MySQL. You had to compile a &#8220;vanilla&#8221; <strong>5.1<\/strong> version without query cache in order to completely remove the cache&#8217;s mutex contention.<\/p>\n<p>Anyway, I find the easiest way is to install onto a path associated with the server version. For example, I would install a <strong>5.5<\/strong> server onto <strong>\/usr\/local\/mysql55<\/strong><\/p>\n<p>This way, a new version gets its own path, and no ambiguity.<\/p>\n<p>To do that, use the <strong>prefix<\/strong> option on configuration step:<\/p>\n<blockquote>\n<pre>cd \/path\/to\/extracted\/source\/tarball\r\nsh BUILD\/autorun.sh\r\n.\/configure --prefix=\/usr\/local\/mysql55\r\nmake\r\nsudo make install<\/pre>\n<\/blockquote>\n<p>Once this is complete, you have <em>everything<\/em> under <strong>\/usr\/local\/mysql55<\/strong>. This means binaries, libraries, scripts, etc.<\/p>\n<p>To install the MySQL server as a service, copy the mysql.server script to <strong>\/etc\/init.d<\/strong>:<\/p>\n<blockquote>\n<pre>sudo cp \/usr\/local\/mysql55\/support-files\/mysql.server \/etc\/init.d\/mysql55<\/pre>\n<\/blockquote>\n<p>Again, I&#8217;m naming the script after the MySQL version. This avoids conflict with possible past or future installations of the MySQL server, which typically create a service named <strong>mysql<\/strong> or <strong>mysqld<\/strong>.<!--more--><\/p>\n<p>A thing to note about the mysql.server script is that it allows you (at around line <strong>#45<\/strong>) to set two variables:<\/p>\n<ul>\n<li><strong>basedir<\/strong>: path to your installation directory. When compiling from source this is already setup with the path provided to the <strong>configure<\/strong> script. Thus, in our example, you can expect this variable to read <strong>\/usr\/local\/mysql55<\/strong>. So basically nothing to do here.<\/li>\n<li><strong>datadir<\/strong>: path to your data directory. If you&#8217;re putting your <strong>my.cnf<\/strong> file in <strong>\/etc<\/strong> or <strong>\/etc\/mysql<\/strong>, then setting <strong>datadir<\/strong> in <strong>my.cnf<\/strong> suffices. However, if you&#8217;re going to put <strong>my.cnf<\/strong> itself on the data directory (e.g. so as to avoid collisions) then make sure to set the variable in the <strong>mysql.server<\/strong> init script.<\/li>\n<\/ul>\n<p>Depending on your <strong>$PATH<\/strong> configuration, it is also a good idea to specify <strong>basedir<\/strong> variable on your <strong>my.cnf<\/strong>&#8216;s <strong>[mysqld]<\/strong> section.<\/p>\n<p>Which leads us to <strong>$PATH<\/strong>: your linux system is still unaware of the many binaries you&#8217;ve got in there. I typically add the following line at the end of <strong>\/etc\/bash.bashrc<\/strong>:<\/p>\n<blockquote>\n<pre>export PATH=\/usr\/local\/mysql55:${PATH}<\/pre>\n<\/blockquote>\n<p>This is the most global PATH settings one can do. Alternatively, use <strong>\/etc\/profile<\/strong>, <strong>~\/.bashrc<\/strong> etc. (you may have noticed by now I&#8217;m working with <strong>bash<\/strong>).<\/p>\n<p>Finally, need to setup the init script to run at startup and stop at shutdown.<\/p>\n<ul>\n<li>On Debian\/Ubuntu\/related I use <strong>rcconf<\/strong> (I&#8217;m too lazy to remember the command line setup).<\/li>\n<li>On RedHat\/CentOS\/related I use\u00a0<strong>chkconfig &#8211;add mysql55<\/strong>, or\u00a0 <strong>linuxconf<\/strong> (since I&#8217;m lazy).<\/li>\n<\/ul>\n<h4>Installing from binary tarball<\/h4>\n<p>The only difference is that the <strong>mysql.server<\/strong> script is unaware of our deployment path. So the <strong>basedir<\/strong> variable must be set in that file. Other than that, follow same steps as for source installation (oh, of course no need to <strong>configure<\/strong> &amp; <strong>make<\/strong>&#8230;).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve written before I prefer to do a manual install of MySQL over a repository one. I still do: I typically install from binary tarball or by compiling from source. I&#8217;d like to share my setup procedure for Linux installation and service setup. I&#8217;ve done this dozens of times, on different Linux flavors, and it [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[5],"tags":[10,119],"class_list":["post-4858","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-installation","tag-linux"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2bZZp-1gm","_links":{"self":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/4858","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/comments?post=4858"}],"version-history":[{"count":14,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/4858\/revisions"}],"predecessor-version":[{"id":4893,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/4858\/revisions\/4893"}],"wp:attachment":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/media?parent=4858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/categories?post=4858"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/tags?post=4858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}