mysqld_multi啟動多個mysql例項

jx_yu發表於2015-01-29

         可以管理多個幀聽不同Unix套接字檔案和TCP/IP埠的連線的mysqld 程式。它可以啟動或停止伺服器,或報告它們的當前狀態。

         即可以管理多個例項。

        

         之前使用mysql_safe啟用多例項的方法,啟動和關閉都指定配置檔案,例項間是對立的,互不影響。成功的部署了多個例項主從Replication

        

         mysql_multi多例項管理,配置簡單,方便管理。

clip_image001說明





 

 

        

實戰

1.配置my.cnf檔案

 ~]# cat /etc/my.cnf

[mysqld_multi]

 mysqld = /usr/bin/mysqld_safe #根據自己的mysql目錄配置,使用which command可以查詢路徑

 mysqladmin = /usr/bin/mysqladmin

 

[mysqld]             #之前已經正常使用的mysql例項

 basedir=/usr

 datadir = /data/mysql

 port = 3306

 server_id = 2

 socket = /tmp/mysql3306.sock

 skip-host-cache

 skip-name-resolve

 character-set-server=utf8

 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

[client]

 socket=/tmp/mysql3306.sock      #配置client預設使用的scoket檔案

 

#mysqld1mysqld2是使用mysqld_multi啟動的多個例項

[mysqld1] 

 basedir=/usr

 datadir = /data/mysql1      

 port = 3307

 server_id = 3

 socket = /tmp/mysql3307.sock

 skip-host-cache

 skip-name-resolve

 character-set-server=utf8

 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

 

[mysqld2]

 basedir=/usr

 datadir = /data/mysql2

 port = 3308

 server_id = 3

 socket = /tmp/mysql3308.sock

 skip-host-cache

 skip-name-resolve

 character-set-server=utf8

 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

注:配置檔案中其他的引數跟正常的mysqld下一樣 根據實際需要設定即可

2.複製mysqld的檔案到mysqld1mysqld2對應的datadir

~]# cp -pr /data/mysql /data/mysql1

~]# cp -pr /data/mysql /data/mysql2

3.啟動mysqld1mysqld2例項--使用mysqld_multi

~]# mysqld_multi start 1

~]# mysqld_multi start 2

 

Usage: mysqld_multi [OPTIONS] {start|reload|stop|report} [GNR,GNR,GNR...]

or     mysqld_multi [OPTIONS] {start|reload|stop|report} [GNR-GNR,GNR,GNR-GNR,...]

4.啟動預設的mysql例項--使用/etc/init.d/mysql start

~]# /etc/init.d/mysql start

Starting MySQL.                                            [  OK  ]

5.檢視已經啟動的mysql例項

~]# netstat -ntpl|grep 330

tcp        0      0 :::3306                 :::*                        LISTEN      6643/mysqld        

tcp        0      0 :::3307                 :::*                        LISTEN      5667/mysqld        

tcp        0      0 :::3308                 :::*                        LISTEN      5666/mysqld     

至此可以看到 在一臺機器上啟動了3個例項

6.連線不同的例項,用port區分

 ~]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 6

Server version: 5.6.11 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 its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> Ctrl-C -- exit!

Aborted

~]# mysql -uroot -p -P3307

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 7

Server version: 5.6.11 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 its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql> Ctrl-C -- exit!

Aborted

~]# mysql -uroot -p -P3308

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 5.6.11 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 its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

mysql>

 

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27000195/viewspace-1419251/,如需轉載,請註明出處,否則將追究法律責任。

相關文章