標籤:mysql多執行個體
第1章 MySQL多執行個體配置:1.1 什麼是Mysql多執行個體?
簡單的說,Mysql多執行個體就是在一台伺服器上同時開啟多個不同的服務連接埠(如 : 3306/3307/3308)同時運行多個Mysql伺服器,這些服務進程通過不同的socket來監聽不同的服務連接埠來提供服務
這些Mysql多執行個體共用一套Mysql安裝程式,使用不同的my.cnf設定檔,啟動程式,和資料檔案,在提供服務時,多執行個體Mysql在邏輯上來看是各自獨立的,他們根據設定檔對應設定值,獲得伺服器相應的資源
1.2 多執行個體配置思路:
1. 多套獨立目錄
2. 每個執行個體有獨立的資料(初始化資料)
3. 多個連接埠
4. 多個socket
5. 多個啟動程式
6. 多個記錄檔
1.3 多執行個體配置過程:1.3.1 建立獨立目錄:
mkdir -p /data/{3307,3308}chown –R mysql.mysql /data1.3.2 編寫每個執行個體的設定檔:
[[email protected] ~]# cat /data/3307/my.cnf[mysqld]basedir=/application/mysqldatadir=/data/3307socket=/data/3307/mysql.socklog-error=/data/3307/mysql.loglog_bin=/data/3307/mysql-binbinlog_format=rowskip_name_resolve=1server_id=3307port=3307
1.3.3 初始化資料:
./mysql_install_db --defaults-file=/data/3307/my.cnf --basedir=/application/mysql --datadir=/data/3307 --user=mysql
1.3.4 啟動執行個體:
sh mysqld_safe --defaults-file=/data/3307/my.cnf --pid-file=/data/3307/3307.pid &
shell指令碼管理多執行個體服務:
#!/bin/bash. /etc/init.d/functions. /etc/profileStart='/application/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf --pid-file=/data/3307/3307.pid'Stop='mysqladmin -uroot -S /data/3307/mysql.sock shutdown'Port=`ss -tunlp|grep 3307|wc -l`function START(){ if [ $Port -ne 1 ];then $Start >/dev/null 2>&1 & sleep 3 if [ $? -eq 0 ];then action 'MySQL 3307 Starting' /bin/true fi else action 'MySQL 3307 Already Exists' /bin/true fi}function STOP(){ if [ $Port -ne 0 ];then $Stop if [ $? -eq 0 ];then action 'MySQL Stoping Successfuly' /bin/true fi else action 'MySQL already Stoped' /bin/true fi}function RESTART(){ STOP sleep 1 START}case $1 instart) START ;;stop) STOP ;;restart) RESTART ;;*) echo "Usage: $0 {start|stop|restart}" ;;esac
MySQL多執行個體配置