Multiple instances on linux

401 views

Published on

Multiple instances on linux

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
401
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Multiple instances on linux

  1. 1. Install first instance (3306) by using rpm’sDefault installation directory will be/var/lib/mysqlAnd configuration file location will be/etc/my.cnfStart the MySql server , it will initialize the database automaticallyService mysql startHere First instance is already running .i.e 3306[root@INVIRH54DB3 ~]# service mysql statusMySQL running (14835) [ OK ][root@INVIRH54DB3 ~]# mysql -u root -pEnter password: (mysql)Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 6Server version: 5.5.30-log MySQL Community Server (GPL)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is aregistered trademark of Oracle Corporation and/or itsaffiliates. Other names may betrademarks of their respectiveowners.Type help; or h for help. Type c to clear thecurrent input statement.mysql> SHOW GLOBAL VARIABLES LIKE %port%;+---------------------+-------+| Variable_name | Value |+---------------------+-------+| innodb_support_xa | ON || large_files_support | ON || port | 3306 || report_host | || report_password | || report_port | 3306 || report_user | |+---------------------+-------+7 rows in set (0.00 sec)
  2. 2. mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || sample1 || sample2 || sample3 || sample4 || test |+--------------------+8 rows in set (0.01 sec)
  3. 3. To run multiple instances using MySQL we need to have a couple of things separate fromthe initial install on MySQL like data directory, init script and config file. It is quite thatsimple and here is how we do it, I will subscript 2 for all the files/directories that I amgoing to create to indicate this new second instance:Step 1. Create a new data directory [/var/lib/Instances/INFA1] and[/var/lib/Instances/INFA2] make mysql user own it.(3307,3308)[root@INVIRH54DB3 ~]# mkdir /var/lib/Instances[root@INVIRH54DB3 ~]# chown -R mysql:mysql /var/lib/Instances/[root@INVIRH54DB3 ~]# mkdir /var/lib/Instances/INFA1[root@INVIRH54DB3 ~]# mkdir /var/lib/Instances/INFA2[root@INVIRH54DB3 ~]# chown -R mysql:mysql /var/lib/Instances/INFA1[root@INVIRH54DB3 ~]# chown -R mysql:mysql /var/lib/Instances/INFA2Step : 2. Create a new mysql configuration fileNext we need a separate configuration file. We can start by copying the existing one andchanging the needed values. We just copy this folder and modify it from there.If you use a redhat variant package then your configuration file is under /etc/my.cnf bydefault and you can just copy it directly:(or change the path appropriately for yourconfiguration file is in a different place).Next, we need to edit our new configuration file and at least update the mysqlport (default to 3306), the pid and socket to be different than the default ones, and alsopoint the data and logfolders to the ones created before.[root@INVIRH54DB3 ~]# cp /etc/my.cnf /etc/my3307.cnf[root@INVIRH54DB3 ~]# cp /etc/my.cnf /etc/my3308.cnf
  4. 4. New Instances Directories should be like this:[root@INVIRH54DB3 lib]# cd Instances/[root@INVIRH54DB3 Instances]# ls –ltrdrwxr-xr-x 2 mysql mysql 4096 May 31 09:50 INFA1drwxr-xr-x 2 mysql mysql 4096 May 31 09:50 INFA2Step: 3Edit cnf file for port number 3307 (Sample 3307.cnf File)[client]password = your_passwordport = 3307socket = /var/lib/Instances/INFA1/mysql3307.sock# Here follows entries for some specific programs# The MySQL server[mysqld]port = 3307datadir=/var/lib/Instnaces/INFA1socket = /var/lib/Instances/INFA1/mysql3307.sockskip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512K
  5. 5. myisam_sort_buffer_size = 8Mcharacter_set_server = utf8collation_server = utf8_general_ci# Uncomment the following if you are using InnoDB tablesinnodb_data_home_dir = /var/lib/Instances/INFA1innodb_data_file_path = ibdata1:10M:autoextendinnodb_log_group_home_dir = /var/lib/Instances/INFA1# You can set .._buffer_pool_size up to 50 - 80 %# of RAM but beware of setting memory usage too highinnodb_buffer_pool_size = 16Minnodb_additional_mem_pool_size = 2M# Set .._log_file_size to 25 % of buffer pool sizeinnodb_log_file_size = 5Minnodb_log_buffer_size = 8Minnodb_flush_log_at_trx_commit = 1innodb_lock_wait_timeout = 50
  6. 6. Step: 4 Edit cnf file for port number 3308 (Sample 3308.cnf File)[client]password = your_passwordport = 3308socket = /tmp/mysql3308.sock# Here follows entries for some specific programs# The MySQL server[mysqld]port = 3308datadir=/var/lib/Instances/INFA2socket = /tmp/mysql3308.sockskip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mcharacter_set_server = utf8collation_server = utf8_general_ci
  7. 7. # Uncomment the following if you are using InnoDB tablesinnodb_data_home_dir = /var/lib/Instances/INFA2innodb_data_file_path = ibdata1:10M:autoextendinnodb_log_group_home_dir = /var/lib/Instances/INFA2# You can set .._buffer_pool_size up to 50 - 80 %# of RAM but beware of setting memory usage too highinnodb_buffer_pool_size = 16Minnodb_additional_mem_pool_size = 2M# Set .._log_file_size to 25 % of buffer pool sizeinnodb_log_file_size = 5Minnodb_log_buffer_size = 8Minnodb_flush_log_at_trx_commit = 1innodb_lock_wait_timeout = 50
  8. 8. Step 5. Install default tables for this new database instance (3307)[root@INVIRH54DB3 ~]# /usr/bin/mysql_install_db --basedir=/usr/ --datadir=/var/lib/Instances/INFA1/Installing MySQL system tables...OKFilling help tables...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right placefor your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !To do so, start the server, then issue the following commands:/usr//bin/mysqladmin -u root password new-password/usr//bin/mysqladmin -u root -h INVIRH54DB3 password new-passwordAlternatively you can run:/usr//bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous usercreated by default. This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd /usr/ ; /usr//bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd /usr//mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr//scripts/mysqlbug script!
  9. 9. Step 6 : Install default tables for this new database instance (3308)[root@INVIRH54DB3 ~]# /usr/bin/mysql_install_db --basedir=/usr/ --datadir=/var/lib/Instances/INFA2/Installing MySQL system tables...OKFilling help tables...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right placefor your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !Todo so, start the server, then issue the following commands:/usr//bin/mysqladmin -u root password new-password/usr//bin/mysqladmin -u root -h INVIRH54DB3 password new-passwordAlternatively you can run:/usr//bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous usercreated by default. This isstrongly recommended for production servers.
  10. 10. See the manual for more instructions.You can start the MySQL daemon with:cd /usr/ ; /usr//bin/mysqld_safe &You can test the MySQL daemon with mysql-test-run.plcd /usr//mysql-test ; perl mysql-test-run.plPlease report any problems with the /usr//scripts/mysqlbug script!Directory Checking :[root@INVIRH54DB3 Instances]# chown -R mysql:mysql INFA1[root@INVIRH54DB3 Instances]# chown -R mysql:mysql INFA2[root@INVIRH54DB3 Instances]# cd INFA1[root@INVIRH54DB3 INFA1]# ls -ltrdrwx------ 2 mysql mysql 4096 May 31 10:10 testdrwx------ 2 mysql mysql 4096 May 31 10:10 performance_schema-rw-rw---- 1 mysql mysql 38 May 31 10:10 mysql-bin.index
  11. 11. -rw-rw---- 1 mysql mysql 27308 May 31 10:10 mysql-bin.000001drwx------ 2 mysql mysql 4096 May 31 10:10 mysql-rw-rw---- 1 mysql mysql 1036239 May 31 10:10 mysql-bin.000002[root@INVIRH54DB3 Instances]# cd INFA2[root@INVIRH54DB3 INFA2]# ls -ltrdrwx------ 2 mysql mysql 4096 May 31 10:13 testdrwx------ 2 mysql mysql 4096 May 31 10:13 performance_schema-rw-rw---- 1 mysql mysql 27308 May 31 10:13 mysql-bin.000001drwx------ 2 mysql mysql 4096 May 31 10:13 mysql-rw-rw---- 1 mysql mysql 38 May 31 10:13 mysql-bin.index-rw-rw---- 1 mysql mysql 1036239 May 31 10:13 mysql-bin.000002Step :7 Finally we can start our new mysql instance with: (3307.cnf)[root@INVIRH54DB3 ~]# /usr/bin/mysqld_safe --defaults-file=/etc/my3307.cnf --basedir=/usr --datadir=/var/lib/Instances/INFA1 &
  12. 12. 130531 10:21:58 mysqld_safe Logging to /var/lib/Instances/INFA1/INVIRH54DB3.err.130531 10:21:59 mysqld_safe Starting mysqld daemon with databases from/var/lib/Instances/INFA1130531 10:22:17 mysqld_safe mysqld from pid file/var/lib/Instances/INFA1/INVIRH54DB3.pid endedStep :8Finally we can start our new mysql instance with: (3308.cnf)[root@INVIRH54DB3 ~]# /usr/bin/mysqld_safe --defaults-file=/etc/my3308.cnf --basedir=/usr --datadir=/var/lib/Instances/INFA2 &[root@INVIRH54DB3 ~]# 130531 10:24:25 mysqld_safe Logging to/var/lib/Instances/INFA2/INVIRH54DB3.err.130531 10:24:26 mysqld_safe Starting mysqld daemon with databases from/var/lib/Instances/INFA2Step :9 Checking the Mysql new instances are running or not (3307 & 3308)[root@INVIRH54DB3 ~]# ps -ef | grep -i mysqlroot 14422 1 0 May30 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/INVIRH54DB3.pidmysql 14835 14422 0 May30 ? 00:00:05 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/INVIRH54DB3.err --pid-file=/var/lib/mysql/INVIRH54DB3.pid --socket=/var/lib/mysql/mysql.sock --port=3306
  13. 13. root 23827 27077 0 May30 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/etc/my3307.cnf --basedir=/usr --datadir=/var/lib/INFA1/datamysql 24201 23827 0 May30 pts/0 00:00:05 /usr/sbin/mysqld --defaults-file=/etc/my3307.cnf --basedir=/usr --datadir=/var/lib/INFA1/data --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/INFA1/data/INVIRH54DB3.err --pid-file=/var/lib/INFA1/data/INVIRH54DB3.pid --socket=/tmp/mysql3307.sock --port=3307root 30211 27077 0 10:24 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/etc/my3308.cnf --basedir=/usr --datadir=/var/lib/Instances/INFA2mysql 30621 30211 0 10:24 pts/0 00:00:02 /usr/sbin/mysqld --defaults-file=/etc/my3308.cnf --basedir=/usr --datadir=/var/lib/Instances/INFA2 --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/Instances/INFA2/INVIRH54DB3.err --pid-file=/var/lib/Instances/INFA2/INVIRH54DB3.pid --socket=/tmp/mysql3308.sock --port=3308
  14. 14. Step: 10We can connect to our new instance using 3307Make sure thehere password is empty, just press enter button ,it will connect mysqlprompt.[root@INVIRH54DB3 ~]# mysql -u root -p -S /tmp/mysql3307.sockEnter password: (Press Enter)Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 1Server version: 5.5.30-log MySQL Community Server (GPL)Copyright (c) 2000, 2013,Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of OracleCorporation and/or itsaffiliates. Other names may be trademarks of theirrespectiveowners.Type help; or h for help. Type c to clear the current inputstatement.mysql> SHOW GLOBAL VARIABLES LIKE %port%;+---------------------+-------+| Variable_name | Value |+---------------------+-------+| innodb_support_xa | ON || large_files_support | ON || port | 3307 || report_host | || report_password | || report_port | 3307 || report_user | |+---------------------+-------+7 rows in set (0.00 sec)
  15. 15. And also check innodb files…
  16. 16. Step :11We can connect to our new instance using 3308Make sure the password is empty ,just press enter button ,it will connect mysql promt.Later we update the password after connecting mysql prompt.[root@INVIRH54DB3 ~]# mysql -u root -p -S /tmp/mysql3308.sockEnter password: (empty)Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 1
  17. 17. Server version: 5.5.30-log MySQL Community Server (GPL)Copyright (c) 2000, 2013,Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of OracleCorporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type help; or h for help. Type c to clear the current input statement.mysql> SHOW GLOBAL VARIABLES LIKE %port%;+---------------------+-------+| Variable_name | Value |+---------------------+-------+| innodb_support_xa | ON || large_files_support | ON || port | 3308 || report_host | || report_password | || report_port | 3308 || report_user | |+---------------------+-------+7 rows in set (0.00 sec)
  18. 18. And also check innodb files…
  19. 19. Step 12:To check Directories on each new instance.It should be like this.For INFA1 –3307
  20. 20. Step 13: To check Directories on each new instance.It should be like this.For INFA2 --- 3308Step 14: To check /tmp Directory .It should be like this.If you want to create log file on cnf file ,we can mention like this .log-bin=/var/lib/INFA1/3307.logStep 15 : If we no longer need it, stop it with the following command. (Shutdownparticular port instance 3307)/usr/bin/mysqladmin -u root -S /tmp/mysql3307.sock shutdown -pEnter password: (Here password is mysql)130531 14:15:59 mysqld_safe mysqld from pid file/var/lib/Instances/INFA1/INVIRH54DB3.pid ended[5] Done/usr/bin/mysqld_safe --defaults-file=/etc/my3307.cnf --basedir=/usr --datadir=/var/lib/Instances/INFA1
  21. 21. Here password is empty. Untill we set password on particular hostStep 16: Process checking after shutdown the port (3307)After shut downing the particular port ,if you want to start again means, we can run thiscommand./usr/bin/mysqld_safe --defaults-file=/etc/my3307.cnf --basedir=/usr --datadir=/var/lib/Instances/INFA1 &Once the service is starts we can check process (3307),[root@INVIRH54DB3 ~]# ps -ef | grep -i mysqlroot 8286 1 0 13:48 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib/mysql/INVIRH54DB3.pidmysql 8699 8286 0 13:48 pts/0 00:00:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/INVIRH54DB3.err --pid-file=/var/lib/mysql/INVIRH54DB3.pid --socket=/var/lib/mysql/mysql.sock --port=3306root 10783 27077 0 14:21 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/etc/my3307.cnf --basedir=/usr --datadir=/var/lib/Instances/INFA1mysql 11191 10783 0 14:21 pts/0 00:00:00 /usr/sbin/mysqld --defaults-file=/etc/my3307.cnf --basedir=/usr --datadir=/var/lib/Instances/INFA1 --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/Instances/INFA1/INVIRH54DB3.err --pid-
  22. 22. file=/var/lib/Instances/INFA1/INVIRH54DB3.pid --socket=/var/lib/Instances/INFA1/mysql3307.sock --port=3307root 11281 27077 0 14:23 pts/0 00:00:00 grep -i mysqlroot 30211 27077 0 10:24 pts/0 00:00:00 /bin/sh /usr/bin/mysqld_safe --defaults-file=/etc/my3308.cnf --basedir=/usr --datadir=/var/lib/Instances/INFA2mysql 30621 30211 0 10:24 pts/0 00:00:03 /usr/sbin/mysqld --defaults-file=/etc/my3308.cnf --basedir=/usr --datadir=/var/lib/Instances/INFA2 --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/Instances/INFA2/INVIRH54DB3.err --pid-file=/var/lib/Instances/INFA2/INVIRH54DB3.pid --socket=/tmp/mysql3308.sock --port=3308Step 17 : Check for the instances running on the machine.[root@INVIRH54DB3 ~]# lsof -i :3306COMMAND PID USER FD TYPE DEVICE SIZE NODE NAMEmysqld 8699 mysql 11u IPv4 385132 TCP *:mysql (LISTEN)[root@INVIRH54DB3 ~]# lsof -i :3307COMMAND PID USER FD TYPE DEVICE SIZE NODE NAMEmysqld 11191 mysql 11u IPv4 387891 TCP *:opsession-prxy (LISTEN)[root@INVIRH54DB3 ~]# lsof -i :3308COMMAND PID USER FD TYPE DEVICE SIZE NODE NAMEmysqld 30621 mysql 11u IPv4 373622 TCP *:tns-server (LISTEN)
  23. 23. Step 18 :UPDATE THE PASSSWORD after login mysql prompt (3307)[root@INVIRH54DB3 ~]# mysql -u root -p -S /tmp/mysql3307.sockEnter password: (Here password is empty)Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 4Server version: 5.5.30-log MySQL Community Server(GPL)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is aregistered trademark of Oracle Corporation and/or itsaffiliates. Other names may betrademarks of their respectiveowners.Type help; or h for help. Type c to clear thecurrent input statement.mysql> use mysql;mysql> UPDATE user SET PASSWORD=PASSWORD(mysql) WHERE USER=root;mysql> FLUSH PRIVILEGES;
  24. 24. Step 19 :UPDATE THE PASSSWORD after login mysql prompt (3308)[root@INVIRH54DB3 ~]# mysql -u root -p -S /tmp/mysql3308.sockEnter password:Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 3Server version: 5.5.30-log MySQL Community Server(GPL)Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other namesmay be trademarks of their respectiveowners.Type help; or h for help. Type c toclear the current input statement.mysql> use mysql;mysql> UPDATE user SET PASSWORD=PASSWORD(mysql) WHERE USER=root;mysql> FLUSH PRIVILEGES;
  25. 25. Useful Links :http://linuxhackadmin.blogspot.in/2013/02/mysql-multiple-instance-installation.htmlhttp://opensourcedbms.com/dbms/running-multiple-mysql-5-6-instances-on-one-server-in-centos-6rhel-6fedora/http://www.ducea.com/2009/01/19/running-multiple-instances-of-mysql-on-the-same-machine/

×