以下的文章主要是向大家介紹的是使用mysqld_multi來對多個MySQL數據庫實例進行管理的實際操作流程,MySQL數據庫是可以多主一從的來進行實時備份,在google下可以使用mysqld_multi來管理多個MySQL實例。
之前有想過在一台服務器上運行多個MySQL實例就可以實現一從多主的master-slave方式的實時備份,今天剛好看到mysqld-multi就動手測試下配置過程如下,
1. 修改mysql的配置文件my.cnf配置mysqld_multi的選項
- [mysqld_multi]
- mysqld = /usr/local/mysql/bin/mysqld_safe
- mysqladmin = /usr/local/mysql/bin/mysqladmin
- user = multi_admin
- password = multipass
- log = /usr/local/mysql/etc/mysqld_multi.log
2. 創建mysqld_multi的config-file
- cat /usr/local/mysql/etc/mysqld_multi.cnf
- [mysqld1]
- socket = /tmp/mysql.sock1
- port = 3306
- pid-file = /usr/local/mysql/var1/localhost.pid
- datadir = /usr/local/mysql/var1
- user = mysql
- [mysqld2]
- socket = /tmp/mysql.sock2
- port = 3307
- pid-file = /usr/local/mysql/var2/localhost.pid
- datadir = /usr/local/mysql/var2
- user = mysql
- [mysqld3]
- socket = /tmp/mysql.sock3
- port = 3308
- pid-file = /usr/local/mysql/var3/localhost.pid
- datadir = /usr/local/mysql/var3
- user = mysql
3. 拷貝mysqld_multi.server在源代碼的support-files中)腳本到/usr/sbin
- cp /mysql_source/support-files/mysqld_multi.server /usr/sbin
4. 編輯/usr/sbin/mysqld_multi.server(添加–config-file=/usr/local/mysql/etc/mysqld_multi.cnf選項)
- 'start' )
- "$mysqld_multi" start $2
- ;;
- 'stop' )
- "$mysqld_multi" --config-file=/usr/local/mysql/etc/mysqld_multi.cnf stop $2
- ;;
- 'report' )
- "$mysqld_multi" --config-file=/usr/local/mysql/etc/mysqld_multi.cnf report $2
5. 啟動多個MySQL數據庫實例
- mysqld_multi.server start
6. 之前在my.cnf設置的user和password是用來關閉數據庫實例的,根據配置中的用戶名和密碼授權該用戶shutdown權限
- mysql -u root -S /tmp/mysql.sock1 -p
- mysql> grant shutdown on *.* to multi_admin@'localhost' identified by 'multipass';
7. 關閉所有數據庫實例
- mysqld_multi.server stop
8. 對單台數據庫的啟動和關閉
語法:mysqld_multi [options] {start|stop|report} [GNR[,GNR] …]
如對mysqld1的啟動和關閉,可以通過mysqld_multi來操作
啟動: mysqd_multi start 1
關閉: mysqd_multi stop 1
也可以同時啟動和關閉多個MySQL數據庫實例
啟動: mysqd_multi start 1-3
關閉: mysqd_multi stop 1-3