MySQL多執行個體配置

來源:互聯網
上載者:User

標籤: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 /data
1.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多執行個體配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.