{"id":1186,"date":"2020-02-09T00:01:45","date_gmt":"2020-02-09T05:01:45","guid":{"rendered":"http:\/\/xfloyd.net\/blog\/?p=1186"},"modified":"2020-02-10T11:42:45","modified_gmt":"2020-02-10T16:42:45","slug":"x","status":"publish","type":"post","link":"http:\/\/xfloyd.net\/blog\/?p=1186","title":{"rendered":"Running multiple instances of MySQL on the same server."},"content":{"rendered":"<p>\n<!--StartFragment--><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"step-2-\u2014-pointing-to-the-new-data-location\">Starting point.<\/h2>\n\n\n\n<p>Below is another alternative, but this one seems to be a better way to go.<br><br><a href=\"https:\/\/www.percona.com\/blog\/2014\/08\/26\/mysqld_multi-how-to-run-multiple-instances-of-mysql\/\">https:\/\/www.percona.com\/blog\/2014\/08\/26\/mysqld_multi-how-to-run-multiple-instances-of-mysql\/<\/a> <\/p>\n\n\n\n<p>Above needs to be done in my.cnf and not the &#8220;.d&#8221; folders.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Copy \/etc\/mysql\/my.cnf to \/etc\/mysql\/my2.cnf<br>Also copy conf.d and mysql.conf.d to  conf2.d and mysql.conf2.d<br>Update all the files in them to point to new data location and lock file needs to be in the \/tmp\/ location.<br><br>Pointing to the New Data Location<\/p>\n\n\n\n<p>MySQL has several ways to override configuration values. By default, the&nbsp;<code>datadir<\/code>&nbsp;is set to&nbsp;<code>\/var\/lib\/mysql<\/code>&nbsp;in the&nbsp;<code>\/etc\/mysql\/mysql.conf.d\/mysqld.cnf<\/code>&nbsp;file. Edit this file to reflect the new data directory:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo vi \/etc\/mysql\/mysql.conf.d\/mysqld.cnf <\/pre>\n\n\n\n<p>Find the line that begins with&nbsp;<code>datadir=<\/code>&nbsp;and change the path which follows to reflect the new location.<\/p>\n\n\n\n<p>In our case, the updated file looks like the output below:\/etc\/mysql\/mysql.conf.d\/mysqld.cnf<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>. . .\ndatadir=\/var\/lib\/mysql2\n. . .<\/code><\/pre>\n\n\n\n<p>This seems like the right time to bring up MySQL again, but there\u2019s one more thing to configure before we can do that successfully.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-3-\u2014-configuring-apparmor-access-control-rules\">Step 3 \u2014 Configuring AppArmor Access Control Rules<\/h2>\n\n\n\n<p>We\u2019ll need to tell AppArmor to let MySQL write to the new directory by creating an alias between the default directory and the new location. To do this, edit the AppArmor&nbsp;<code>alias<\/code>&nbsp;file:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/apparmor.d\/tunables\/alias\n<\/pre>\n\n\n\n<p>At the bottom of the file, add the following alias rule:\/etc\/apparmor.d\/tunables\/alias<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>. . .\nalias \/var\/lib\/mysql\/ -> \/var\/lib\/mysql2\/,\n. . .\n<\/code><\/pre>\n\n\n\n<p>For the changes to take effect, restart AppArmor:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sudo systemctl restart apparmor<br><br>Now we can start new MySQL<br><br>shell> mysqld_safe --defaults-file=\/etc\/mysql\/mysql2.cnf &amp; <\/pre>\n\n\n<p><!--EndFragment--><\/p>\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>Starting point. Below is another alternative, but this one seems to be a better way to go. https:\/\/www.percona.com\/blog\/2014\/08\/26\/mysqld_multi-how-to-run-multiple-instances-of-mysql\/ Above needs to be done in my.cnf and not the &#8220;.d&#8221; folders. Copy \/etc\/mysql\/my.cnf to \/etc\/mysql\/my2.cnfAlso copy conf.d and mysql.conf.d to conf2.d and mysql.conf2.dUpdate all the files in them to point to new data location and lock [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1186"}],"collection":[{"href":"http:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1186"}],"version-history":[{"count":7,"href":"http:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1186\/revisions"}],"predecessor-version":[{"id":1194,"href":"http:\/\/xfloyd.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1186\/revisions\/1194"}],"wp:attachment":[{"href":"http:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1186"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xfloyd.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}