Install multi version MySQL in one machine
--
As a fullstack software developer, you must be a superman. What is superman? Someone who create an application, setup an automation, prepare server/hosting, install requirements that required by it machine, and ensure your environment will working well.
In case, your great application already running smoothly on your current server. But that condition will be changes when your client ask you to migrate that application into another existing machine with so many existing application. What do you feel?
But . . . what a problem?
One of the most problem is, Version of the tools is really different. For example, Your application use MySQL with version 5.7, but on new machine already installed version 5.5. That’s really different, your application will not compatible and couldn’t running well as you think.
So . . . What is the solution?
1st. Upgrade MySQL version on your new machine
As simple as you think, upgrade MySQL version is the simplest way to fix that problem. But how about existing application that using old version? . . .
Another application is not my responsibility, i just ensure my application running well. That’s All 😆
That is not the best solution, fix one problem and bring up another complicated problem.
2nd. Install another version of MySQL
I think, this the right solution right now . . . Your MySQL will independent not conflict with another version.
And, how to do this?
Follow this step, trust me it’s works. But, make sure you already have a cup of coffee, because this will take a longer time.
Step 1. Download MySQL source code from official site or you can directly download from this link
Why install using source? why not using deb or another linux extension?
Using source, we can specify installation directory, so it doesn’t overwrite existing version.
Step 2. Copy that downloaded file into wherever you want. But in this sample, i copy into /opt
Step 3. Extract downloaded file and follow this instruction
tar -xvzf mysql-version.tar.gz
cd mysql-version
mkdir build
mkdir bost
cd build
And run below command in build
directory
cmake \
-DCMAKE_INSTALL_PREFIX=/opt/mysql-5.7.26 \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=/opt/mysql-5.7.26/bost \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_UNIX_ADDR=/tmp/mysql5.7.sock \
-DSYSCONFDIR=/etc/mysql-5.7.26 \
..
DCMAKE_INSTALL_PREFIX
Destination directory to install mysql. Make sure, don’t use same directory with existing version.
DDOWNLOAD_BOOST
Give value 1
if you want to automatically download boost
DWITH_BOOST
Destination directory to place boost
DDEFAULT_CHARSET
The server character set. By default, MySQL uses the latin1 (cp1252 West European) character set.
DDEFAULT_COLLATION
The server collation. By default, MySQL uses latin1_swedish_ci
DMYSQL_UNIX_ADDR
Destination directory to place unix socket address that run mysql daemon
DSYSCONFDIR
Destination directory to place mysql config my.cnf
And finish it with
make
make install
Step 4. Go to installation directory that you define on DCMAKE_INSTALL_PREFIX
and enter to bin directory. Let’s assume the value of DCMAKE_INSTALL_PREFIX
is /opt/mysql-5.7
then Create symbolic link with sudo ln -s /opt/mysql-5.7/bin/mysql /usr/bin/mysql5.7
Step 5. Create your new my.cnf
by copy from existing my.cnf
. Place file to directory have you registered on DSYSCONFDIR
. Change several config or follow below config.
[client]
port = 3306
socket = /var/run/mysqld5.7/mysqld.sock[mysqld]
pid-file = /var/run/mysqld5.7/mysqld.pid
socket = /var/run/mysqld5.7/mysqld.sock
datadir = /var/lib/mysql5.7
log-error = /var/log/mysql5.7/error.log
Step 6. Make datadir directory
sudo mkdir /var/lib/mysql5.7
Step 7. Create your first user
bin/mysqld --initialize --user=mysql
bin/mysqld_safe --user=mysql --socket=/var/run/mysqld5.7/mysqld.sock &
bin/mysqladmin -u root password 'new-password' --socket=/var/run/mysqld5.7/mysqld.sock
Note : Make sure you already on /opt/mysql-5.7/
and use --socket
flag to specify mysql socket used
Step 8. Try to login using your account
mysql5.7 -u root -p --socket=/var/run/mysqld5.7/mysqld.sock
Note : If you can’t find mysql5.7
command, back to step 5
That’s it all. If you find missing way, don’t hesitate to make a comment and clap for this article if it use full. Thank you.