Showing posts with label multi. Show all posts
Showing posts with label multi. Show all posts

Tuesday, November 4, 2014

How to install multiple MySQL instances of the same version on a single server

Overview

This will show you how to install multi MySQL instances of the same version on a single server

How to steps
  • Make sure you created the user and group mysql:mysql 
  • Install the MySQL software of your choice without running the mysql_install_db since we'll be doing it at a later time. On my side I used a tarball instead of rpm or yum so I have better control and also I can install multiple version of MySQL on the same server.
  • make sure you have all your filesystems created for your instances. Let say we want 2 instances mysql1 and mysql2. here the folders I created for my exemple
    • /mysql/product/5.5.36 ($MYSQL_HOME)
    • /mysql/product/5.5.36/config ($MYSQL_CONFIG)
    • /mysql/admin/mysql1/noslog
    • /mysql/admin/mysql1/nossql
    • /mysql/admin/mysql1/pid
    • /mysql/admin/mysql1socket
    • /mysql/admin/mysql1backup
    • /mysql/admin/mysql2/noslog
    • /mysql/admin/mysql2/nossql
    • /mysql/admin/mysql2/pid
    • /mysql/admin/mysql2socket
    • /mysql/admin/mysql2backup
    • /mysql1/data
    • /mysql1/logs
    • /mysql2/data
    • /mysql2/logs
  • Make sure the user and group mysql are owner of all the folders  for mysql and the instances
    • chown -R mysql:mysql /mysql /mysql1 /mysql2
    • chmod -R 775  /mysql /mysql1 /mysql2
  • now create a .cnf file onto $MYSQL__CONFIG and call it mysql_5.5.36.cnf and make sure mysql:mysql have access to it
  • here is a simple exemple
[mysqld_safe]
basedir=/mysql/product/5.5.36
ledir=/mysql/product/5.5.36/bin

[mysqld_multi]
mysqld=mysqld_safe
mysqladmin=/mysql/product/5.5.36/bin/mysqladmin
log=/mysql/admin/mysql_multi/logs/mysql_multi.log

[mysqld1]
basedir=/mysql/product/5.5.36datadir=/mysql1/data
log-bin=/mysql1/logs/log-bin
socket=/mysql/admin/mysql1/socket/mysql1.socket
pid-file=/mysql/admin/mysql1/pid/mysql1.pid
log-error=/mysql/admin/mysql1/noslog/mysql1-error.log
max_binlog_size=100M
binlog-format=MIXED
port=3307
expire_logs_days=5
default-storage-engine=innodb
server-id=5401
skip-slave-start

[mysqld2]
basedir=/mysql/product/5.5.36datadir=/mysql2/data
log-bin=/mysql2/logs/log-bin
socket=/mysql/admin/mysql2/socket/mysql2.socket
pid-file=/mysql/admin/mysql2/pid/mysql1.pid
log-error=/mysql/admin/mysql2/noslog/mysql1-error.log
max_binlog_size=100M
binlog-format=MIXED
port=3308
expire_logs_days=5
default-storage-engine=innodb
server-id=5402
skip-slave-start

  •  Now you have to create your instances
  • cd $MYSQL_HOME
  • ./scripts/mysql_install_db --defaults-file=$MYSQL_HOME/config/mysql_5.5.36.cnf --basedir=$MYSQL_HOME --datadir=/mysql1/data --user=mysql
  • ./scripts/mysql_install_db --defaults-file=$MYSQL_HOME/config/mysql_5.5.36.cnf --basedir=$MYSQL_HOME --datadir=/mysql2/data --user=mysql
  • Now you can start the 2 instances using mysqld_multi
    • mysqld_multi --defaults-file=$MYSQL_CONFIG/mysql_5.5.36.cnf start 1
    • mysqld_multi --defaults-file=$MYSQL_CONFIG/mysql_5.5.36.cnf start 2
  • From that point
    your instances are up and running ad you can secure them
    • cd $MYSQL_HOME
    • ./bin/mysql_secure_installation defaults-file=$MYSQL_HOME/config/mysql_5.5.36.cnf --port=yourinstanceport --socket=yourinstancesocket

