大家有沒有遇到在一台機器裝好多mysqld呢?如果有,那大家一般是怎麼做呢?是不是也像我以前,編譯很多mysql,放在不同的目錄下,然後一個個的啟動呢?如果是這樣,那我強烈推薦使用mysqld_multi,這個可以迅速的配置N個mysqld。
步驟如下:
1) 先在服務器上裝一mysqld,啟動,配置好mysql用戶
2) Copy data目錄下的mysql 庫到准備新開的mysql服務器(可以是N個)
3) 配置mysqld_multi
具體的配置可以參照./mysqld_multi –example
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = yt
password = yangting
[mysqld1]
datadir=/usr/local/mysql/data/
basedir=/usr/local/mysql
port = 3306
socket = /tmp/mysql.sock
[mysqld2]
datadir=/usr/local/mysql/data2/
basedir=/usr/local/mysql
port = 3307
socket = /tmp/mysql1.sock
pid-file=/usr/local/mysql/data2/mysql2.pid
default-storage-engine=innodb
[mysql]
prompt=mysql--\\u@\\h:\\d \\r:\\m:\\s>>
4)啟動與關閉
./mysqld_multi --log=/usr/local/mysql/data2/yt.err start
./mysqld_multi --log=/usr/local/mysql/data2/yt.err stop
還可以mysqld_multi --log=/usr/local/mysql/data2/yt.err start 1,3-10 start 來啟動
也可以./mysqld_multi --log=/usr/local/mysql/data2/yt.err stop 2 來關閉第二個
注意:一定要在起來後,確定每個server上有mysqld_mult需要的用戶及密碼,且必須是localhost
GRANT SHUTDOWN ON *.* TO 'yt'@'localhost' IDENTIFIED BY 'yangting';
否則不能stop
作者“sky-鵬”