WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
Multiple instances second method
1. Running multiple instances of MySQL
It’s reasonably easy to run multiple instances of MySQL with the mysqld_multi
bash script. This can be really useful in development environments where you
need to give several developers their own instance. To install multiple Microsoft
SQL Server instances we have to get the install DVD and go through a laborious
series 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 by
cloning an existing single instance.
Login to your existing mysql instance and run the below statement to create a
user.
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 down
before beginning. You can do this at the command prompt with…
[root@INVIRH54DB2 ~]# service mysql stop
Next 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. #
# 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 binary
mysqladmin = /usr/bin/mysqladmin
log = /var/log/mysqld_multi.log
user = multi_admin
password = mysql
[mysqld1]
port = 3306
3. datadir = /var/lib/mysql
pid-file = /var/lib/mysql/mysqld.pid
socket = /var/lib/mysql/mysql.sock
user = mysql
log-error = /var/log/mysql1.err
[mysqld2]
port = 3307
datadir = /var/lib/instances/mysqld2
pid-file = /var/lib/instances/mysqld2/mysql.pid
socket = /var/lib/instances/mysqld2/mysql.sock
user = mysql
log-error = /var/log/mysql2.err
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
character_set_server = utf8
collation_server = utf8_general_ci
# Don't 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. # binary logging is required for replication
log-bin=mysql-bin
# binary logging format - mixed recommended
binlog_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 omitted
server-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 master's 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. # 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. # 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]
quick
max_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 = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
7.
8. 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/mysql
Copy the mysql database files from the original instance to the second instances
database directory. Then this instance will have all of the same users as instance
1.
[root@INVIRH54DB2 ~]# sudocp -r /var/lib/mysql/mysql/
/var/lib/instances/mysqld2/mysql
You 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 can
read them.
[root@INVIRH54DB2 ~]# sudochown -R mysql:mysql /var/lib/instances/
9. after that we need to install second instance :
[root@INVIRH54DB2 ~]# mysqld_multi start
[root@INVIRH54DB2 ~]# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
[root@INVIRH54DB2 ~]# mysqld_multi start
[root@INVIRH54DB2 ~]# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
Process checking :
[root@INVIRH54DB2 ~]# ps -auxf | grepmysql
Connect to second instance like port 3307
10. [root@INVIRH54DB2 ~]# mysql -uroot -p -S
/var/lib/instances/mysqld2/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 15
Server 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)
11. 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 ..3307
client can't connect with root user ..u need to create a user ..and give the
required grants ..
root is only for the admin.
suppose the client is connecting from say an ip 192.168.1.77,then u need give the
grant like ...
grant all on db_name.* to 'user_name'@'192.168.1.%' identified by
'some_password' ;
flush privileges;
following command is user for connection from clients :
mysql -usome_user -psome_password -h'db_ip' -P 3307
12. this command should be fired from another box on which mysql_client is
available
Folder conatains :
[root@INVIRH54DB2 mysqld2]# ls -ltr
total 28736
drwx--x--x 2 mysqlmysql 4096 May 28 15:05 mysql
-rw-rw---- 1 mysqlmysql 5242880 May 28 15:06 ib_logfile1
srwxrwxrwx 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.000001
For connecting 3306
[root@INVIRH54DB2 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 14
Server version: 5.5.30 MySQL Community Server (GPL)
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
13. 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 -p
Enter password:
./mysqladminVer 8.42 Distrib 5.5.30, for Linux on x86_64
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
14. owners.
Server version 5.5.30
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 2 days 2 hours 46 min 49 sec
Threads: 1 Questions: 31 Slow queries: 0 Opens: 33 Flush tables: 1 Open tables:
26 Queries per second avg: 0.000