Centos: How to run multiple mysql instances on a single server

centos_iconmysql There are plenty instruction on how to run multiple mysql instances on a single server on various blogs. Most of them are based on the original mysql rpm package produced by Oracle (nowdays). In my opinion this could be unnecessary overhead when you have OS provided mysql server package and all you need to configure another instance is to slightly modify bundled configuration and init.d script.

To separate new instance from default mysql server configuration we will use

  • server port 3307
  • pid file /var/run/mysqld/mysql2.pid
  • server config file /etc/my2.cnf
  • Data dir (for all database file storage) /home/mysql2
  • Server log file /var/log/mysqld2.log
  • Socket file /home/mysql2/mysql.sock
  1. First we need to make /etc/my2.cnf –
    here is original minimal /etc/my.cnf

    And here modified /etc/my2.cnf

    Or as patch file

    You can download patch file and apply it

  2. Next step – create modified startup script, that would read proper configuration file, extract port number from it (by default port number is not passed) and invoke mysqld process with set parameters. Here is the patch:

    Download the patch to ~/mysqld2.patch and apply

  3. Now after everything configured we can start new instance and let it configure new data dir with service databases and permissions

Now you have fully functional second instance of mysqld server running with the only overhead of modified configuration files. You can create as many instances as you need the same way.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">