Installing a single MySQL instance on a linux machine is a very simple operation. It may be as simple as:
apt-get install mysql-server
But you cannot use this method to install another MySQL instance. Moreover, if you try to manually install another instance, you may find that some collisions occur.
For example, when trying to install two 5.0 servers, apt-get or yum will just tell me “package is already installed”.
When trying to install a new 5.1 server along with 5.0, an implicit upgrade is performed.
But even if we try forcing the installation, there are collisions:
- A dpkg or rpm will install my.cnf under /etc. Two installations will override one another. With RPM you may get a .rpmsave backup file, but that doesn’t help too much.
- The daemon file: /etc/init.d/mysql(d) is overwritten.
- The default data directory is used for both installations: /var/lib/mysql
- The binaries are overwritten
- Both installations will use port 3306.
- In both installations, the same socket file (e.g. /var/run/mysql/mysql.sock) is used.
Interestingly, on Windows, multiple MySQL installations are by far easier:
- Binaries are under Program Files\\MySQL\\MySQLX.X. With two installations, you specify different directories.
- Data files are by default directly under the installations paths (MySQL 5.0) or under “Documents And Settings…” (MySQL 5.1) with no collisions.
- The my.ini files are located directly under the installation paths.
- The installer asks you for a service name, and notifies you if that name is already in use.
- The installer let’s you know if port 3306 is already taken, and allows you to specify another one.
- Of course, there’s no unix socket file.
I usually install MySQL on Linux using the binary tarball. When there’s only one instance expected, I go with the standards: my.cnf is in /etc, mysqld is under /etc/init.d, etc. (no pun intended)
Steps for multiple installation on Linux
When more than one installation is expected, here’s a safe way to ensure no collisions occur. We will assume a 5.0 and 5.1 installation (say we want to upgrade):
Install the MySQL binaries under /usr/local
Following the INSTALL document file, we make symbolic links to the full path in the names
ln -s /usr/local/your-mysql-5.0-full-installation-path /usr/local/mysql50 ln -s /usr/local/your-mysql-5.1-full-installation-path /usr/local/mysql51
Do not put my.cnf under /etc
Instead, put them directly in the installation path:
touch /usr/local/mysql50/my.cnf touch /usr/local/mysql51/my.cnf
Setup different port numbers in the my.cnf files
For example, in /usr/local/mysql50/my.cnf, use port 3350:
[mysql] port=3350 [mysqld] port=3350
Choose another port (e.g. 3351) for the 5.1 installation, then have it written as above in the 5.1 my.cnf file.
Choose distinct socket files
For example, in /usr/local/mysql50/my.cnf, add:
[mysql] port=3350 socket=/tmp/mysql50.sock [mysqld] port=3350 socket=/tmp/mysql50.sock
Choose another socket and set it up in the second my.cnf file. You may also choose to put the socket files under the data paths or installation paths.
Choose distinct data paths
Either do not specify them at all, in which case they will reside under the installation path, or, if you want to enjoy another partition, use:
[mysql] port=3350 socket=/tmp/mysql50.sock [mysqld] port=3350 socket=/tmp/mysql50.sock datadir=/my_raid_path/mysql50/
Create distinct daemons
Manually copy support_files/mysql.server to /etc/init.d under distinct names. For example:
cp /usr/local/mysql50/support_files/mysql.server /etc/init.d/mysqld50 cp /usr/local/mysql51/support_files/mysql.server /etc/init.d/mysqld51
Other settings
You may wish to set up a soft link for the client binaries, for example:
ln -s /usr/local/mysql50/bin/mysql /usr/bin/mysql50
chkconfig (RedHat and derived) can be used to start/stop daemon as service:
chkconfig --add mysqld50
Conclusion
I would prefer MySQL to come bundled in self-contained directory. The tarball is almost that, except it expects socket file to be on /tmp, and by default uses the 3306 port. I would further like to have a dpkg-reconfigure script to setup the above issues.
Till then, it’s manual configuration.
Andi,
Try another one: add –basedir=/usr/local/mysqlg/
Let me know if this worked out
Shlomi
Guys thank you for starting this thread. This has been very helpful for me to get up to speed. and getting both of the mysql instances running in parallel
Andi,
I’ve encountered exactly the same problem, try this – i think this will resolve your problem:
/usr/local/mysqlg/bin/mysqld_safe –defaults-file=/usr/local/mysqlg/my.cnf &
By doing so you explicitly tell mysql to use your new my.cnf.
Also, i’ve made a change in mysqld_safe script as well to use my own user – u might want to try it as well. In my version it’s on line 21 user=’mysqlg’
I have tried out MySQL sandbox and recommend it to everyone – it’s very easy to handle. http://mysqlsandbox.net/
Hi,
Thanks for the information,just found this post my technorati news feed section! I was searching for this since past 3 months and i am glad to see it here. Thanking you much
Martin
Hi Martin,
I’m glad it helped. But do try MySQL sandbox. It automates so much.
Shlomi