Skip navigation.
Home

Languages

MyEnv (MySQL BasEnv)

MyEnv is an environment to run comfortably multiple MySQL instance on one server. You can run even multiple instances with the same binaries.

The concept behind this is to separate binaries from databases itself.

MyEnv bases on OFA which was adapted and improved by my former employer Trivadis. Their product is called TVD-BasEnv. MyEnv is not so comfortable yet but it is free and open.

Requirements

  • Perl must be installed.
  • A user where mysql runs on must exist.

How to install myenv

 root > su - mysql
 mysql> mkdir -p myenv data etc log product source tmp
 mysql> wget http://www.shinguz.ch/MySQL/myenv.tgz
 mysql> tar -xzf myenv.tgz

Install MySQL binaries

 mysql> cd ~/product
 mysql> wget .../Downloads/MySQL-5.0/mysql-5.0.37-linux-i686-glibc23.tar.gz
 mysql> tar -xzf mysql-5.0.37-linux-i686-glibc23.tar.gz
 mysql> mv mysql-5.0.37-linux-i686-glibc23 mysql-5.0.37

Set up a database (instance)

 mysql> cd ~/product/mysql-5.0.37
 mysql> ./scripts/mysql_install_db

Add the following section to ~/myenv/mysqld_multi.conf

 [mysqld5037]
 # must be at first position
 defaults-file = /home/mysql/product/mysql-5.0.37/data/my.cnf
 ledir         = /home/mysql/product/mysql-5.0.37/bin
 mysqld        = /home/mysql/product/mysql-5.0.37/bin/safe_mysqld
 mysqladmin    = /home/mysql/product/mysql-5.0.37/bin/mysqladmin
 language      = /home/mysql/product/mysql-5.0.37/share/mysql/english
 
 port          = 3307
 socket        = /home/mysql/tmp/mysql-3307.sock
 pid-file      = /home/mysql/product/mysql-5.0.37/data/mysql-3307.pid
 datadir       = /home/mysql/product/mysql-5.0.37/data

Add at least the follwing lines to ~/product/mysql-5.0.37/data/my.cnf

 [client]
 
 port          = 3307
 socket        = /home/mysql/tmp/mysql-3307.sock
 
 
 [mysqld]
 
 port          = 3307
 socket        = /home/mysql/tmp/mysql-3307.sock

How to activate myenv

Copy the following lines to your ~/.profile:

 export MYSQL_BASE=`grep '^mysql' /etc/passwd | cut -d':' -f 6`
 export MYENV_BASE="$MYSQL_BASE/myenv"
 
 cd $MYENV_BASE
 . myenv.profile
 cd

And then start the environment with the following command:

 mysql>. ./.profile

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.

Download

Actual release: myenv-newest.tgz

History

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.