Running multiple instances of MySQLIt’s reasonably easy to run multiple instances of MySQL with the mysqld_multibash scrip...
## This is for a system with little memory (32M - 64M) where MySQL plays# an important part, or systems up to 128M where M...
datadir = /var/lib/mysqlpid-file = /var/lib/mysql/mysqld.pidsocket = /var/lib/mysql/mysql.sockuser = mysqllog-error = /var...
# binary logging is required for replicationlog-bin=mysql-bin# binary logging format - mixed recommendedbinlog_format=mixe...
# overridden by the content of the master.info file, unless you shutdown# the slave server, delete master.info and restart...
# Set .._log_file_size to 25 % of buffer pool size#innodb_log_file_size = 5M#innodb_log_buffer_size = 8M#innodb_flush_log_...
Next create all the required directories on your system.[root@INVIRH54DB2 ~]# sudomkdir /var/lib/instances[root@INVIRH54DB...
after that we need to install second instance :[root@INVIRH54DB2 ~]# mysqld_multi start[root@INVIRH54DB2 ~]# mysqld_multi ...
[root@INVIRH54DB2 ~]# mysql -uroot -p -S/var/lib/instances/mysqld2/mysql.sockEnter password:Welcome to the MySQL monitor. ...
when u r connecting from your system .u need to give the socket file ..if clients connect to the system ..they will mentio...
this command should be fired from another box on which mysql_client isavailableFolder conatains :[root@INVIRH54DB2 mysqld2...
mysql> show global variables like %port%;+---------------------+-------+| Variable_name | Value |+---------------------+--...
owners.Server version 5.5.30Protocol version 10Connection Localhost via UNIX socketUNIX socket /var/lib/mysql/mysql.sockUp...
Multiple instances second method
Upcoming SlideShare
Loading in …5
×

Multiple instances second method

2,602 views
2,538 views

Published on

Creating Multiple instances on linux

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

No Downloads
Views
Total views
2,602
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Multiple instances second method

  1. 1. Running multiple instances of MySQLIt’s reasonably easy to run multiple instances of MySQL with the mysqld_multibash script. This can be really useful in development environments where youneed to give several developers their own instance. To install multiple MicrosoftSQL Server instances we have to get the install DVD and go through a laboriousseries of wizards. MySQL makes this easy with a few configuration files changes.In this example I’m going to outline how to configure 2 instances of MySQL bycloning an existing single instance.Login to your existing mysql instance and run the below statement to create auser.GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY mysql;FLUSH PRIVILEGES;The mysqld_multi script needs this user, on each instance, to function correctly.This user only needs the SHUTDOWN privilege.If you already have an instance of MySQL running then you’ll want to shut it downbefore beginning. You can do this at the command prompt with…[root@INVIRH54DB2 ~]# service mysql stopNext we need to edit the my.cnf file.First we need to comment out a few lines in the mysqld section.[root@INVIRH54DB2 ~]# cat /etc/my.cnf# Example MySQL config file for medium systems.
  2. 2. ## This is for a system with little memory (32M - 64M) where MySQL plays# an important part, or systems up to 128M where MySQL is used together with# other programs (such as a web server)## MySQL programs look for option files in a set of# locations which depend on the deployment platform.# You can copy this option file to one of those# locations. For information about these locations, see:# http://dev.mysql.com/doc/mysql/en/option-files.html## In this file, you can use all long options that a program supports.# If you want to know which options a program supports, run the program# with the "--help" option.# The following options will be passed to all MySQL clients[client]password = your_password#port = 3306#socket = /var/lib/mysql/mysql.sock# Here follows entries for some specific programs# The MySQL server[mysqld]#port = 3306#socket = /var/lib/mysql/mysql.sock[mysqld_multi]mysqld = /usr/bin/mysqld_safe # location MySQL binarymysqladmin = /usr/bin/mysqladminlog = /var/log/mysqld_multi.loguser = multi_adminpassword = mysql[mysqld1]port = 3306
  3. 3. datadir = /var/lib/mysqlpid-file = /var/lib/mysql/mysqld.pidsocket = /var/lib/mysql/mysql.sockuser = mysqllog-error = /var/log/mysql1.err[mysqld2]port = 3307datadir = /var/lib/instances/mysqld2pid-file = /var/lib/instances/mysqld2/mysql.pidsocket = /var/lib/instances/mysqld2/mysql.sockuser = mysqllog-error = /var/log/mysql2.errskip-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# Dont listen on a TCP/IP port at all. This can be a security enhancement,# if all processes that need to connect to mysqld run on the same host.# All interaction with mysqld must be made via Unix sockets or named pipes.# Note that using this option without enabling named pipes on Windows# (via the "enable-named-pipe" option) will render mysqld useless!##skip-networking# Replication Master Server (default)
  4. 4. # binary logging is required for replicationlog-bin=mysql-bin# binary logging format - mixed recommendedbinlog_format=mixed# required unique id between 1 and 2^32 - 1# defaults to 1 if master-host is not set# but will not function as a master if omittedserver-id = 1# Replication Slave (comment out master section to use this)## To configure this host as a replication slave, you can choose between# two methods :## 1) Use the CHANGE MASTER TO command (fully described in our manual) -# the syntax is:## CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,# MASTER_USER=<user>, MASTER_PASSWORD=<password> ;## where you replace <host>, <user>, <password> by quoted strings and# <port> by the masters port number (3306 by default).## Example:## CHANGE MASTER TO MASTER_HOST=125.564.12.1, MASTER_PORT=3306,# MASTER_USER=joe, MASTER_PASSWORD=secret;## OR## 2) Set the variables below. However, in case you choose this method, then# start replication for the first time (even unsuccessfully, for example# if you mistyped the password in master-password and the slave fails to# connect), the slave will create a master.info file, and any later# change in this file to the variables values below will be ignored and
  5. 5. # overridden by the content of the master.info file, unless you shutdown# the slave server, delete master.info and restart the slaver server.# For that reason, you may want to leave the lines below untouched# (commented) and instead use CHANGE MASTER TO (see above)## required unique id between 2 and 2^32 - 1# (and different from the master)# defaults to 2 if master-host is set# but will not function as a slave if omitted#server-id = 2## The replication master for this slave - required#master-host = <hostname>## The username the slave will use for authentication when connecting# to the master - required#master-user = <username>## The password the slave will authenticate with when connecting to# the master - required#master-password = <password>## The port the master is listening on.# optional - defaults to 3306#master-port = <port>## binary logging - not required for slaves, but recommended#log-bin=mysql-bin# Uncomment the following if you are using InnoDB tables#innodb_data_home_dir = /var/lib/mysql#innodb_data_file_path = ibdata1:10M:autoextend#innodb_log_group_home_dir = /var/lib/mysql# You can set .._buffer_pool_size up to 50 - 80 %# of RAM but beware of setting memory usage too high#innodb_buffer_pool_size = 16M#innodb_additional_mem_pool_size = 2M
  6. 6. # Set .._log_file_size to 25 % of buffer pool size#innodb_log_file_size = 5M#innodb_log_buffer_size = 8M#innodb_flush_log_at_trx_commit = 1#innodb_lock_wait_timeout = 50[mysqldump]quickmax_allowed_packet = 16M[mysql]no-auto-rehash# Remove the next comment character if you are not familiar with SQL#safe-updates[myisamchk]key_buffer_size = 20Msort_buffer_size = 20Mread_buffer = 2Mwrite_buffer = 2M[mysqlhotcopy]interactive-timeout
  7. 7. Next create all the required directories on your system.[root@INVIRH54DB2 ~]# sudomkdir /var/lib/instances[root@INVIRH54DB2 ~]# sudomkdir /var/lib/instances/mysqld2[root@INVIRH54DB2 ~]# sudomkdir /var/lib/instances/mysqlCopy the mysql database files from the original instance to the second instancesdatabase directory. Then this instance will have all of the same users as instance1.[root@INVIRH54DB2 ~]# sudocp -r /var/lib/mysql/mysql//var/lib/instances/mysqld2/mysqlYou can also copy across any other databases you want the new server to host.Change the owner of the data directory to the mysql user so the instance canread them.[root@INVIRH54DB2 ~]# sudochown -R mysql:mysql /var/lib/instances/
  8. 8. after that we need to install second instance :[root@INVIRH54DB2 ~]# mysqld_multi start[root@INVIRH54DB2 ~]# mysqld_multi reportReporting MySQL serversMySQL server from group: mysqld1 is runningMySQL server from group: mysqld2 is running[root@INVIRH54DB2 ~]# mysqld_multi start[root@INVIRH54DB2 ~]# mysqld_multi reportReporting MySQL serversMySQL server from group: mysqld1 is runningMySQL server from group: mysqld2 is runningProcess checking :[root@INVIRH54DB2 ~]# ps -auxf | grepmysqlConnect to second instance like port 3307
  9. 9. [root@INVIRH54DB2 ~]# mysql -uroot -p -S/var/lib/instances/mysqld2/mysql.sockEnter password:Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 15Server version: 5.5.30-log MySQL Community Server (GPL)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 | 3307 || report_host | || report_password | || report_port | 3307 || report_user | |+---------------------+-------+7 rows in set (0.00 sec)
  10. 10. when u r connecting from your system .u need to give the socket file ..if clients connect to the system ..they will mention the port ..3307client cant connect with root user ..u need to create a user ..and give therequired grants ..root is only for the admin.suppose the client is connecting from say an ip 192.168.1.77,then u need give thegrant like ...grant all on db_name.* to user_name@192.168.1.% identified bysome_password ;flush privileges;following command is user for connection from clients :mysql -usome_user -psome_password -hdb_ip -P 3307
  11. 11. this command should be fired from another box on which mysql_client isavailableFolder conatains :[root@INVIRH54DB2 mysqld2]# ls -ltrtotal 28736drwx--x--x 2 mysqlmysql 4096 May 28 15:05 mysql-rw-rw---- 1 mysqlmysql 5242880 May 28 15:06 ib_logfile1srwxrwxrwx 1 mysqlmysql 0 May 28 15:06 mysql.sock-rw-rw---- 1 mysqlmysql 6 May 28 15:06 mysql.pid-rw-rw---- 1 mysqlmysql 19 May 28 15:06 mysql-bin.index-rw-rw---- 1 mysqlmysql 5242880 May 28 15:06 ib_logfile0-rw-rw---- 1 mysqlmysql 18874368 May 28 15:06 ibdata1-rw-rw---- 1 mysqlmysql 436 May 28 17:39 mysql-bin.000001For connecting 3306[root@INVIRH54DB2 ~]# mysql -u root -pEnter password:Welcome to the MySQL monitor. Commands end with ; or g.Your MySQL connection id is 14Server version: 5.5.30 MySQL Community Server (GPL)Type help; or h for help. Type c to clear the current input statement.
  12. 12. 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)[root@INVIRH54DB2 bin]# ./mysqladmin version -u root -pEnter password:./mysqladminVer 8.42 Distrib 5.5.30, for Linux on x86_64Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respective
  13. 13. owners.Server version 5.5.30Protocol version 10Connection Localhost via UNIX socketUNIX socket /var/lib/mysql/mysql.sockUptime: 2 days 2 hours 46 min 49 secThreads: 1 Questions: 31 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables:26 Queries per second avg: 0.000

×