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.
Hello, should these steps work when installing 32 and 64 bit versions in parallel? I have a system with 32 bit MySQL installed and in production taht cant be touched or changed, I need to import a database that is in excess of 30G. As this is to big for 32 bit MySQL I need to install 64bit on the same system without touching the 32bit installation. However, when I try and install I keep getting conflicts between the 32 and 64 bit library and dependencies.
So the problem is not with two MySQL instances, one 32 bit and another 64 bit. The problem is with dependencies on your OS.
To be honest, I’m not sure. It depends on which OS you’ve got. Debian based? RedHat based?
I would suggest trying to set the new instance via mysqlsandbox, and resolve the dependencies one by one. Which packages are failing?