{"id":216,"date":"2013-04-01T19:47:52","date_gmt":"2013-04-01T19:47:52","guid":{"rendered":"http:\/\/www.reades.com\/?p=216"},"modified":"2013-04-01T19:47:52","modified_gmt":"2013-04-01T19:47:52","slug":"multiple-mysql-servers-on-a-single-machine","status":"publish","type":"post","link":"http:\/\/www.reades.com\/wp\/?p=216","title":{"rendered":"Multiple MySQL Servers on a Single Machine"},"content":{"rendered":"<p>\t\t\t\t<i>Note: this was previously posted at\u00a0<a href=\"http:\/\/simulacra.blogs.casa.ucl.ac.uk\/2011\/05\/configuring-multiple-mysql-servers-on-a-single-machine\/\" target=\"_blank\" rel=\"noopener\">simulacra.info<\/a>, but I am in the process of (re)organising my technical notes and tutorials.<\/i><\/p>\n<p>A bit of a dry post here, but I thought I&#8217;d share my experience of trying to get two instances of MySQL (and two different versions, to boot) running simultaneously on a single piece of hardware as I&#8217;ve spent the past two days tearing my hear out and swearing profusely (mostly) under my breath.<!--more--><\/p>\n<p>So the background for this post is that we&#8217;ve recently received a new\u00a0toy\u00a0server for data crunching in short, sharp bursts. The idea is that when we&#8217;re working with sensitive data that can&#8217;t be stored &#8216;in the cloud&#8217; we can use this machine, with its 32GB of RAM, to whiz through aggregation and querying. However, because we&#8217;ve got multiple users of the system and some of us need different levels of security\u00a0<em>as well as<\/em>\u00a0different versions of the software, there really was no alternative to installing two sets of binaries with two very different configurations.<\/p>\n<p>We installed the first using Ubuntu&#8217;s handy\u00a0<code>apt-get<\/code>\u00a0utility, but the second one proved the problem. First, it needs to be installed somewhere else, and because it&#8217;s Ubuntu we can&#8217;t install from RPM. So custom configuration here we come&#8230; which is where the fun begins because it turns out that the configuration process has changed\u00a0<em>utterly<\/em>\u00a0since I last did anything like this.<\/p>\n<p>Apparently,\u00a0<code>cmake<\/code>\u00a0has now replaced\u00a0<code>.\/configure<\/code>\u00a0as the &#8216;right way&#8217; to do these things, and after a great deal of huffing and puffing this got me a configurable system:<\/p>\n<p><code><br \/>\ncmake . -DCMAKE_INSTALL_PREFIX=\/usr\/local\/mysql-secure -DMYSQL_DATADIR=\/var\/mysql-secure\/ -DWITH_SSL=yes\u00a0-DCURSES_LIBRARY=\/usr\/lib\/libncurses.a\u00a0-DWITH_DEBUG=OFF -DMYSQL_MAINTAINER_MODE=OFF -DENABLED_PROFILING=ON -DINSTALL_LAYOUT=STANDALONE<br \/>\n<\/code><\/p>\n<p>Now you go back to the old habit of:<\/p>\n<p><code><br \/>\nmake<br \/>\nsudo make install<br \/>\n<\/code><\/p>\n<p>If you&#8217;re very, very lucky then this will have compiled smoothly. If you&#8217;re not then, in all probability you don&#8217;t have curses or libaio1 installed and will have to\u00a0<code>make clean<\/code>\u00a0before you can reach this point without an error.<\/p>\n<p>You&#8217;re now ready to finish the installation, so head on over to your base directory for the install:<\/p>\n<p><code><br \/>\ncd \/usr\/local\/mysql-secure\/<br \/>\n<\/code><\/p>\n<p>I&#8217;m assuming here that you still want to\u00a0<em>run<\/em>\u00a0MySQL as the\u00a0<code>mysql<\/code>\u00a0user (who should have their login shell set to\u00a0<code>\/dev\/null<\/code>), but you could quite easily run it as another user if you want:<\/p>\n<p><code><br \/>\nsudo .\/scripts\/mysql_install_db --user=mysql --basedir=\/usr\/local\/mysql-secure\/ --datadir=\/var\/lib\/mysql-secure<br \/>\n<\/code><\/p>\n<p>You should then go through the normal steps to set up a\u00a0<code>root<\/code>\u00a0password and generally lock down MySQL as best you can. You will also want to set up a separate configuration file for your &#8216;secure&#8217; MySQL installation because, at the very least, you need it to run on a different port (here specified as\u00a0<code>XXXX<\/code>) and with a different socket. Something like this:<\/p>\n<p><code><br \/>\n[client]<br \/>\nport = XXXX<br \/>\nsocket = \/var\/run\/mysqld\/mysqld-secure.sock<\/code><\/p>\n<p>user = mysql<br \/>\nsocket = \/var\/run\/mysqld\/mysqld-secure.sock<br \/>\nport = XXXX<br \/>\nbasedir = \/usr\/local\/mysql-secure<br \/>\ndatadir = \/var\/lib\/mysql-secure<br \/>\ntmpdir = \/tmp<\/p>\n<p>You&#8217;re nearly there, and from here on out the server can be started by simply running:<\/p>\n<p><code><br \/>\nsudo .\/bin\/mysqld_safe --defaults-file=\/etc\/mysql\/secure.cnf --user=mysql &amp;<br \/>\n<\/code><\/p>\n<p>I&#8217;m still trying to figure out what isn&#8217;t\u00a0<em>quite<\/em>\u00a0right about the configuration, but here&#8217;s how to connect locally and remotely to a database called\u00a0<code>db<\/code>\u00a0on the\u00a0<em>second<\/em>\u00a0instance of MySQL server listening on port XXX:<\/p>\n<p><code><br \/>\nmysql --socket=\/var\/run\/mysqld\/mysqld-secure.sock -P XXX\u00a0-u root -p db<br \/>\nmysql -P XXX -u foo -p db<br \/>\n<\/code><\/p>\n<p>Hope this helps anyone trying to do anything similar.<\/p>\n<p>Next up: figuring out how to configure SSL with MySQL for additional security.<\/p>\n<h3>Configuring a Third Server<\/h3>\n<p>As with all things computer related, you can always have more. In this case, I wanted access to the OpenQuery Graph engine for MySQL\/MariaDB. Well, it turns out that MySQL isn&#8217;t so keen on the engine and MariaDB (a drop-in replacement for MySQL) is the only way to go. So for posterity&#8217;s sake here&#8217;s how I got a third database up and running on the\u00a0<em>same<\/em>\u00a0machine.<\/p>\n<p>I grabbed the source distribution for MariaDB (this is version 5.3, by the time you&#8217;re reading this you might want to check for a 5.x) from here:\u00a0<a href=\"http:\/\/downloads.askmonty.org\/mariadb\/5.3\/#file_type=source\">http:\/\/downloads.askmonty.org\/mariadb\/5.3\/#file_type=source<\/a><br \/>\n<code>tar -xzvf maria...<br \/>\ncd .\/maria...<br \/>\n.\/configure --prefix=\/usr\/local\/mariadb-5.3 --datadir=\/cosmic\/...<br \/>\nmake &amp;&amp; sudo make install<br \/>\nsudo chown -R XXX \/cosmic\/...<br \/>\ncd \/usr\/local\/mariadb-5.3<br \/>\nsudo .\/bin\/mysql_install_db --user=XXX --defaults-file=\/etc\/my-openquery.cnf --datadir=\/cosmic\/...<\/code><br \/>\nThat last command obviously relies on you having created a configuration file for the OpenQuery-enabled MariaDB installation. Here&#8217;s a minimal working copy:<\/p>\n<p><code><br \/>\n[client]<br \/>\nport = XXX<br \/>\nsocket = \/tmp\/mariadb-secure.sock<\/code><\/p>\n<p>[mysql.server]<br \/>\nuser=mysql<br \/>\nbasedir=\/mnt\/cosmic\/&#8230;<\/p>\n<p>[mysqld]<br \/>\nuser = XXX<br \/>\nport = XXX<br \/>\nsocket = \/tmp\/mariadb-secure.sock<br \/>\ndatadir=\/mnt\/cosmic\/&#8230;<br \/>\nskip-external-locking<br \/>\nkey_buffer = 16M<br \/>\nmax_allowed_packet = 1M<br \/>\ntable_cache = 64<br \/>\nsort_buffer_size = 512K<br \/>\nnet_buffer_length = 8K<br \/>\nread_buffer_size = 256K<br \/>\nread_rnd_buffer_size = 512K<br \/>\nmyisam_sort_buffer_size = 8M<\/p>\n<p>&#8230; [There&#8217;s more in here, but a basic MySQL.cnf file will give you all you need] &#8230;<\/p>\n<p>Starting up is as simple as:<br \/>\n<code><br \/>\nsudo \/usr\/local\/mariadb-5.3\/bin\/mysqld_safe --defaults-file=\/etc\/mysql\/my-opengraph.cnf --user=mysql &amp;<br \/>\n<\/code><\/p>\n<p>But to enable the graph plug-in engine for Maria there&#8217;s one last step &#8212; you need to connect to the database an issue the following command (as root):<\/p>\n<p><code><br \/>\nINSTALL PLUGIN oqgraph SONAME 'ha_oqgraph.so';<br \/>\nSHOW ENGINES;<\/code>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note: this was previously posted at\u00a0simulacra.info, but I am in the process of (re)organising my technical notes and tutorials. A bit of a dry post here, but I thought I&#8217;d share my experience of trying to get two instances of MySQL (and two different versions, to boot) running simultaneously on a single piece of hardware [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,12],"tags":[36,37,72],"class_list":["post-216","post","type-post","status-publish","format-standard","hentry","category-big-data","category-tutorials","tag-data-2","tag-database","tag-mysql"],"_links":{"self":[{"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/216","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=216"}],"version-history":[{"count":0,"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=\/wp\/v2\/posts\/216\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=216"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=216"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.reades.com\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=216"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}