Skip navigation.
Home

Languages

RSS Feed FromDual on Linked In Recommend us on Xing Join us on Facebook Google+ Flickr Contact us

MyEnv (MySQL BasEnv)

What is MyEnv

MyEnv is a set of scripts to run comfortably multiple MySQL/MariaDB databases on the same server. You can even run multiple databases with different binary versions.

It is more comfortable than mysqld_multi and provides more functionality.

When to use MyEnv?

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

  • when you have to consolidate many databases from dedicated servers into less machines or
  • when you have to separate the data of different customers into different databases when you provide Software-as-a-Service (SaaS) solutions.

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

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

Requirements

  • PHP must be installed.
  • A user where the MySQL database runs with (typically mysql) must exist.

How to install MyEnv

 shell> su - mysql
 shell> cd
 shell> wget http://www.shinguz.ch/download/myenv-latest.tar.gz
 shell> tar xf myenv-latest.tar.gz
 shell> ln -s myenv-x.y myenv

Configuring

You have 2 possibilities:

  • You can "configure" MyEnv by running the installMyEnv script:

 shell> myenv/bin/installMyEnv.sh

  • 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...

If you want to have your databases stopped and started automatically copy myenv/bin/myenv.server to /etc/init.d and link it correctly to the different run levels.

Deinstall MyEnv

To de-install the MyEnv just remove the myenv-x.y directory again:

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

and remove the myenv section from your .bash_profile.

Put a database under MyEnv control

Add a section similar to the following example to ~/myenv/myenv.conf:

 #
 # myenv.conf
 #
 
 [test]
 basedir  = /usr/local/mysql
 datadir  = /var/lib/mysql
 port     = 3306
 socket   = /tmp/mysql-3306.sock
 my.cnf   = /etc/my.cnf
 start    = YES

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:

 Releases : 4.0.27 4.1.22 5.0.37 5.1.16 5.2.3
 
 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]>

The most important commands are:

  • mysqldxxxx: Sets the environment for the according database.
  • start, stop: starts or stops the according database.
  • cdh: cds to the binary tree of the actual database.
  • cdd: cds to the data tree of the actual database.
  • up, u: Shows what is available, up and down.

Any feedback, bug descriptions enhancement requests etc. are welcome to contact@fromdual.com.

Download

Actual and past releases you can find here for download.

Other approaches

Isotopp and Giuseppe Maxia have similar approaches... Maybe in the near or far future we will merge one or both of them?

MySQL Sandbox from Giuseppe Maxia

... something similar that I've done some time ago, called MySQL Sandbox, which has enjoyed some popularity.

There is a tutorial explaining how it works.