mysqld_multi部署單機(jī)詳細(xì)說明
發(fā)表時間:2023-07-14 來源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]這次給大家?guī)韒ysqld_multi部署單機(jī)詳解,mysqld_multi部署單機(jī)的注意事項(xiàng)有哪些,下面就是實(shí)戰(zhàn)案例,一起來看一下。前言大家應(yīng)該都有所體會,隨著硬件層面的發(fā)展,linux系統(tǒng)多核已...
這次給大家?guī)韒ysqld_multi部署單機(jī)詳解,mysqld_multi部署單機(jī)的
注意事項(xiàng)有哪些,下面就是實(shí)戰(zhàn)案例,一起來看一下。
前言
大家應(yīng)該都有所體會,隨著硬件層面的發(fā)展,linux系統(tǒng)多核已經(jīng)是普通趨勢,而mysql是單進(jìn)程多線程,所以先天上對多進(jìn)程的利用不是很高,雖然5.6版本已經(jīng)在這方面改進(jìn)很多,但是也沒有達(dá)到100%,所以為了充分的利用系統(tǒng)資源,mysql有自己的補(bǔ)充,那就是可以部署多實(shí)例,一個實(shí)例一個端口。
mysqld_multi設(shè)計用于管理在同一臺機(jī)器上運(yùn)行的多個mysqld進(jìn)程,這些進(jìn)程使用不同的socket文件并監(jiān)聽在不同的端口上。mysqld_multi可以批量啟動、關(guān)閉、或者報告這些mysqld進(jìn)程的狀態(tài)。
下面話不多說了,來一起看看詳細(xì)的介紹吧。
一、mysql編譯安裝:
cd /usr/local/src
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
cd /usr/local/mysql
useradd mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
二、準(zhǔn)備第一個多實(shí)例3307
2.1 創(chuàng)建目錄:
mkdir /usr/local/mysql3307
chown -R mysql.mysql /usr/local/mysql3307/
mkdir -p /data/mysql3307
chown -R mysql.mysql /data/mysql3307
mkdir -p /home/data/mysql3307/binlog
chown -R mysql.mysql /home/data/mysql3307
2.2 配置文件
[root@zhdya01 ~]# vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin =/usr/local/mysql/bin/mysqladmin
log =/var/log/mysqld_multi.log
[mysqld1]
socket = /usr/local/mysql3307/mysql.sock
port = 3307
pid-file = /usr/local/mysql3307/mysql.pid
datadir = /data/mysql3307
log_bin=/home/data/mysql3307/binlog
server-id = 1
innodb_buffer_pool_size = 128M
innodb_flush_log_at_trx_commit = 0
2.3 初始化數(shù)據(jù)庫
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql3307
三、準(zhǔn)備第二個多實(shí)例3308
3.1 創(chuàng)建目錄:
mkdir /usr/local/mysql3308
chown -R mysql.mysql /usr/local/mysql3308/
mkdir -p /data/mysql3308
chown -R mysql.mysql /data/mysql3308
mkdir -p /home/data/mysql3308/binlog
chown -R mysql.mysql /home/data/mysql3308
3.2 配置文件
[root@zhdya01 ~]# vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin =/usr/local/mysql/bin/mysqladmin
log =/var/log/mysqld_multi.log
[mysqld1]
socket = /usr/local/mysql3307/mysql.sock
port = 3307
pid-file = /usr/local/mysql3307/mysql.pid
datadir = /data/mysql3307
log_bin=/home/data/mysql3307/binlog
server-id = 1
innodb_buffer_pool_size = 128M
innodb_flush_log_at_trx_commit = 0
[mysqld2]
socket = /usr/local/mysql3308/mysql.sock
port = 3308
pid-file = /usr/local/mysql3308/mysql.pid
datadir = /data/mysql3308
log_bin=/home/data/mysql3308/binlog
server-id = 2
innodb_buffer_pool_size = 128M
innodb_flush_log_at_trx_commit = 0
3.3 初始化數(shù)據(jù)庫
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql3308
四、啟動多實(shí)例
/etc/init.d/mysqld start
mysqld_multi --defaults-extra-file=/etc/my.cnf start 1,2
[root@zhdya01 bin]# !net
netstat -lntp -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1241/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2087/master
tcp6 0 0 :::3306 :::* LISTEN 4406/mysqld
tcp6 0 0 :::3307 :::* LISTEN 4197/mysqld
tcp6 0 0 :::3308 :::* LISTEN 3359/mysqld
tcp6 0 0 :::8080 :::* LISTEN 2222/java
tcp6 0 0 :::22 :::* LISTEN 1241/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2087/master
五、查看啟動狀態(tài)
[root@zhdya01 bin]# mysqld_multi --defaults-extra-file=/etc/my.cnf report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
六、停止多實(shí)例
[root@zhdya01 bin]# mysqld_multi --defaults-extra-file=/etc/my.cnf stop 1,2
[root@zhdya01 bin]# mysqld_multi --defaults-extra-file=/etc/my.cnf report
Reporting MySQL servers
MySQL server from group: mysqld1 is not running
MySQL server from group: mysqld2 is not running
七、各自登錄mysql實(shí)例
[root@zhdya01 bin]# mysql --socket=/usr/local/mysql3307/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.35-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights 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>
相信看了本文案例你已經(jīng)掌握了方法,更多精彩請關(guān)注php中文網(wǎng)其它相關(guān)文章!
推薦閱讀:
怎樣用一條SQL語句查詢不同的數(shù)據(jù)庫
在Bootstrap怎么操作表格
小程序的Promise簡化回調(diào)
以上就是mysqld_multi部署單機(jī)詳解的詳細(xì)內(nèi)容,更多請關(guān)注php中文網(wǎng)其它相關(guān)文章!
學(xué)習(xí)教程快速掌握從入門到精通的SQL知識。