為什麼資料庫要配置多例項呢?
主要的原因是因為資料庫是單程序多執行緒的服務,為了最大可能的利用資源,所以配置多例項
具體的配置方法如下:
第一步:生成多例項的目錄
mkdir /data/330/data -p
第二步:準備多個配置檔案
[root@mysql02 local]# vim /data/3307/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/data/3307/data
socket=/data/3307/mysql.sock
port=3307
log-error=/data/3307/mysql.log
log_bin=/data/3307/mysql-bin
binlog_format=row
skip-name-resolve
server-id=7
[root@mysql02 local]# vim /data/3308/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/data/3308/data
socket=/data/3308/mysql.sock
port=3308
log_bin=/data/3308/mysql-bin
log-error=/data/3308/mysql.log
binlog_format=row
skip-name-resolve
server-id=8
[root@mysql02 local]# vim /data/3309/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/data/3309/data
socket=/data/3309/mysql.sock
port=3309
log-error=/data/3309/mysql.log
log_bin=/data/3309/mysql-bin
binlog_format=row
skip-name-resolve
server-id=9
第三步:初始化三套資料:
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/3307/data
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/3308/data
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/3309/data
第四步:建立日誌檔案,並修改許可權:
touch /data/330/mysql.log
[root@mysql02 local]# vim /etc/systemd/system/mysqld3307.service
[unit]
description=mysql server
documentation=man:mysqld(8)
documentation=
after=network.target
after=syslog.target
[install]
wantedby=multi-user.target
[service]
user=mysql
group=mysql
execstart=/usr/local/mysql/bin/mysqld
--defaults-file=/data/3307/my.cnf
limitnofile = 5000
[root@mysql02 local]# vim /etc/systemd/system/mysqld3308.service
[unit]
description=mysql server
documentation=man:mysqld(8)
documentation=
after=network.target
after=syslog.target
[install]
wantedby=multi-user.target
[service]
user=mysql
group=mysql
execstart=/usr/local/mysql/bin/mysqld --defaults-file=/data/3308/my.cnf
limitnofile = 5000
[root@mysql02 local]# vim /etc/systemd/system/mysqld3309.service
[unit]
description=mysql server
documentation=man:mysqld(8)
documentation=
after=network.target
after=syslog.target
[install]
wantedby=multi-user.target
[service]
user=mysql
group=mysql
execstart=/usr/local/mysql/bin/mysqld
--defaults-file=/data/3309/my.cnf
limitnofile = 5000
第六步:加入開機自啟動,並啟動mysql多例項的服務
systemctl enable mysql3307.service
systemctl enable mysql3308.service
systemctl enable mysql3309.service
systemctl start mysql3307
systemctl start mysql3308
systemctl start mysql3309
systemctl status mysql3307
systemctl status mysql3308
systemctl status mysql3309
第七步:檢視埠
[root@mysql02 local]# ss -luntp|grep 33
tcp listen 0
80 :::3306 :::*
users:(("mysqld",pid=25300,fd=15))
tcp listen 0
80 :::3307 :::* users:(("mysqld",pid=30400,fd=22))
tcp listen 0
80 :::3308 :::*
users:(("mysqld",pid=30435,fd=22))
tcp listen 0
80 :::3309 :::* users:(("mysqld",pid=30470,fd=22))
第八步:測試
[root@mysql02 local]# mysql -s /data/3307/mysql.sock
welcome to the mysql monitor.
commands end with ; or \g.
your mysql connection id is 4
server version: 5.7.20-log source distribution
reserved.
oracle is a registered trademark of oracle corporation and/or its
affiliates. other names may be trademarks of their respective
owners.
type 'help;' or '\h' for help. type '\c' to clear the current input
statement.
mysql>
配置一定要注意將許可權全部修改為mysql,並建立日誌檔案,否則無法啟動。希望對大家有所幫助,筆芯!!!
centos 安裝多例項資料庫
centos 安裝多例項資料庫 2019年11月19日 19 05 一 安裝資料庫,可以編譯安裝,二進位制安裝,yum安裝等 二 準備三個例項目錄 mkdir pv mysql chown r mysql.mysql mysql 三 生成資料庫檔案 如果是二進位制安裝,則需要確定mysql inst...
部署多例項的MySQL資料庫
部署多例項的mysql資料庫,將data.zip上傳到伺服器 目錄下 1 mkdir pv data data 2 cd unzip data.zip archive data.zip inflating data 3306 my.cnf inflating data 3306 mysql infl...
centos 安裝多例項資料庫
編寫安裝指令碼 bin bash basemysqldir usr local tarspkg mysql 5.7.22 linux glibc2.12 x86 64 yuminstall mysql devel 建立 mysql 軟鏈結 ln s usr local mysql 建立 mysql ...