佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > Linux下MySQL多實例部署及安裝指南

Linux下MySQL多實例部署及安裝指南

熱門標(biāo)簽:鐵路電話系統(tǒng) 地方門戶網(wǎng)站 AI電銷 Linux服務(wù)器 百度競價排名 呼叫中心市場需求 網(wǎng)站排名優(yōu)化 服務(wù)外包

什么是MySQL多實例

  • 簡單地說,Mysql多實例就是在一臺服務(wù)器上同時開啟多個不同的服務(wù)端口(3306、3307),同時運行多個Mysql服務(wù)進程,這些服務(wù)進程通過不同的socket監(jiān)聽不同的服務(wù)端口來提供服務(wù)。
  • 這些Mysql多實例公用一套Mysql安裝程序,使用不同的my.cnf(也可以相同)配置文件,啟動程序(也可以相同)和數(shù)據(jù)文件。在提供服務(wù)時,多實例 Mysql在邏輯上看來是各自獨立的,它們根據(jù)配置文件的對應(yīng)設(shè)定值,獲得服務(wù)器相應(yīng)數(shù)量的硬件資源。
  • 打個比方,Mysql多實例就相當(dāng)于房子的多個臥室,每個實例可以看作一間臥室,整個服務(wù)器就是一套房子,服務(wù)器的硬件資源(cpu、mem、disk)、軟件資源(centos操作系統(tǒng))可以看作房子的衛(wèi)生間、客廳,是房子的公用資源。

    

MySQL多實例優(yōu)缺點:

1、有效利用服務(wù)器資源:當(dāng)單個服務(wù)器資源有空剩余時,可以充分利用剩余的資源創(chuàng)建更多的MySQL實例提供更多的服務(wù)。2、節(jié)約服務(wù)器資源:當(dāng)公司資金緊張,但是數(shù)據(jù)庫又需要多個并且需各自盡量獨立提供服務(wù)或者需要主從同步等,MySQL多實例就再好不過了。

3、資源相互爭搶問題:當(dāng)某個服務(wù)實例并發(fā)很高或者有慢查詢時,整個實例會消耗更多的內(nèi)存、CPU、磁盤、IO資源,導(dǎo)致服務(wù)器上的其它實例提供服務(wù)的質(zhì)量下降,這就相當(dāng)于大家在一個房子的不同臥室(MySQL實例),需要上廁所(硬件的CPU、內(nèi)存、磁盤的IO資源)時,一個占用了廁所,其他人都要等待。

