{"id":531,"date":"2009-02-19T08:02:00","date_gmt":"2009-02-19T06:02:00","guid":{"rendered":"http:\/\/code.openark.org\/blog\/?p=531"},"modified":"2010-09-17T09:26:53","modified_gmt":"2010-09-17T07:26:53","slug":"manually-installing-multiple-mysql-instances-on-linux-howto","status":"publish","type":"post","link":"https:\/\/code.openark.org\/blog\/mysql\/manually-installing-multiple-mysql-instances-on-linux-howto","title":{"rendered":"Manually installing multiple MySQL instances on Linux: HOWTO"},"content":{"rendered":"<p>Installing a single MySQL instance on a linux machine is a very simple operation. It may be as simple as:<\/p>\n<blockquote>\n<pre>apt-get install mysql-server<\/pre>\n<\/blockquote>\n<p>But you cannot use this method to install another MySQL instance. Moreover, if you try to manually install another instance, you may find that some collisions occur.<\/p>\n<p>For example, when trying to install two 5.0 servers, apt-get or yum will just tell me &#8220;package is already installed&#8221;.<\/p>\n<p>When trying to install a new 5.1 server along with 5.0, an implicit upgrade is performed.<\/p>\n<p>But even if we try forcing the installation, there are collisions:<\/p>\n<ul>\n<li>A dpkg or rpm will install my.cnf under <strong>\/etc<\/strong>. Two installations will override one another. With RPM you may get a .rpmsave backup file, but that doesn&#8217;t help too much.<\/li>\n<li>The daemon file: <strong>\/etc\/init.d\/mysql(d)<\/strong> is overwritten.<\/li>\n<li>The default data directory is used for both installations: <strong>\/var\/lib\/mysql<\/strong><\/li>\n<li>The binaries are overwritten<\/li>\n<li>Both installations will use port 3306.<\/li>\n<li>In both installations, the same socket file (e.g. <strong>\/var\/run\/mysql\/mysql.sock<\/strong>) is used.<\/li>\n<\/ul>\n<p><!--more-->Interestingly, on Windows, multiple MySQL installations are by far easier:<\/p>\n<ul>\n<li>Binaries are under <strong>Program Files\\\\MySQL\\\\MySQLX.X<\/strong>. With two installations, you specify different directories.<\/li>\n<li>Data files are by default directly under the installations paths (MySQL 5.0) or under &#8220;<strong>Documents And Settings&#8230;<\/strong>&#8221; (MySQL 5.1) with no collisions.<\/li>\n<li>The <strong>my.ini<\/strong> files are located directly under the installation paths.<\/li>\n<li>The installer asks you for a service name, and notifies you if that name is already in use.<\/li>\n<li>The installer let&#8217;s you know if port 3306 is already taken, and allows you to specify another one.<\/li>\n<li>Of course, there&#8217;s no unix socket file.<\/li>\n<\/ul>\n<p>I usually install MySQL on Linux using the binary tarball. When there&#8217;s only one instance expected, I go with the standards: my.cnf is in <strong>\/etc<\/strong>, mysqld is under <strong>\/etc\/init.d<\/strong>, etc. (no pun intended)<\/p>\n<h4>Steps for multiple installation on Linux<\/h4>\n<p>When more than one installation is expected, here&#8217;s a safe way to ensure no collisions occur. We will assume a 5.0 and 5.1 installation (say we want to upgrade):<\/p>\n<h4>Install the MySQL binaries under \/usr\/local<\/h4>\n<p>Following the INSTALL document file, we make symbolic links to the full path in the names<\/p>\n<blockquote>\n<pre>ln -s \/usr\/local\/your-mysql-5.0-full-installation-path \/usr\/local\/mysql50\r\nln -s \/usr\/local\/your-mysql-5.1-full-installation-path \/usr\/local\/mysql51<\/pre>\n<\/blockquote>\n<p><strong> <\/strong><\/p>\n<h4>Do not put my.cnf under \/etc<\/h4>\n<p>Instead, put them directly in the installation path:<\/p>\n<blockquote>\n<pre>touch \/usr\/local\/mysql50\/my.cnf\r\ntouch \/usr\/local\/mysql51\/my.cnf<\/pre>\n<\/blockquote>\n<h4>Setup different port numbers in the my.cnf files<\/h4>\n<p>For example, in \/usr\/local\/mysql50\/my.cnf, use port 3350:<\/p>\n<blockquote>\n<pre>[mysql]\r\nport=3350\r\n\r\n[mysqld]\r\nport=3350<\/pre>\n<\/blockquote>\n<p>Choose another port (e.g. 3351) for the 5.1 installation, then have it written as above in the 5.1 my.cnf file.<\/p>\n<h4>Choose distinct socket files<\/h4>\n<p>For example,  in \/usr\/local\/mysql50\/my.cnf, add:<\/p>\n<blockquote>\n<pre>[mysql]\r\nport=3350\r\n<strong>socket=\/tmp\/mysql50.sock<\/strong>\r\n\r\n[mysqld]\r\nport=3350\r\n<strong>socket=\/tmp\/mysql50.sock\r\n<\/strong><\/pre>\n<\/blockquote>\n<p>Choose another socket and set it up in the second my.cnf file. You may also choose to put the socket files under the data paths or installation paths.<\/p>\n<h4>Choose distinct data paths<\/h4>\n<p>Either do not specify them at all, in which case they will reside under the installation path, or, if you want to enjoy another partition, use:<\/p>\n<blockquote>\n<pre>[mysql]\r\nport=3350\r\nsocket=\/tmp\/mysql50.sock\r\n\r\n[mysqld]\r\nport=3350\r\nsocket=\/tmp\/mysql50.sock\r\n<strong>datadir=\/my_raid_path\/mysql50\/<\/strong><\/pre>\n<\/blockquote>\n<h4>Create distinct daemons<\/h4>\n<p>Manually copy support_files\/mysql.server to \/etc\/init.d under distinct names. For example:<\/p>\n<blockquote>\n<pre>cp \/usr\/local\/mysql50\/support_files\/mysql.server \/etc\/init.d\/mysqld50\r\ncp \/usr\/local\/mysql51\/support_files\/mysql.server \/etc\/init.d\/mysqld51<\/pre>\n<\/blockquote>\n<h4>Other settings<\/h4>\n<p>You may wish to set up a soft link for the client binaries, for example:<\/p>\n<blockquote>\n<pre>ln -s \/usr\/local\/mysql50\/bin\/mysql \/usr\/bin\/mysql50<\/pre>\n<\/blockquote>\n<p>chkconfig (RedHat and derived) can be used to start\/stop daemon as service:<\/p>\n<blockquote>\n<pre>chkconfig --add mysqld50<\/pre>\n<\/blockquote>\n<h4>Conclusion<\/h4>\n<p>I would prefer MySQL to come bundled in self-contained directory. The tarball is almost that, except it expects socket file to be on \/tmp, and by default uses the 3306 port. I would further like to have a dpkg-reconfigure script to setup the above issues.<\/p>\n<p>Till then, it&#8217;s manual configuration.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Installing a single MySQL instance on a linux machine is a very simple operation. It may be as simple as: apt-get install mysql-server But you cannot use this method to install another MySQL instance. Moreover, if you try to manually install another instance, you may find that some collisions occur. For example, when trying to [&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":[11,10,119],"class_list":["post-531","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-configuration","tag-installation","tag-linux"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2bZZp-8z","_links":{"self":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/531","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=531"}],"version-history":[{"count":34,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/531\/revisions"}],"predecessor-version":[{"id":577,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/531\/revisions\/577"}],"wp:attachment":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/media?parent=531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/categories?post=531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/tags?post=531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}