How to run mysql and other commands for each instance

To run mysql you have to run the mysql and other command with the --defaults-file, --port and --socket options so you indicate to mysql on wich instance you want to connect

Note

  • I had few issues with some of the command where even if I specified the location of the .cnf that contains the location of the socket. it was not reading it. this is a know issue ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'.In order to fix it  create a soft link then remove it after
Ex: ln -fs /mysql/admin/mysql1/socket/mysql1.socket /tmp/mysql.sock
once done remove it
rm -f /tmp/mysql.sock








Monday, November 3, 2014

How to install a MySQL using a tarball as source

Overview

This will give view an overview on how to install a MySQL using a tarball. This way of installation will also allow you to install multiple version of MySQL on the same version.

Software Download

  • The first step is to download a version that is on tar format instead of the RPM.On my side I'm using generic Linux 64 bit 5.5.40
  • The next step is to prepare your server so you can install MySQL
    • Create a user mysql:mysql
    • Create a filesystem /mysql/product/5.5.40 (MYSQL_HOME) but you can also create folders
    • create the folder $MYSQL_HOME/config (MYSQL_CONFIG)
    • create a small  filesystem /mysql1
    • Create a filesystem /mysql1/data (mysql1 is my instance) (MYSQL_DATA)
    • Create a filesystem /mysql1/logs (MYSQL_BINLOG)
    • Create a filesystem /mysql
    • Create /mysql/admin/mysql1 (MYSQL_ADMIN)
      • scripts
      • logs
      • socket
      • pid
      • backup 
    • create /mysql/admin/mysqld_safe/logs
    • create /mysql/admin
    • Once your filesystems and folders are created make sure you do the following 
      • chown -R mysql;mysql /mysql /mysql1
      • chmod -R 775 /mysql /mysql1
  • copy the .tar.gz file in /mysql/product/5.5.40
  • untar (tar -zxvf)  the content into /mysql/product/5.5.40
  •  At this point the software is installed

 Create the instance (mysql1)

  • create your my.cnf into $MYSQL_HOME/config (I use mysql_5.5.40.cnf)
Here is an exemple of my .cnf file
#############################################33
[mysqld_safe]
basedir=/mysql/product/5.5.36

ledir=/mysql/product/5.5.36/bin

[mysqld_multi]
mysqld=mysqld_safe
mysqladmin=/mysql/product/5.5.36/bin/mysqladmin
log=/mysql/admin/mysql_multi/logs/mysql_multi.log

[mysqld1]
basedir=/mysql/product/5.5.36datadir=/mysql1/data
log-bin=/mysql1/logs/log-bin
socket=/mysql/admin/mysql1/socket/mysql1.socket
pid-file=/mysql/admin/mysql1/pid/mysql1.pid
log-error=/mysql/admin/mysql1/noslog/mysql1-error.log
max_binlog_size=100M
binlog-format=MIXED
port=3307

expire_logs_days=5
default-storage-engine=innodb

server-id=5401
skip-slave-start

##################################

  •  connect as mysql
  • cd $MYSQL_HOME
  • ./scripts/mysql_install_db --defaults-file=$MYSQL_HOME/config/mysql_5.5.36.cnf --basedir=$MYSQL_HOME --datadir=/mysql1/data --user=mysql
  • Your instance is now ready to be started

Start your Application

  • cd $MYSQL_HOME
  • ./bin/mysqld_multi --defaults-file=$MYSQL_CONFIG/mysql_5.5.36.cnf start 1 
  • I highly suggest you run the $MYSQL_HOME/bin/mysql_secure installation 
To stop it
  • ./bin/mysqld_multi --defaults-file=$MYSQL_CONFIG/mysql_5.5.36.cnf stop 1

Note

I discover that there is a bug (
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
)
for some of the tools like mysqladmin or mysqlcheck.
even if you specify the location of the my.cnf with the --defaults-file option you will get an error about not finding /tmp/my.cnf
the solution
  • create a symbolic link 
    • ln -fs $MYSQL_HOME/config/mysql_5.5.36.cnf /tmp/my.cnf
    • run your command
    • if you do not have multiple instance you can leave otherwise remove it after