MySQL多實(shí)例配置方案
1.1 什么是Mysql多實(shí)例?
簡(jiǎn)單的說(shuō),Mysql多實(shí)例就是在一臺(tái)服務(wù)器上同時(shí)開(kāi)啟多個(gè)不同的服務(wù)端口(如 : 3306/3307/3308)同時(shí)運(yùn)行多個(gè)Mysql服務(wù)器,這些服務(wù)進(jìn)程通過(guò)不同的socket來(lái)監(jiān)聽(tīng)不同的服務(wù)端口來(lái)提供服務(wù)
這些Mysql多實(shí)例共用一套Mysql安裝程序,使用不同的my.cnf配置文件,啟動(dòng)程序,和數(shù)據(jù)文件,在提供服務(wù)時(shí),多實(shí)例Mysql在邏輯上來(lái)看是各自獨(dú)立的,他們根據(jù)配置文件對(duì)應(yīng)設(shè)定值,獲得服務(wù)器相應(yīng)的資源
1.2 多實(shí)例配置思路:
1. 多套獨(dú)立目錄
2. 每個(gè)實(shí)例有獨(dú)立的數(shù)據(jù)(初始化數(shù)據(jù))
3. 多個(gè)端口
4. 多個(gè)socket
5. 多個(gè)啟動(dòng)程序
6. 多個(gè)日志文件
1.3 多實(shí)例配置過(guò)程:
1.3.1 創(chuàng)建獨(dú)立目錄:
mkdir -p /data/{3307,3308} chown –R mysql.mysql /data
1.3.2 編寫(xiě)每個(gè)實(shí)例的配置文件:
[root@db01 ~]# cat /data/3307/my.cnf [mysqld] basedir=/application/mysql datadir=/data/3307 socket=/data/3307/mysql.sock log-error=/data/3307/mysql.log log_bin=/data/3307/mysql-bin binlog_format=row skip_name_resolve=1 server_id=3307 port=3307
1.3.3 初始化數(shù)據(jù):
./mysql_install_db --defaults-file=/data/3307/my.cnf --basedir=/application/mysql --datadir=/data/3307 --user=mysql
1.3.4 啟動(dòng)實(shí)例:
sh mysqld_safe --defaults-file=/data/3307/my.cnf --pid-file=/data/3307/3307.pid &
shell腳本管理多實(shí)例服務(wù):
#!/bin/bash . /etc/init.d/functions . /etc/profile Start='/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 in start) START ;; stop) STOP ;; restart) RESTART ;; *) echo "Usage: $0 {start|stop|restart}" ;; esac
相關(guān)文章
MySQL更新存放JSON的字段、\“ 轉(zhuǎn)義成 “的問(wèn)題描述
本篇介紹在執(zhí)行MySQL線上變更時(shí)遇到的問(wèn)題,表現(xiàn)為"更新JSON字段時(shí),實(shí)際更新的值與SQL語(yǔ)句中的值不一致,JSON格式錯(cuò)誤",本文給大家分享問(wèn)題描述及解決方案,感興趣的朋友一起看看吧2022-12-12MySQL數(shù)據(jù)庫(kù)之內(nèi)置函數(shù)和自定義函數(shù) function
這篇文章主要介紹了MySQL數(shù)據(jù)庫(kù)之內(nèi)置函數(shù)和自定義函數(shù) function,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,感興趣的小伙伴可以參考一下2022-06-06mysql實(shí)現(xiàn)事務(wù)的提交與回滾的實(shí)例詳解
在本篇文章中我們給大家分享一篇關(guān)于mysql實(shí)現(xiàn)事務(wù)的提交與回滾的實(shí)例內(nèi)容,有需要的朋友們可以參考學(xué)習(xí)下。2020-01-01Windows下mysql community server 8.0.16安裝配置方法圖文教程
這篇文章主要為大家詳細(xì)介紹了Windows下mysql community server 8.0.16安裝配置方法圖文教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-06-06一文帶你了解MySQL之事務(wù)隔離級(jí)別和MVCC
這篇文章主要帶大家詳細(xì)了解一下MySQL之事務(wù)隔離級(jí)別和MVCC,文中有詳細(xì)的代碼示例,具有一定的參考價(jià)值,感興趣的同學(xué)可以借鑒月u的2023-06-06