Linux下MySQL配置單機多例項

svoid發表於2014-07-20

單機多例項可以使用使用mysqld_safe指定配置檔案啟動,但是需要記住很多指定的配置檔案,推薦使用
mysqld_multi來管理多個例項,下面詳細介紹mysqld_multi的用法。

首先需要安裝MySQL

具體安裝過程不介紹了。

配置mysqld_multi的引數檔案

mysqld_multi有預設的模板,按照自己的實際環境修改,與單個例項配置引數檔案基本相同。
檔案主要包含以下內容:

  • 指定通用使用者,用來關閉mysql,確保該使用者有Shutdown_priv許可權,為安全起見,所有例項都建立同一使用者名稱稱密碼指定shutdown許可權。使用mysqld_multi其實就是呼叫mysqladmin來關閉mysql例項。
GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY '123qwe'
  • 指定每個例項mysqld、pid-file、資料檔案路徑、TCP/IP埠及其他mysql特定引數。
檢視自帶模板
shell> mysqld_multi --example
shell> mysqld_multi --example > /etc/my.cnf   
shell> vi /etc/my.cnf  
==============================================
[mysqld_multi]
user       = multi_admin
password   = 123@qwe

[mysqld2]
mysqld     = /db/mysql/mysql_55/bin/mysqld_safe
mysqladmin = /db/mysql/mysql_55/bin/mysqladmin
socket     = /tmp/mysql_3306.sock
port       = 3306
pid-file   = /db/mysql/mysql_55/svoid-a.pid
datadir    = /db/mysql/mysql_55/data
innodb_file_per_table=1
log-bin=mysql_info
server-id=100
user       = mysql

[mysqld3]
mysqld     = /db/mysql/mysql_56/bin/mysqld_safe
mysqladmin = /db/mysql/mysql_56/bin/mysqladmin
socket     = /tmp/mysql_3307.sock
port       = 3307
pid-file   = /db/mysql/mysql_56/svoid-a.pid
datadir    = /db/mysql/mysql_56/data
innodb_file_per_table=1
log-bin=mysql_info
server-id=200
user       = mysql

[mysqld4]
mysqld     = /db/mysql/mysql_57/bin/mysqld_safe
mysqladmin = /db/mysql/mysql_57/bin/mysqladmin
socket     = /tmp/mysql_3308.sock
port       = 3308
pid-file   = /db/mysql/mysql_57/svoid-a.pid
datadir    = /db/mysql/mysql_57/data
innodb_file_per_table=1
log-bin=mysql_info
server-id=300
user       = mysql

mysqld_multi使用方法

顯示mysql啟動狀態
shell> mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld2 is not running
MySQL server from group: mysqld3 is not running
MySQL server from group: mysqld4 is not running

啟動MySQL例項
shell> mysqld_multi start 2-4
shell> mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld2 is running
MySQL server from group: mysqld3 is running
MySQL server from group: mysqld4 is running

停止MySQL例項
shell> mysqld_multi stop 4
shell> mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld2 is running
MySQL server from group: mysqld3 is running
MySQL server from group: mysqld4 is not running


mysqld_multi具體使用方法
shell> mysqld_multi --help

整理自網路

Svoid
2015-05-02

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

相關文章