Mysql多實例安裝指南:

  具體詳細參考官網(wǎng) (https://dev.mysql.com/doc/refman/5.7/en/installing.html)

  • mysql的安裝方法有多種,如二進制安裝、源碼編譯安裝、yum安裝;
  • yum安裝都是默認(rèn)路徑,安裝相對簡單;
  • 源碼安裝編譯的過程比較長,若沒有對源碼進行修改且要求使用mysql較高版本;

準(zhǔn)備環(huán)境。

[root@mysql-multi ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@mysql-multi ~]# uname -r
3.10.0-862.el7.x86_64
[root@mysql-multi ~]# hostname -I
172.16.70.37
[root@mysql-multi ~]# getenforce
Permissive
[root@mysql-multi ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

Jul 23 14:36:11 mysql-multi systemd[1]: Starting firewalld - dynamic firewall daemon...
Jul 23 14:36:12 mysql-multi systemd[1]: Started firewalld - dynamic firewall daemon.
Jul 23 15:09:10 mysql-multi systemd[1]: Stopping firewalld - dynamic firewall daemon...
Jul 23 15:09:11 mysql-multi systemd[1]: Stopped firewalld - dynamic firewall daemon.

# CentOS 7 版本的系統(tǒng)默認(rèn)自帶安裝了MariaDB,需要先清理
[root@mysql-multi ~]# rpm -qa |grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
或
[root@mysql-multi ~]# yum list installed | grep mariadb
mariadb-libs.x86_64                  1:5.5.56-2.el7                    @anaconda
# 卸載
[root@mysql-multi ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
或
[root@mysql-multi ~]# yum -y remove mariadb-libs.x86_64

安裝并配置MySQL多實例

YUM源安裝方式如下:

  官網(wǎng)rpm包下載:https://downloads.mysql.com/archives/community,選擇下載適合的版本。

#  將rpm包上傳至服務(wù)器
[root@mysql-multi ~]# yum install libaio lrzsz tree net-tools -y
[root@mysql-multi ~]# ls
mysql-community-client-5.7.34-1.el7.x86_64.rpm  mysql-community-libs-5.7.34-1.el7.x86_64.rpm
mysql-community-common-5.7.34-1.el7.x86_64.rpm  mysql-community-server-5.7.34-1.el7.x86_64.rpm

# 必須按照順序執(zhí)行安裝操作
[root@mysql-multi ~]# rpm -ivh mysql-community-common-5.7.34-1.el7.x86_64.rpm
[root@mysql-multi ~]# rpm -ivh mysql-community-libs-5.7.34-1.el7.x86_64.rpm
[root@mysql-multi ~]# rpm -ivh mysql-community-client-5.7.34-1.el7.x86_64.rpm
[root@mysql-multi ~]# rpm -ivh mysql-community-server-5.7.34-1.el7.x86_64.rpm

[root@mysql-multi ~]# yum list installed | grep mysql
mysql-community-client.x86_64        5.7.34-1.el7                      installed
mysql-community-common.x86_64        5.7.34-1.el7                      installed
mysql-community-libs.x86_64          5.7.34-1.el7                      installed
mysql-community-server.x86_64        5.7.34-1.el7                      installed

# 創(chuàng)建實例目錄
[root@mysql-multi ~]# mkdir -p /data/app/mysql/{3306,3307}
[root@mysql-multi ~]# mkdir -p /data/app/mysql/3306/{data,binlog,logs}
[root@mysql-multi ~]# mkdir -p /data/app/mysql/3307/{data,binlog,logs}
[root@mysql-multi ~]# tree /data/app/mysql/
/data/app/mysql/
├── 3306
│   ├── binlog
│   ├── data
│   └── logs
└── 3307
    ├── binlog
    ├── data
    └── logs

# 設(shè)置目錄屬主屬組
[root@mysql-multi ~]# chown -R mysql:mysql /data/app/mysql
[root@mysql-multi ~]# ls -ld /data/app/mysql
drwxr-xr-x. 4 mysql mysql 30 Jul 29 18:39 /data/app/mysql
[root@mysql-multi ~]# ls -ld /data/app
drwxr-xr-x. 3 root root 19 Jul 29 18:39 /data/app

# 新增配置文件my3306.cnf
[root@mysql-multi ~]# mv /etc/my.cnf /etc/my.cnf_bak
[root@mysql-multi ~]# cat /etc/my3306.cnf
[mysqld]
user = mysql
port = 3306
server_id = 3306
datadir = /data/app/mysql/3306/data
socket = /data/app/mysql/3306/mysql3306.sock
symbolic-links = 0
log-error = /data/app/mysql/3306/logs/mysqld3306.log
pid-file = /data/app/mysql/3306/mysqld3306.pid

# 新增配置文件my3307.cnf
[root@mysql-multi ~]# cp /etc/my3306.cnf /etc/my3307.cnf
[root@mysql-multi ~]# sed -i 's/3306/3307/g' /etc/my3307.cnf
[root@mysql-multi ~]# cat /etc/my3307.cnf
[mysqld]
user = mysql
port = 3307
server_id = 3307
datadir = /data/app/mysql/3307/data
socket = /data/app/mysql/3307/mysql3307.sock
symbolic-links = 0
log-error = /data/app/mysql/3307/logs/mysqld3307.log
pid-file = /data/app/mysql/3307/mysqld3307.pid

# 備份mysql啟動服務(wù)文件
[root@mysql-multi ~]# mv /usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/mysqld.service_bak
# 新增mysqld3306.service啟動文件
[root@mysql-multi ~]# cat /usr/lib/systemd/system/mysqld3306.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/data/app/mysql/3306/mysqld3306.pid
TimeoutSec=0
PermissionsStartOnly=true
#ExecStartPre=/usr/bin/mysqld_pre_systemd_3306 3306
ExecStart=/usr/sbin/mysqld --defaults-file=/etc/my3306.cnf --daemonize --pid-file=/data/app/mysql/3306/mysqld3306.pid $MYSQLD_OPTS
EnvironmentFile=-/etc/sysconfig/mysql
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false

# 新增mysqld3307.service啟動文件
[root@mysql-multi ~]# cp /usr/lib/systemd/system/mysqld3306.service /usr/lib/systemd/system/mysqld3307.service
[root@mysql-multi ~]# sed -i 's/3306/3307/g' /usr/lib/systemd/system/mysqld3307.service
[root@mysql-multi ~]# cat /usr/lib/systemd/system/mysqld3307.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/data/app/mysql/3307/mysqld3307.pid
TimeoutSec=0
PermissionsStartOnly=true
#ExecStartPre=/usr/bin/mysqld_pre_systemd_3307 3307
ExecStart=/usr/sbin/mysqld --defaults-file=/etc/my3307.cnf --daemonize --pid-file=/data/app/mysql/3307/mysqld3307.pid $MYSQLD_OPTS
EnvironmentFile=-/etc/sysconfig/mysql
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false

# 初始化多實例3306,3307
[root@mysql-multi ~]# mysqld --defaults-file=/etc/my3306.cnf --initialize --user=mysql --datadir=/data/app/mysql/3306/data
[root@mysql-multi ~]# mysqld --defaults-file=/etc/my3307.cnf --initialize --user=mysql --datadir=/data/app/mysql/3307/data

# 啟動多實例3306,3307
[root@mysql-multi ~]# systemctl start mysqld3306
[root@mysql-multi ~]# systemctl start mysqld3307
[root@mysql-multi ~]# netstat -nutpl | grep mysql
tcp6       0      0 :::3306                 :::*                    LISTEN      128270/mysqld
tcp6       0      0 :::3307                 :::*                    LISTEN      128328/mysqld
[root@mysql-multi ~]# ps -ef | grep mysql
mysql    128270      1  1 11:43 ?        00:00:00 /usr/sbin/mysqld --defaults-file=/etc/my3306.cnf --daemonize --pid-file=/data/app/mysql/3306/mysqld3306.pid
mysql    128328      1  1 11:43 ?        00:00:00 /usr/sbin/mysqld --defaults-file=/etc/my3307.cnf --daemonize --pid-file=/data/app/mysql/3307/mysqld3307.pid
root     128373    949  0 11:43 pts/0    00:00:00 grep --color=auto mysql

======================================== 【 再新增一MySQL實例 】===================================================================
# 創(chuàng)建目錄,設(shè)置屬主屬組
[root@mysql-multi ~]# mkdir -p /data/app/mysql/3308/{data,binlog,logs}
[root@mysql-multi ~]# chown -R mysql:mysql /data/app/mysql/3308
[root@mysql-multi ~]# ls -ld /data/app/mysql/3308
drwxr-xr-x. 5 mysql mysql 44 Aug  5 14:45 /data/app/mysql/3308

# 新增配置文件my3308.cnf
[root@mysql-multi ~]# cp /etc/my3306.cnf /etc/my3308.cnf
[root@mysql-multi ~]# sed -i 's/3306/3308/g' /etc/my3308.cnf
[root@mysql-multi ~]# cat /etc/my3308.cnf
[mysqld]
user = mysql
port = 3308
server_id = 3308
datadir = /data/app/mysql/3308/data
socket = /data/app/mysql/3308/mysql3308.sock
symbolic-links = 0
log-error = /data/app/mysql/3308/logs/mysqld3308.log
pid-file = /data/app/mysql/3308/mysqld3308.pid

# 新增mysqld3308.service啟動文件
[root@mysql-multi ~]# cp /usr/lib/systemd/system/mysqld3306.service /usr/lib/systemd/system/mysqld3308.service
[root@mysql-multi ~]# sed -i 's/3306/3308/g' /usr/lib/systemd/system/mysqld3308.service
[root@mysql-multi ~]# cat /usr/lib/systemd/system/mysqld3308.service
[Unit]
Description=MySQL Server 3308
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/data/app/mysql/3308/mysqld3308.pid
TimeoutSec=0
PermissionsStartOnly=true
#ExecStartPre=/usr/bin/mysqld_pre_systemd_3308 3308
ExecStart=/usr/sbin/mysqld --defaults-file=/etc/my3308.cnf --daemonize --pid-file=/data/app/mysql/3308/mysqld3308.pid $MYSQLD_OPTS
EnvironmentFile=-/etc/sysconfig/mysql
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false

# 初始化多實例3308
[root@mysql-multi ~]# mysqld --defaults-file=/etc/my3308.cnf --initialize --user=mysql --datadir=/data/app/mysql/3308/data

# 啟動多實例3308
[root@mysql-multi ~]# systemctl start mysqld3308
[root@mysql-multi ~]# netstat -nutpl | grep mysql
tcp6       0      0 :::3306                 :::*                    LISTEN      5062/mysqld
tcp6       0      0 :::3307                 :::*                    LISTEN      5098/mysqld
tcp6       0      0 :::3308                 :::*                    LISTEN      5189/mysqld
[root@mysql-multi ~]# ps -ef |grep mysql
mysql      5062      1  0 14:43 ?        00:00:01 /usr/sbin/mysqld --defaults-file=/etc/my3306.cnf --daemonize --pid-file=/data/app/mysql/3306/mysqld3306.pid
mysql      5098      1  0 14:44 ?        00:00:01 /usr/sbin/mysqld --defaults-file=/etc/my3307.cnf --daemonize --pid-file=/data/app/mysql/3307/mysqld3307.pid
mysql      5189      1  4 14:57 ?        00:00:01 /usr/sbin/mysqld --defaults-file=/etc/my3308.cnf --daemonize --pid-file=/data/app/mysql/3308/mysqld3308.pid

源碼編譯安裝方式如下:

  MySQL下載:https://downloads.mysql.com/archives/community

  Boost下載:https://sourceforge.net/projects/boost/files/boost/1.59.0

  MySQL多實例:https://dev.mysql.com/doc/refman/5.7/en/multiple-servers.html

# 依賴包和編譯軟件
[root@mysql-multi ~]# yum install -y cmake make gcc gcc-c++ openssl openssl-devel ncurses ncurses-devel libaio-devel wget lrzsz tree
[root@mysql-multi ~]# rpm -qa ncurses-devel libaio-devel
libaio-devel-0.3.109-13.el7.x86_64
ncurses-devel-5.9-14.20130511.el7_4.x86_64

# 下載上傳源碼包并解壓編譯安裝(最好內(nèi)存gt;8G)
ls[root@mysql-multi ~]# ls
boost_1_59_0.tar.gz  mysql-boost-5.7.34.tar.gz
[root@mysql-multi ~]# tar xf boost_1_59_0.tar.gz
[root@mysql-multi ~]# tar xf mysql-boost-5.7.34.tar.gz
[root@mysql-multi ~]# ls
boost_1_59_0  boost_1_59_0.tar.gz  mysql-5.7.34  mysql-boost-5.7.34.tar.gz
[root@mysql-multi ~]# cd mysql-5.7.34/
[root@mysql-multi mysql-5.7.34]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8mb4 \

-DENABLED_LOCAL_INFILE=1 -DWITH_SYSTEMD=1 -DWITH_BOOST=/root/boost_1_59_0 -DEXTRA_CHARSETS=all
......
......最末尾顯示如下內(nèi)容,則完成
-- CMAKE_SHARED_LINKER_FLAGS
-- Configuring done
-- Generating done
-- Build files have been written to: /root/mysql-5.7.34

選項說明:
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql    # mysql安裝目錄
-DDEFAULT_CHARSET=utf8mb4             # 數(shù)據(jù)庫默認(rèn)字符編碼
-DENABLED_LOCAL_INFILE=1             # 允許從本文件導(dǎo)入數(shù)據(jù)
-DWITH_SYSTEMD=1                 # 提供systemd腳本
-DWITH_BOOST=/root/boost_1_59_0         # boost源路徑
-DEXTRA_CHARSETS=all               # 安裝所有字符集

[root@mysql-multi mysql-5.7.34]#make -j 4  make install    # make -j 4 表示用CPU4核心同時進行編譯:cat /proc/cpuinfo|grep "processor"|wc -l
......
......最末尾顯示如下內(nèi)容,則完成
-- Up-to-date: /usr/local/app/mysql/mysql-test/mysql-test-run
-- Installing: /usr/local/app/mysql/mysql-test/lib/My/SafeProcess/my_safe_process
-- Up-to-date: /usr/local/app/mysql/mysql-test/lib/My/SafeProcess/my_safe_process
-- Installing: /usr/local/app/mysql/mysql-test/lib/My/SafeProcess/Base.pm
-- Installing: /usr/local/app/mysql/support-files/mysqld_multi.server
-- Installing: /usr/local/app/mysql/support-files/mysql-log-rotate
-- Installing: /usr/local/app/mysql/support-files/magic
-- Installing: /usr/local/app/mysql/share/aclocal/mysql.m4
-- Installing: /usr/local/app/mysql/support-files/mysql.server

# 創(chuàng)建實例目錄
[root@mysql-multi ~]# mkdir -p /data/app/mysql/{3306,3307}/{data,binlog,logs}
[root@mysql-multi ~]# tree /data/app/mysql
/data/app/mysql
├── 3306
│   ├── binlog
│   ├── data
│   └── logs
└── 3307
    ├── binlog
    ├── data
    └── logs

# 創(chuàng)建用戶,設(shè)置目錄屬主屬組
[root@mysql-multi ~]# useradd -M -r -s /sbin/nologin mysql
[root@mysql-multi ~]# chown -R mysql:mysql /data/app/mysql
[root@mysql-multi ~]# ls -ld /data/app/mysql
drwxr-xr-x. 4 mysql mysql 30 Aug  5 12:17 /data/app/mysql

# 新增配置文件my3306.cnf
[root@mysql-multi ~]# mv /etc/my.cnf /etc/my.cnf_bak
[root@mysql-multi ~]# cat /etc/my3306.cnf
[mysqld]
user = mysql
port = 3306
server_id = 3306
basedir = /usr/local/mysql
datadir = /data/app/mysql/3306/data
socket = /data/app/mysql/3306/mysql3306.sock
symbolic-links = 0
log-error = /data/app/mysql/3306/logs/mysqld3306.log
pid-file = /data/app/mysql/3306/mysqld3306.pid
character_set_server = utf8
default-storage-engine = INNODB

# 新增配置文件my3307.cnf
[root@mysql-multi ~]# cp /etc/my3306.cnf /etc/my3307.cnf
[root@mysql-multi ~]# sed -i 's/3306/3307/g' /etc/my3307.cnf
[root@mysql-multi ~]# cat /etc/my3307.cnf
[mysqld]
user = mysql
port = 3307
server_id = 3307
basedir = /usr/local/mysql
datadir = /data/app/mysql/3307/data
socket = /data/app/mysql/3307/mysql3307.sock
symbolic-links = 0
log-error = /data/app/mysql/3307/logs/mysqld3307.log
pid-file = /data/app/mysql/3307/mysqld3307.pid
character_set_server = utf8
default-storage-engine = INNODB

# 安裝后規(guī)范化操作(設(shè)置環(huán)境變量、輸出頭文件和庫文件、設(shè)置man路徑)
[root@mysql-multi ~]# echo "export PATH=/usr/local/mysql/bin:$PATH" gt;gt; /etc/profile.d/mysql.sh
[root@mysql-multi ~]# chmod +x /etc/profile.d/mysql.sh
[root@mysql-multi ~]# source /etc/profile.d/mysql.sh
[root@mysql-multi ~]# echo "MANPATH /usr/local/mysql/man" gt;gt;/etc/man.config
[root@mysql-multi ~]# echo "/usr/local/mysql/lib" gt; /etc/ld.so.conf.d/mysql.conf
[root@mysql-multi ~]# ldconfig
[root@mysql-multi ~]# ln -s /usr/local/mysql/include /usr/include/mysql

# 新增實例3306,3307 systemd方式
[root@mysql-multi ~]# cat /usr/lib/systemd/system/mysqld3306.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/data/app/mysql/3306/mysqld3306.pid
TimeoutSec=0
PermissionsStartOnly=true
#ExecStartPre=/usr/bin/mysqld_pre_systemd_3306 3306
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my3306.cnf --daemonize --pid-file=/data/app/mysql/3306/mysqld3306.pid $MYSQLD_OPTS
EnvironmentFile=-/etc/sysconfig/mysql
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false

[root@mysql-multi ~]# cp /usr/lib/systemd/system/mysqld3306.service /usr/lib/systemd/system/mysqld3307.service
[root@mysql-multi ~]# sed -i 's/3306/3307/g' /usr/lib/systemd/system/mysqld3307.service
[root@mysql-multi ~]# cat /usr/lib/systemd/system/mysqld3307.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
Type=forking
PIDFile=/data/app/mysql/3307/mysqld3307.pid
TimeoutSec=0
PermissionsStartOnly=true
#ExecStartPre=/usr/bin/mysqld_pre_systemd_3307 3307
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my3307.cnf --daemonize --pid-file=/data/app/mysql/3307/mysqld3307.pid $MYSQLD_OPTS
EnvironmentFile=-/etc/sysconfig/mysql
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false

# 初始化實例3306,3307
[root@mysql-multi ~]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my3306.cnf --initialize --basedir=/usr/local/mysql --user=mysql --datadir=/data/app/mysql/3306/data
[root@mysql-multi ~]# /usr/local/mysql/bin/mysqld --defaults-file=/etc/my3307.cnf --initialize --basedir=/usr/local/mysql --user=mysql --datadir=/data/app/mysql/3307/data

# 啟動實例3306,3307服務(wù) (start|stop|restart|status)
[root@mysql-multi ~]# systemctl start mysqld3306
[root@mysql-multi ~]# systemctl start mysqld3307
[root@mysql-multi ~]# netstat -nuptl | grep mysql
tcp6       0      0 :::3306                 :::*                    LISTEN      27165/mysqld
tcp6       0      0 :::3307                 :::*                    LISTEN      27201/mysqld
[root@mysql-multi ~]# ps -ef | grep mysql
mysql     27165      1  2 17:03 ?        00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my3306.cnf --daemonize --pid-file=/data/app/mysql/3306/mysqld3306.pid
mysql     27201      1  2 17:03 ?        00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my3307.cnf --daemonize --pid-file=/data/app/mysql/3307/mysqld3307.pid

修改MySQL實例密碼并測試登錄。

# 獲取實例初始密碼
[root@mysql-multi ~]# grep 'temporary password' /data/app/mysql/3306/logs/mysqld3306.log
2021-08-05T08:52:37.904630Z 1 [Note] A temporary password is generated for root@localhost: ,YrsLryq3Ll

[root@mysql-multi ~]# grep 'temporary password' /data/app/mysql/3307/logs/mysqld3307.log
2021-08-05T08:52:48.082526Z 1 [Note] A temporary password is generated for root@localhost: OvxKu,su=4O1

# 修改實例密碼
[root@mysql-multi ~]# mysqladmin -p -S /data/app/mysql/3306/mysql3306.sock password
Enter password:  # 輸入初始密碼
New password:   # 輸入新密碼  123456
Confirm new password:  # 再次輸入新密碼  123456

--------------------------------------------------------------------------------------
# 或
shellgt; mysql -uroot -p /data/app/mysql/3306/mysql3306.sock
mysqlgt; ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
--------------------------------------------------------------------------------------

[root@mysql-multi ~]# mysqladmin -p -S /data/app/mysql/3306/mysql3307.sock password
Enter password:  # 輸入初始密碼
New password:   # 輸入新密碼  654321
Confirm new password:  # 再次輸入新密碼  654321

# 測試登錄
[root@mysql-multi ~]# mysql -uroot -p -S /data/app/mysql/3306/mysql3306.sock
Enter password:  # 輸入密碼  123456
[root@mysql-multi ~]# mysql -uroot -p -S /data/app/mysql/3307/mysql3307.sock
Enter password:  # 輸入密碼  654321

# 停止實例
[root@mysql-multi ~]# mysqladmin -uroot -p -S /data/app/mysql/3306/mysql3306.sock shutdown
Enter password:  # 輸入密碼  123456
[root@mysql-multi ~]# mysqladmin -uroot -p -S /data/app/mysql/3307/mysql3307.sock shutdown
Enter password:  # 輸入密碼  654321

至此,MySQL多實例已經(jīng)實現(xiàn)!

到此這篇關(guān)于Linux下MySQL多實例部署記錄的文章就介紹到這了,更多相關(guān)MySQL多實例部署內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • Linux下mysql 8.0.25 安裝配置方法圖文教程
  • 一臺linux主機啟動多個MySQL數(shù)據(jù)庫的方法
  • linux mysql5.5升級至mysql5.7的步驟與踩到的坑
  • 解決Linux安裝mysql 在/etc下沒有my.cnf的問題
  • linux下利用Docker安裝mysql的步驟
  • Linux手動部署遠程的mysql數(shù)據(jù)庫的方法詳解
  • linux使用mysqldump+expect+crontab實現(xiàn)mysql周期冷備份思路詳解
  • Aliyun Linux 編譯安裝 php7.3 tengine2.3.2 mysql8.0 redis5的過程詳解
  • Mysql如何在linux中實現(xiàn)定時備份
  • Linux mysql-5.6如何實現(xiàn)重置root密碼
  • 在Ubuntu/Linux環(huán)境下使用MySQL開放/修改3306端口和開放訪問權(quán)限
  • MySQL定時備份方案(利用Linux crontab)
  • linux環(huán)境下安裝mysql數(shù)據(jù)庫的詳細教程
  • Linux下mysql異地自動備份的方法
  • Linux MySQL忘記root密碼解決方案
  • Linux下安裝mysql-8.0.20的教程詳解
  • Linux如何使用 MyCat 實現(xiàn) MySQL 主從讀寫分離

標(biāo)簽:蘭州 黃山 銅川 崇左 湖南 仙桃 衡水 湘潭

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Linux下MySQL多實例部署及安裝指南》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    沙河市| 芜湖县| 石嘴山市| 且末县| 洱源县| 新宁县| 泗阳县| 西丰县| 绵竹市| 连城县| 江津市| 都匀市| 肥城市| 临夏县| 江达县| 喀什市| 普安县| 加查县| 普定县| 稻城县| 渑池县| 仙居县| 大洼县| 霍林郭勒市| 滁州市| 高雄县| 鲁甸县| 鹿邑县| 原阳县| 玉龙| 井陉县| 墨竹工卡县| 马关县| 十堰市| 达尔| 砀山县| 陆丰市| 察隅县| 英吉沙县| 嘉禾县| 涟源市|