You are here

MyEnv (MySQL BasEnv)

What is MyEnv?

MyEnv is a set of scripts to run comfortably multiple MySQL, Percona Server or MariaDB database instances on the same server. You can even run multiple database instances with different binary versions.

MyEnv is more comfortable than mysqld_multi and provides more functionality.

A large MySQL user (Alexa Ranking: Top 500 world-wide, top 20 in Germany) stated:

I found MyEnv accidentally when I was searching for something like this. I liked it immediately more than MySQL Sandbox or mysqld_multi. A very comfortable tool. Thank you very much!

MyEnv user Jonv:

I am working on a project where I will most likely be using MyEnv (oh how I wish I had known of this the last time I set up mysqld_multi).
...
Thanks for writing MyEnv, it's going to make this project far more polished without having to use mysqld_multi again.

License

MyEnv is distributed under the terms of the GNU General Public License v2.

Download

Actual and past releases you can find here for download.

When to use MyEnv?

MyEnv is useful when you have to install several MySQL database instances on one machine. This has to be done typically:

  • when you have to consolidate many databases from dedicated servers into fewer machines or
  • when you have to separate the data of different customers into different databases if you provide Software-as-a-Service (SaaS) solutions (for example hoster or internal IT departments for big companies).

Check out this link for more information about How to install multiple MySQL instances on a single host using MyEnv.

MyEnv has the advantage over virtualization solutions (like VMWare or VirtualBox) that you do not have the overhead of an additional virtual machine and the installed operating system.

MyEnv bases on the ideas of my former employer Trivadis. Their product is called TVD-BasEnv.

Requirements

  • Currently those scripts work on UNIX only (only Linux is tested).
  • PHP must be installed.
  • A user where the MySQL database runs with (typically mysql) must exist.

Requires on CentOS

  • php-cli
  • php-mysqli
  • php-posix

Requires on Ubuntu

  • php5-cli
  • php5-mysql

Requires on SLES

  • php5-posix
  • php5-pcntl

More sources for MyEnv

MyEnv can be downloaded from here.

For questions, feedback and comments, please go to our MyEnv forum.

Bug and feature request can be reported here.

How to install MyEnv

Ideally you install the tar-ball in the home directory of your mysql user (typically mysql):

# Install the dependencies as mentioned above according to your OS.
shell> mkdir /etc/myenv
shell> chown -R mysql:mysql /etc/myenv
shell> su - mysql
shell> cd /download
shell> wget http://www.fromdual.com/download/myenv-latest.tar.gz
shell> mkdir ~/product
shell> cd ~/product
shell> tar xf /download/myenv-latest.tar.gz
shell> ln -s myenv-x.y myenv

Upgrade MyEnv

Upgrading MyEnv is very simple. You can proceed as follows:

shell> su - mysql
shell> cd /download
shell> wget http://www.fromdual.com/download/myenv-x.y.tar.gz
shell> cd ~/product
shell> tar xf /download/myenv-x.y.tar.gz
shell> unlink myenv
shell> ln -s myenv-x.y myenv

Configuring MyEnv

You have 2 possibilities:

  • You can configure MyEnv by running the installMyEnv.php script:
    shell> myenv/bin/installMyEnv.php
  • Or you can configure MyEnv manually:
    shell> cp myenv/etc/myenv.conf.template myenv/etc/myenv.conf
    shell> cat myenv/profile.template >> .bash_profile

Then logout and login again...

De-install MyEnv

To de-install MyEnv again just remove the myenv section from your .bash_profile and the myenv-x.y directory:

shell> cd ~/product
shell> rm -rf myenv-x.y myenv /etc/init.d/myenv /etc/myenv

Make sure that the original start/stop script is put back in place and that the my.cnf is at its original location.

Put a database under MyEnv control

Run the myenv install script ~/myenv/bin/installMyEnv.sh and choose the option "a" (add instance) then follow the instructions.

Or add a section similar to the following example to /etc/myenv/myenv.conf:

#
# /etc/myenv/myenv.conf
#

[test]
start                = yes
stop                 = yes
hideschema           = mysql,performance_schema
name                 = test
basedir              = /usr/local/mysql
datadir              = /var/lib/mysql
port                 = 3306
socket               = /tmp/mysql-3306.sock
my.cnf               = /etc/my.cnf
angel                = yes
user                 = mysql

How MyEnv works

You should always work as user mysql for starting, stopping and doing maintenance work.

When you login you get the following display:

Up       : mysqld523 (5.2.3)

Down     : mysqld5115 (5.1.16) mysqld5037 (5.0.37) mysqld4027 (4.0.27)
           mysqld4122 (4.1.22)

mysqld523 (3323)  : cacti mysql test
mysqld5116 (3325)  : cluster_test mysql test
mysqld5037 (3307)  : mysql test
mysqld4027 (3320)  : mysql test
mysqld4122 (3319)  : mysql test FoodMart

mysql@master:~ [mysqld523, 3323]>

Functionality

The most important commands are:

<instance> : Switches to the environment for this instance. For example:
             shell> mysqld5116
u or up    : Lists, which releases are available, which instances are up and
             down and which instance contains which database. For example:
             shell> u
start      : Starts the actual or a specific instance. For example:
             shell> start
             or
             shell> start mysqld5116
stop       : Stops the actual instance or a specific instance. For example:
             shell> stop
             or
             shell> stop mysqld5116
restart    : restarts the actual or a specific instance. For example:
             shell> restart
             or
             shell> restart mysqld5116
V          : print the current MyEnv version
cdh, cdb   : cd to the basedir of this instance.
cdd        : cd to the datadir of this instance.
cdc        : cd to the cluster-directory of this instance.
cde        : cd to the myenv-directory.
cd a b     : cd to a directory with the name where a is substituted by b.
             For example:
             shell> pwd /var/lib/mysql1
             shell> cd 1 2
             shell> pwd /var/lib/mysql2
ll         : ls -l
la         : ls -la

To enable debugging functionality use:

shell> export MYENV_DEBUG=1

To disable debugging functionality again use:

shell> unset MYENV_DEBUG

Feedback is welcome at our MyEnv forum. Bug descriptions and enhancement requests can be reported at the MyEnv bug tracker.