MySQL啟多個執行個體

來源:互聯網
上載者:User

很多朋友都想在一台伺服器上運行多個MySQL
Instance,究竟怎麼做呢?

首先要明晰幾個原理,
簡稱為mysqld讀取my.cnf的順序:

第一搜,首先讀取/etc/my.cnf,多執行個體這個設定檔不會存在。:-(
第二搜,$datadir/my.cnf,在data目錄下尋找此設定檔。
第三搜,defaultfile=/path/my.cnf
通常寫在命令列上,mysqld_safe defaultfile=/tmp/my.cnf &等執行。
第四搜,~/my.cnf
目前使用者下的設定檔。

mysqld多進程啟動並執行必要條件,就是pid檔案,datadir,socket,port是獨立分開的。
|
Variable_name | Value |
| datadir | /home/mysql/ |
| Variable_name | Value
|
| socket | /home/mysql/mysql.sock |
| Variable_name | Value |
|
pid_file | /home/mysql/mysql.pid |
| Variable_name | Value |
| port | 3306
|

單一版本實現多執行個體
#pwd
/usr/local/
#touch
my_multi.cnf
#cat my_multi.cnf
[mysqld_multi]
mysqld =
/usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = root

[mysqld1]
socket = /tmp/mysql_3301.sock
port = 3301
pid-file =
/usr/local/mysql_3301/data/mysql_3301.pid
datadir =
/usr/local/mysql_3301/data/
log =
/usr/local/mysql_3301/data/mysql_3301.log
user = mysql

[mysqld2]
socket = /tmp/mysql_3302.sock
port = 3302
pid-file =
/usr/local/mysql_3302/data/mysql_3302.pid
datadir =
/usr/local/mysql_3302/data/
log =
/usr/local/mysql_3302/data/mysql_3302.log
user = mysql

啟動mysqld 的兩個執行個體

/usr/bin/mysqld_multi –config-file=./my_multi.cnf start 1,2

Starting mysqld daemon with databases from
/usr/local/mysql_3301/data/
Starting mysqld daemon with databases from
/usr/local/mysql_3302/data/

查看3301,3302連接埠是否被監聽
# netstat -lt |grep 33
tcp 0 0
*:3301 *:* LISTEN
tcp 0 0 *:3302 *:* LISTEN

測試mysql是否可以連通

#pwd
/usr/local/
通過/tmp/mysql_3301.sock串連3001連接埠的mysqld
#
bin/mysql -u root -S /tmp/mysql_3301.sock -e “SELECT
@@VERSION;”
停止3001連接埠的mysqld
# /usr/bin/mysqld_multi
–config-file=./my_multi.cnf stop 1
STOPPING server from pid file
/usr/local/mysql_3301/data/mysql_3301.pid
091010 11:56:04 mysqld
ended
再次串連,系統會提示錯誤
# bin/mysql -u root -S
/tmp/mysql_3301.sock -e “SELECT @@VERSION;”
ERROR 2002 (HY000):
Can’t
connect to local MySQL server through socket ‘/tmp/mysql_3301.sock’
(2)
相同的步驟測試3002連接埠的mysqld,輸出與上面相同。
# /usr/bin/mysql -u
root -S /tmp/mysql_3302.sock -e “SELECT @@VERSION;”
# /usr/bin/mysqld_multi
–config-file=./my_multi.cnf stop 2
# /usr/bin/mysql -u root -S
/tmp/mysql_3302.sock -e “SELECT @@VERSION;”

補充上兩句:
[Nova@imdba.cn mysql]# cp
../mysql-5.0.67/support-files/my-large.cnf /etc/my.cnf
[Nova@imdba.cn mysql]#
cp ../mysql-5.0.67/support-files/mysql.server
/etc/rc.d/init.d/mysqld
[Nova@imdba.cn mysql]# chkconfig –add
mysql
[Nova@imdba.cn mysql]# chkconfig –level mysql 345 on
[Nova@imdba.cn
mysql]# chkconfig –list mysql

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.