一壶普洱 發表於 2020-3-28 15:31:00

在一台Linux服务器上安装多个MySQL实例(一)--使用mysqld_multi方式

<p><img style="display: inline; background-image: none" title="image" src="https://img2020.cnblogs.com/blog/823295/202003/823295-20200328153036979-1548275162.png" alt="image" width="285" height="200" border="0"></p>
<p><strong>&nbsp;</strong></p>
<p><strong>(一)MySQL多实例概述</strong></p>
<p>实例是进程与内存的一个概述,所谓MySQL多实例,就是在服务器上启动多个相同的MySQL进程,运行在不同的端口(如3306,3307,3308),通过不同的端口对外提供服务。</p>
<p>由于MySQL在一个实例下面可以创建多个数据库,所以通常在一台服务器上只要安装一个MySQL实例即可满足使用。但在实际使用中,因为服务器硬件资源充足,或者业务需要(比如在一台服务器上创建开发数据库和测试数据库),往往会在一台服务器上创建多个实例。</p>
<p>&nbsp;</p>
<p><strong>(二)MySQL部署多实例的方法</strong></p>
<p>MySQL多实例部署主要有以下两种方式:</p>
<ul>
<li>使用官方自带的mysqld_multi来配置管理,特点是使用同一份MySQL配置文件,这种方式属于集中式管理,管理起来较为方便;</li>
<li>使用单独的MySQL配置文件来单独配置实例,这种方式逻辑简单,数据库之间没有关联。</li>
</ul>
<p>本文将对第一种方式进行环境搭建学习。</p>
<p>&nbsp;</p>
<p><strong>(三)<strong>实验环境</strong></strong></p>
<p>操作系统&nbsp;&nbsp; :CentOS Linux release 7.4.1708 (Core)</p>
<p>数据库版本:5.7.24-log</p>
<p>预计划安装4个MySQL实例,规划信息为:</p>
<table style="width: 1000px" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="250"><strong>实例1</strong></td>
<td valign="top" width="250"><strong>实例2</strong></td>
<td valign="top" width="250"><strong>实例3</strong></td>
<td valign="top" width="250"><strong>实例4</strong></td>
</tr>
<tr>
<td valign="top" width="200">
<p>basedir=/usr/local/mysql</p>
<p>datadir=/mysql/3306/data</p>
<p>port=3306</p>
<p>socket=/tmp/mysql_3306.sock</p>
</td>
<td valign="top" width="200">
<p>basedir=/usr/local/mysql</p>
<p>datadir=/mysql/3307/data</p>
<p>port=3307</p>
<p>socket=/tmp/mysql_3307.sock</p>
</td>
<td valign="top" width="200">
<p>basedir=/usr/local/mysql</p>
<p>datadir=/mysql/3308/data</p>
<p>port=3308</p>
<p>socket=/tmp/mysql_3308.sock</p>
</td>
<td valign="top" width="200">
<p>basedir=/usr/local/mysql</p>
<p>datadir=/mysql/3309/data</p>
<p>port=3309</p>
<p>socket=/tmp/mysql_3309.sock</p>
</td>

</tr>

</tbody>

</table>
<p>&nbsp;</p>
<p><strong>(四)实验过程</strong></p>
<p>(4.1)在安装MySQL之前,需要卸载服务器自带的MySQL包和MySQL数据库分支mariadb的包</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre># rpm -qa|<span style="color: rgba(0, 0, 255, 1)">grep</span><span style="color: rgba(0, 0, 0, 1)"> mysql
# rpm -qa |<span style="color: rgba(0, 0, 255, 1)">grep</span><span style="color: rgba(0, 0, 0, 1)"> mariadb
mariadb</span>-libs-<span style="color: rgba(128, 0, 128, 1)">5.5</span>.<span style="color: rgba(128, 0, 128, 1)">56</span>-<span style="color: rgba(128, 0, 128, 1)">2</span><span style="color: rgba(0, 0, 0, 1)">.el7.x86_64

# rpm -e mariadb-libs-<span style="color: rgba(128, 0, 128, 1)">5.5</span>.<span style="color: rgba(128, 0, 128, 1)">56</span>-<span style="color: rgba(128, 0, 128, 1)">2</span>.el7.x86_64 --nodeps</pre>
</div>
<p>&nbsp;</p>
<p>(4.2)依赖包安装</p>
<p>MySQL对libaio 库有依赖性。如果未在本地安装该库,则数据目录初始化和随后的服务器启动步骤将失败
、</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)"><span style="color: rgba(64, 128, 128, 1)"># install library</span>
<pre><span style="color: rgba(0, 0, 0, 1)">
# </span><span style="color: rgba(0, 0, 255, 1)">yum</span> <span style="color: rgba(0, 0, 255, 1)">install</span> libaio</pre>
</div>
<p>对于MySQL 5.7.19和更高版本:通用Linux版本中增加了对非统一内存访问(NUMA)的支持,该版本现在对libnuma库具有依赖性 。</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)"><span style="color: rgba(64, 128, 128, 1)"># install library</span>
<pre><span style="color: rgba(0, 0, 0, 1)">
# </span><span style="color: rgba(0, 0, 255, 1)">yum</span> <span style="color: rgba(0, 0, 255, 1)">install</span> libnuma</pre>
</div>
<p>&nbsp;</p>
<p>(4.3)创建用户和用户组</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre># groupadd mysql
# useradd -r -g mysql -s /bin/<span style="color: rgba(0, 0, 255, 1)">false</span> mysql</pre>
</div>
<p>&nbsp;</p>
<p>(4.4)解压安装包</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre># cd /usr/local/<span style="color: rgba(0, 0, 0, 1)">
# </span><span style="color: rgba(0, 0, 255, 1)">tar</span> xzvf /root/mysql-<span style="color: rgba(128, 0, 128, 1)">5.7</span>.<span style="color: rgba(128, 0, 128, 1)">24</span>-linux-glibc2.<span style="color: rgba(128, 0, 128, 1)">12</span>-x86_64.<span style="color: rgba(0, 0, 255, 1)">tar</span><span style="color: rgba(0, 0, 0, 1)">.gz

<span style="color: rgba(64, 128, 128, 1)"># 修改解压文件名,与前面定义的basedir相同</span>
# </span><span style="color: rgba(0, 0, 255, 1)">mv</span> mysql-<span style="color: rgba(128, 0, 128, 1)">5.7</span>.<span style="color: rgba(128, 0, 128, 1)">24</span>-linux-glibc2.<span style="color: rgba(128, 0, 128, 1)">12</span>-x86_64/ mysql</pre>
</div>
<p>最终解压结果如下:</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre># <span style="color: rgba(0, 0, 255, 1)">ls</span> -<span style="color: rgba(0, 0, 0, 1)">l
total </span><span style="color: rgba(128, 0, 128, 1)">36</span><span style="color: rgba(0, 0, 0, 1)">
drwxr</span>-xr-x<span style="color: rgba(128, 0, 128, 1)">2</span> root root   <span style="color: rgba(128, 0, 128, 1)">4096</span> Mar <span style="color: rgba(128, 0, 128, 1)">28</span> <span style="color: rgba(128, 0, 128, 1)">13</span>:<span style="color: rgba(128, 0, 128, 1)">48</span><span style="color: rgba(0, 0, 0, 1)"> bin
</span>-rw-r--r--<span style="color: rgba(128, 0, 128, 1)">1</span> <span style="color: rgba(128, 0, 128, 1)">7161</span> <span style="color: rgba(128, 0, 128, 1)">31415</span> <span style="color: rgba(128, 0, 128, 1)">17987</span> Oct<span style="color: rgba(128, 0, 128, 1)">4</span><span style="color: rgba(128, 0, 128, 1)">2018</span><span style="color: rgba(0, 0, 0, 1)"> COPYING
drwxr</span>-xr-x<span style="color: rgba(128, 0, 128, 1)">2</span> root root   <span style="color: rgba(128, 0, 128, 1)">55</span> Mar <span style="color: rgba(128, 0, 128, 1)">28</span> <span style="color: rgba(128, 0, 128, 1)">13</span>:<span style="color: rgba(128, 0, 128, 1)">48</span><span style="color: rgba(0, 0, 0, 1)"> docs
drwxr</span>-xr-x<span style="color: rgba(128, 0, 128, 1)">3</span> root root   <span style="color: rgba(128, 0, 128, 1)">4096</span> Mar <span style="color: rgba(128, 0, 128, 1)">28</span> <span style="color: rgba(128, 0, 128, 1)">13</span>:<span style="color: rgba(128, 0, 128, 1)">48</span><span style="color: rgba(0, 0, 0, 1)"> include
drwxr</span>-xr-x<span style="color: rgba(128, 0, 128, 1)">5</span> root root    <span style="color: rgba(128, 0, 128, 1)">230</span> Mar <span style="color: rgba(128, 0, 128, 1)">28</span> <span style="color: rgba(128, 0, 128, 1)">13</span>:<span style="color: rgba(128, 0, 128, 1)">48</span><span style="color: rgba(0, 0, 0, 1)"> lib
drwxr</span>-xr-x<span style="color: rgba(128, 0, 128, 1)">4</span> root root   <span style="color: rgba(128, 0, 128, 1)">30</span> Mar <span style="color: rgba(128, 0, 128, 1)">28</span> <span style="color: rgba(128, 0, 128, 1)">13</span>:<span style="color: rgba(128, 0, 128, 1)">48</span> <span style="color: rgba(0, 0, 255, 1)">man</span>
-rw-r--r--<span style="color: rgba(128, 0, 128, 1)">1</span> <span style="color: rgba(128, 0, 128, 1)">7161</span> <span style="color: rgba(128, 0, 128, 1)">31415</span><span style="color: rgba(128, 0, 128, 1)">2478</span> Oct<span style="color: rgba(128, 0, 128, 1)">4</span><span style="color: rgba(128, 0, 128, 1)">2018</span><span style="color: rgba(0, 0, 0, 1)"> README
drwxr</span>-xr-x <span style="color: rgba(128, 0, 128, 1)">28</span> root root   <span style="color: rgba(128, 0, 128, 1)">4096</span> Mar <span style="color: rgba(128, 0, 128, 1)">28</span> <span style="color: rgba(128, 0, 128, 1)">13</span>:<span style="color: rgba(128, 0, 128, 1)">48</span><span style="color: rgba(0, 0, 0, 1)"> share
drwxr</span>-xr-x<span style="color: rgba(128, 0, 128, 1)">2</span> root root   <span style="color: rgba(128, 0, 128, 1)">90</span> Mar <span style="color: rgba(128, 0, 128, 1)">28</span> <span style="color: rgba(128, 0, 128, 1)">13</span>:<span style="color: rgba(128, 0, 128, 1)">48</span> support-files</pre>
</div>
<p>&nbsp;</p>
<p>(4.5)创建数据文件存放路径</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre># <span style="color: rgba(0, 0, 255, 1)">mkdir</span> -p /mysql/{<span style="color: rgba(128, 0, 128, 1)">3306</span>,<span style="color: rgba(128, 0, 128, 1)">3307</span>,<span style="color: rgba(128, 0, 128, 1)">3308</span>,<span style="color: rgba(128, 0, 128, 1)">3309</span>}/<span style="color: rgba(0, 0, 0, 1)">data
# </span><span style="color: rgba(0, 0, 255, 1)">chown</span> -R mysql:mysql /<span style="color: rgba(0, 0, 0, 1)">mysql
# cd </span>/<span style="color: rgba(0, 0, 0, 1)">mysql
# tree
.
├── </span><span style="color: rgba(128, 0, 128, 1)">3306</span><span style="color: rgba(0, 0, 0, 1)">
│&nbsp;&nbsp; └── data
├── </span><span style="color: rgba(128, 0, 128, 1)">3307</span><span style="color: rgba(0, 0, 0, 1)">
│&nbsp;&nbsp; └── data
├── </span><span style="color: rgba(128, 0, 128, 1)">3308</span><span style="color: rgba(0, 0, 0, 1)">
│&nbsp;&nbsp; └── data
└── </span><span style="color: rgba(128, 0, 128, 1)">3309</span><span style="color: rgba(0, 0, 0, 1)">
    └── data</span></pre>
</div>
<p>&nbsp;</p>
<p>(4.6)创建MySQL参数配置文件<br>
</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre># vim /etc/<span style="color: rgba(0, 0, 0, 1)">my.cnf


user</span>=<span style="color: rgba(0, 0, 0, 1)">mysql
basedir </span>= /usr/local/<span style="color: rgba(0, 0, 0, 1)">mysql


mysqld</span>=/usr/local/mysql/bin/<span style="color: rgba(0, 0, 0, 1)">mysqld_safe
mysqladmin</span>=/usr/local/mysql/bin/<span style="color: rgba(0, 0, 0, 1)">mysqladmin
log</span>=/usr/local/mysql/<span style="color: rgba(0, 0, 0, 1)">mysqld_multi.log


mysqld</span>=<span style="color: rgba(0, 0, 0, 1)">mysqld
mysqladmin</span>=<span style="color: rgba(0, 0, 0, 1)">mysqladmin
datadir</span>=/mysql/<span style="color: rgba(128, 0, 128, 1)">3306</span>/<span style="color: rgba(0, 0, 0, 1)">data
port</span>=<span style="color: rgba(128, 0, 128, 1)">3306</span><span style="color: rgba(0, 0, 0, 1)">
server_id</span>=<span style="color: rgba(128, 0, 128, 1)">3306</span><span style="color: rgba(0, 0, 0, 1)">
socket</span>=/tmp/<span style="color: rgba(0, 0, 0, 1)">mysql_3306.sock
log</span>-error = /mysql/<span style="color: rgba(128, 0, 128, 1)">3306</span>/<span style="color: rgba(0, 0, 0, 1)">error_3306.log


mysqld</span>=<span style="color: rgba(0, 0, 0, 1)">mysqld
mysqladmin</span>=<span style="color: rgba(0, 0, 0, 1)">mysqladmin
datadir</span>=/mysql/<span style="color: rgba(128, 0, 128, 1)">3307</span>/<span style="color: rgba(0, 0, 0, 1)">data
port</span>=<span style="color: rgba(128, 0, 128, 1)">3307</span><span style="color: rgba(0, 0, 0, 1)">
server_id</span>=<span style="color: rgba(128, 0, 128, 1)">3307</span><span style="color: rgba(0, 0, 0, 1)">
socket</span>=/tmp/<span style="color: rgba(0, 0, 0, 1)">mysql_3307.sock
log</span>-error=/mysql/<span style="color: rgba(128, 0, 128, 1)">3307</span>/<span style="color: rgba(0, 0, 0, 1)">error_3307.log


mysqld</span>=<span style="color: rgba(0, 0, 0, 1)">mysqld
mysqladmin</span>=<span style="color: rgba(0, 0, 0, 1)">mysqladmin
datadir</span>=/mysql/<span style="color: rgba(128, 0, 128, 1)">3308</span>/<span style="color: rgba(0, 0, 0, 1)">data
port</span>=<span style="color: rgba(128, 0, 128, 1)">3308</span><span style="color: rgba(0, 0, 0, 1)">
server_id</span>=<span style="color: rgba(128, 0, 128, 1)">3308</span><span style="color: rgba(0, 0, 0, 1)">
socket</span>=/tmp/<span style="color: rgba(0, 0, 0, 1)">mysql_3308.sock
log</span>-error=/mysql/<span style="color: rgba(128, 0, 128, 1)">3308</span>/<span style="color: rgba(0, 0, 0, 1)">error_3308.log


mysqld</span>=<span style="color: rgba(0, 0, 0, 1)">mysqld
mysqladmin</span>=<span style="color: rgba(0, 0, 0, 1)">mysqladmin
datadir</span>=/mysql/<span style="color: rgba(128, 0, 128, 1)">3309</span>/<span style="color: rgba(0, 0, 0, 1)">data
port</span>=<span style="color: rgba(128, 0, 128, 1)">3309</span><span style="color: rgba(0, 0, 0, 1)">
server_id</span>=<span style="color: rgba(128, 0, 128, 1)">3309</span><span style="color: rgba(0, 0, 0, 1)">
socket</span>=/tmp/<span style="color: rgba(0, 0, 0, 1)">mysql_3309.sock
log</span>-error = /mysql/<span style="color: rgba(128, 0, 128, 1)">3309</span>/error_3309.log</pre>
</div>
<p>&nbsp;</p>
<p>(4.7)初始化数据库</p>
<p>注意,初始化实例的最后一行记录了root的初始密码</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre><span style="color: rgba(0, 0, 0, 1)"><span style="color: rgba(64, 128, 128, 1)"># 初始化3306实例</span>
# </span>/usr/local/mysql/bin/mysqld --defaults-<span style="color: rgba(0, 0, 255, 1)">file</span>=/etc/my.cnf --initialize --basedir=/usr/local/mysql/ --datadir=/mysql/<span style="color: rgba(128, 0, 128, 1)">3306</span>/<span style="color: rgba(0, 0, 0, 1)">data
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">28</span>.484174Z <span style="color: rgba(128, 0, 128, 1)">0</span> TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation <span style="color: rgba(0, 0, 255, 1)">for</span> <span style="color: rgba(0, 0, 255, 1)">more</span><span style="color: rgba(0, 0, 0, 1)"> details).
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">28</span>.689102Z <span style="color: rgba(128, 0, 128, 1)">0</span> InnoDB: New log files created, LSN=<span style="color: rgba(128, 0, 128, 1)">45790</span>
<span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">28</span>.723881Z <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)"> InnoDB: Creating foreign key constraint system tables.
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">28</span>.781205Z <span style="color: rgba(128, 0, 128, 1)">0</span> No existing UUID has been found, so we assume that this is the first <span style="color: rgba(0, 0, 255, 1)">time</span> that this server has been started. Generating a new UUID: d29ad574-70ba-11ea-a38f-<span style="color: rgba(0, 0, 0, 1)">000c29fb6200.
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">28</span>.782195Z <span style="color: rgba(128, 0, 128, 1)">0</span> Gtid table is not ready to be used. Table <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">mysql.gtid_executed</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> cannot be opened.
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">28</span>.783078Z <span style="color: rgba(128, 0, 128, 1)">1</span> A temporary password is generated <span style="color: rgba(0, 0, 255, 1)">for</span> root@localhost: YuJ6Bi=<span style="color: rgba(0, 0, 0, 1)">PtqCJ


<span style="color: rgba(64, 128, 128, 1)"># 初始化3307实例</span>
# </span>/usr/local/mysql/bin/mysqld --defaults-<span style="color: rgba(0, 0, 255, 1)">file</span>=/etc/my.cnf --initialize --basedir=/usr/local/mysql/ --datadir=/mysql/<span style="color: rgba(128, 0, 128, 1)">3307</span>/<span style="color: rgba(0, 0, 0, 1)">data
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">45</span>.598676Z <span style="color: rgba(128, 0, 128, 1)">0</span> TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation <span style="color: rgba(0, 0, 255, 1)">for</span> <span style="color: rgba(0, 0, 255, 1)">more</span><span style="color: rgba(0, 0, 0, 1)"> details).
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">45</span>.793277Z <span style="color: rgba(128, 0, 128, 1)">0</span> InnoDB: New log files created, LSN=<span style="color: rgba(128, 0, 128, 1)">45790</span>
<span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">45</span>.829673Z <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)"> InnoDB: Creating foreign key constraint system tables.
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">45</span>.886255Z <span style="color: rgba(128, 0, 128, 1)">0</span> No existing UUID has been found, so we assume that this is the first <span style="color: rgba(0, 0, 255, 1)">time</span> that this server has been started. Generating a new UUID: dcccdb2f-70ba-11ea-a565-<span style="color: rgba(0, 0, 0, 1)">000c29fb6200.
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">45</span>.887571Z <span style="color: rgba(128, 0, 128, 1)">0</span> Gtid table is not ready to be used. Table <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">mysql.gtid_executed</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> cannot be opened.
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">45</span>.890477Z <span style="color: rgba(128, 0, 128, 1)">1</span> A temporary password is generated <span style="color: rgba(0, 0, 255, 1)">for</span> root@localhost: &amp;<span style="color: rgba(0, 0, 0, 1)">s)nYg.e4qx#
#


<span style="color: rgba(64, 128, 128, 1)"># 初始化3308实例</span>
# </span>/usr/local/mysql/bin/mysqld --defaults-<span style="color: rgba(0, 0, 255, 1)">file</span>=/etc/my.cnf --initialize --basedir=/usr/local/mysql/ --datadir=/mysql/<span style="color: rgba(128, 0, 128, 1)">3308</span>/<span style="color: rgba(0, 0, 0, 1)">data
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">55</span>.237714Z <span style="color: rgba(128, 0, 128, 1)">0</span> TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation <span style="color: rgba(0, 0, 255, 1)">for</span> <span style="color: rgba(0, 0, 255, 1)">more</span><span style="color: rgba(0, 0, 0, 1)"> details).
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">55</span>.442794Z <span style="color: rgba(128, 0, 128, 1)">0</span> InnoDB: New log files created, LSN=<span style="color: rgba(128, 0, 128, 1)">45790</span>
<span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">55</span>.479012Z <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)"> InnoDB: Creating foreign key constraint system tables.
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">55</span>.534839Z <span style="color: rgba(128, 0, 128, 1)">0</span> No existing UUID has been found, so we assume that this is the first <span style="color: rgba(0, 0, 255, 1)">time</span> that this server has been started. Generating a new UUID: e28d1d57-70ba-11ea-a5c4-<span style="color: rgba(0, 0, 0, 1)">000c29fb6200.
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">55</span>.535622Z <span style="color: rgba(128, 0, 128, 1)">0</span> Gtid table is not ready to be used. Table <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">mysql.gtid_executed</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> cannot be opened.
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">10</span>:<span style="color: rgba(128, 0, 128, 1)">55</span>.536387Z <span style="color: rgba(128, 0, 128, 1)">1</span> A temporary password is generated <span style="color: rgba(0, 0, 255, 1)">for</span> root@localhost: Mz&lt;kr!<span style="color: rgba(0, 0, 0, 1)">vsh1yj
#


<span style="color: rgba(64, 128, 128, 1)"># 初始化3309实例</span>
# </span>/usr/local/mysql/bin/mysqld --defaults-<span style="color: rgba(0, 0, 255, 1)">file</span>=/etc/my.cnf --initialize --basedir=/usr/local/mysql/ --datadir=/mysql/<span style="color: rgba(128, 0, 128, 1)">3309</span>/<span style="color: rgba(0, 0, 0, 1)">data
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">11</span>:<span style="color: rgba(128, 0, 128, 1)">05</span>.644331Z <span style="color: rgba(128, 0, 128, 1)">0</span> TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation <span style="color: rgba(0, 0, 255, 1)">for</span> <span style="color: rgba(0, 0, 255, 1)">more</span><span style="color: rgba(0, 0, 0, 1)"> details).
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">11</span>:<span style="color: rgba(128, 0, 128, 1)">05</span>.840498Z <span style="color: rgba(128, 0, 128, 1)">0</span> InnoDB: New log files created, LSN=<span style="color: rgba(128, 0, 128, 1)">45790</span>
<span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">11</span>:<span style="color: rgba(128, 0, 128, 1)">05</span>.879941Z <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)"> InnoDB: Creating foreign key constraint system tables.
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">11</span>:<span style="color: rgba(128, 0, 128, 1)">05</span>.936262Z <span style="color: rgba(128, 0, 128, 1)">0</span> No existing UUID has been found, so we assume that this is the first <span style="color: rgba(0, 0, 255, 1)">time</span> that this server has been started. Generating a new UUID: e8c03ed2-70ba-11ea-a8fb-<span style="color: rgba(0, 0, 0, 1)">000c29fb6200.
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">11</span>:<span style="color: rgba(128, 0, 128, 1)">05</span>.937179Z <span style="color: rgba(128, 0, 128, 1)">0</span> Gtid table is not ready to be used. Table <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">mysql.gtid_executed</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> cannot be opened.
</span><span style="color: rgba(128, 0, 128, 1)">2020</span>-<span style="color: rgba(128, 0, 128, 1)">03</span>-28T06:<span style="color: rgba(128, 0, 128, 1)">11</span>:<span style="color: rgba(128, 0, 128, 1)">05</span>.937877Z <span style="color: rgba(128, 0, 128, 1)">1</span> A temporary password is generated <span style="color: rgba(0, 0, 255, 1)">for</span> root@localhost: K.KLa30i-sv3</pre>
</div>
<p>&nbsp;</p>
<p>(4.8)设置环境变量</p>
<p>添加了环境变量,操作系统才能够自己找到mysql、mysqld_multi等命令的位置</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre># vim /etc/<span style="color: rgba(0, 0, 0, 1)">profile
<span style="color: rgba(64, 128, 128, 1)"># 在文件末尾添加下面信息</span>
export PATH</span>=/usr/local/mysql/<span style="color: rgba(0, 0, 0, 1)">bin:$PATH

<span style="color: rgba(64, 128, 128, 1)">#使环境变量生效</span>
# source </span>/etc/profile</pre>
</div>
<p>&nbsp;</p>
<p>(4.9)使用mysqld_multi管理多实例</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre><span style="color: rgba(0, 0, 0, 1)"><span style="color: rgba(64, 128, 128, 1)"># 使用mysqld_multi启动3306端口的实例</span>
# mysqld_multi start </span><span style="color: rgba(128, 0, 128, 1)">3306</span><span style="color: rgba(0, 0, 0, 1)">

<span style="color: rgba(64, 128, 128, 1)"># 使用mysqld_multi启动全部实例</span>
# mysqld_multi start

<span style="color: rgba(64, 128, 128, 1)"># 使用mysqld_multi查看实例状态</span>
# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3306 is running
MySQL server from group: mysqld3307 is running
MySQL server from group: mysqld3308 is running
MySQL server from group: mysqld3309 is running</span></pre>
</div>
<p>使用mysqld_multi关闭实例较为麻烦,需要配置密码,因此如何关闭各个实例,见后面章节:<strong>(六)关闭多实例数据库 。</strong></p>
<p>&nbsp;</p>
<p><strong>(五)访问多实例数据库</strong></p>
<p>(5.1)登录MySQL数据库</p>
<p>在安装完成并启动数据库后,需要去访问各个MySQL实例,这里非常有意思,经常会发现无法连接到数据库上,我们不妨看一下几种连接方式:</p>
<p><span style="background-color: rgba(223, 206, 4, 1)">连接方式一</span>:使用服务器IP地址,无法连接。这里还是比较好理解的,MySQL创建完成后,数据库账号root@localhost只允许本地连接,参数“-h”后面用服务器IP被认为了远程连接,因此无法登陆</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre># mysql -uoot -p -h192.<span style="color: rgba(128, 0, 128, 1)">168.10</span>.<span style="color: rgba(128, 0, 128, 1)">11</span> -<span style="color: rgba(0, 0, 0, 1)">P3306
Enter password:
ERROR </span><span style="color: rgba(128, 0, 128, 1)">1130</span> (HY000): Host <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">masterdb</span><span style="color: rgba(128, 0, 0, 1)">'</span> is not allowed to connect to this MySQL server</pre>
</div>
<p>&nbsp;</p>
<p><span style="background-color: rgba(223, 206, 4, 1)">连接方式二</span>:使用localhost访问数据库,无法连接。我觉得有些匪夷所思,可以看到,MySQL实例使用的socket文件不对</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre># mysql -uroot -p -hlocalhost -<span style="color: rgba(0, 0, 0, 1)">P3306
Enter password:
ERROR </span><span style="color: rgba(128, 0, 128, 1)">2002</span> (HY000): Can<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">t connect to local MySQL server through socket </span><span style="color: rgba(128, 0, 0, 1)">'</span>/tmp/mysql.sock<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)"> (2)</span></pre>
</div>
<p><span style="background-color: rgba(223, 206, 4, 1)">&nbsp;</span></p>
<p><span style="background-color: rgba(223, 206, 4, 1)">连接方式三</span>:使用127.0.0.1访问数据库,可以连接。有些难以理解,理论上127.0.0.1和localhost是对应的,127.0.0.1可以访问数据库,但是localhost却无法访问</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre># mysql -uroot -p -h127.<span style="color: rgba(128, 0, 128, 1)">0.0</span>.<span style="color: rgba(128, 0, 128, 1)">1</span> -<span style="color: rgba(0, 0, 0, 1)">P3306
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection </span><span style="color: rgba(0, 0, 255, 1)">id</span> is <span style="color: rgba(128, 0, 128, 1)">7</span><span style="color: rgba(0, 0, 0, 1)">
Server version: </span><span style="color: rgba(128, 0, 128, 1)">5.7</span>.<span style="color: rgba(128, 0, 128, 1)">24</span><span style="color: rgba(0, 0, 0, 1)"> MySQL Community Server (GPL)

Copyright (c) </span><span style="color: rgba(128, 0, 128, 1)">2000</span>, <span style="color: rgba(128, 0, 128, 1)">2018</span>, Oracle and/<span style="color: rgba(0, 0, 0, 1)">or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and</span>/<span style="color: rgba(0, 0, 0, 1)">or its
affiliates. Other names may be trademarks of their respective
owners.

Type </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">help;</span><span style="color: rgba(128, 0, 0, 1)">'</span> or <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">\h</span><span style="color: rgba(128, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">for</span> help. Type <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">\c</span><span style="color: rgba(128, 0, 0, 1)">'</span> to <span style="color: rgba(0, 0, 255, 1)">clear</span><span style="color: rgba(0, 0, 0, 1)"> the current input statement.

mysql</span>&gt;<span style="color: rgba(0, 0, 0, 1)"> exit
Bye</span></pre>
</div>
<p><span style="background-color: rgba(223, 206, 4, 1)">&nbsp;</span></p>
<p><span style="background-color: rgba(223, 206, 4, 1)">连接方式四</span>:使用socket文件连接,可以正常访问</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre># mysql -S /tmp/mysql_3306.sock -<span style="color: rgba(0, 0, 0, 1)">p
Enter password:
Welcome to the MySQL monitor.Commands end with ; or \g.
Your MySQL connection </span><span style="color: rgba(0, 0, 255, 1)">id</span> is <span style="color: rgba(128, 0, 128, 1)">4</span><span style="color: rgba(0, 0, 0, 1)">
Server version: </span><span style="color: rgba(128, 0, 128, 1)">5.7</span>.<span style="color: rgba(128, 0, 128, 1)">24</span><span style="color: rgba(0, 0, 0, 1)">

Copyright (c) </span><span style="color: rgba(128, 0, 128, 1)">2000</span>, <span style="color: rgba(128, 0, 128, 1)">2018</span>, Oracle and/<span style="color: rgba(0, 0, 0, 1)">or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and</span>/<span style="color: rgba(0, 0, 0, 1)">or its
affiliates. Other names may be trademarks of their respective
owners.

Type </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">help;</span><span style="color: rgba(128, 0, 0, 1)">'</span> or <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">\h</span><span style="color: rgba(128, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">for</span> help. Type <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">\c</span><span style="color: rgba(128, 0, 0, 1)">'</span> to <span style="color: rgba(0, 0, 255, 1)">clear</span><span style="color: rgba(0, 0, 0, 1)"> the current input statement.

mysql</span>&gt;</pre>
</div>
<p><strong>&nbsp;</strong></p>
<p>(5.2)修改数据库root@localhost密码</p>
<p>初次登陆MySQL数据库,需要修改root密码,否则无法正常使用</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre><span style="color: rgba(255, 0, 0, 1)">[</span><span style="color: rgba(255, 0, 0, 1)">root@masterdb mysql</span><span style="color: rgba(255, 0, 0, 1)">]</span># mysql <span style="color: rgba(128, 128, 128, 1)">-</span>S <span style="color: rgba(128, 128, 128, 1)">/</span>tmp<span style="color: rgba(128, 128, 128, 1)">/</span>mysql_3306.sock <span style="color: rgba(128, 128, 128, 1)">-</span><span style="color: rgba(0, 0, 0, 1)">p
Enter password:
Welcome </span><span style="color: rgba(0, 0, 255, 1)">to</span> the MySQL monitor.Commands <span style="color: rgba(0, 0, 255, 1)">end</span> <span style="color: rgba(0, 0, 255, 1)">with</span> ; <span style="color: rgba(128, 128, 128, 1)">or</span><span style="color: rgba(0, 0, 0, 1)"> \g.
Your MySQL connection id </span><span style="color: rgba(0, 0, 255, 1)">is</span> <span style="color: rgba(128, 0, 0, 1); font-weight: bold">4</span><span style="color: rgba(0, 0, 0, 1)">
Server version: </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">5.7</span>.<span style="color: rgba(128, 0, 0, 1); font-weight: bold">24</span><span style="color: rgba(0, 0, 0, 1)">

Type </span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">help;</span><span style="color: rgba(255, 0, 0, 1)">'</span> <span style="color: rgba(128, 128, 128, 1)">or</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">\h</span><span style="color: rgba(255, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">for</span> help. Type <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">\c</span><span style="color: rgba(255, 0, 0, 1)">'</span> <span style="color: rgba(0, 0, 255, 1)">to</span> clear the <span style="color: rgba(0, 0, 255, 1)">current</span><span style="color: rgba(0, 0, 0, 1)"> input statement.

</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 无法查询</span>
mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span><span style="color: rgba(0, 0, 0, 1)"> show databases;
ERROR </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">1820</span> (HY000): You must reset your password using <span style="color: rgba(0, 0, 255, 1)">ALTER</span> <span style="color: rgba(255, 0, 255, 1)">USER</span><span style="color: rgba(0, 0, 0, 1)"> statement before executing this statement.

</span><span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)"> 修改root@localhost用户的密码</span>
mysql<span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">alter</span> <span style="color: rgba(255, 0, 255, 1)">user</span>root<span style="color: rgba(0, 128, 0, 1)">@localhost</span> identified <span style="color: rgba(0, 0, 255, 1)">by</span> <span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(255, 0, 0, 1)">123456</span><span style="color: rgba(255, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">;
Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)

mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> flush <span style="color: rgba(0, 0, 255, 1)">privileges</span><span style="color: rgba(0, 0, 0, 1)">;
Query OK, </span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">0</span> rows affected (<span style="color: rgba(128, 0, 0, 1); font-weight: bold">0.00</span><span style="color: rgba(0, 0, 0, 1)"> sec)

mysql</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span> <span style="color: rgba(0, 0, 255, 1)">exit</span><span style="color: rgba(0, 0, 0, 1)">
Bye</span></pre>
</div>
<p>&nbsp;</p>
<p><strong>(六)关闭多实例数据库 </strong></p>
<p>(6.1)直接使用mysqld_multi来关闭实例</p>
<p>使用mysqld_multi关闭多实例数据库目前来看比较麻烦,需要在my.cnf文件的模块里面配置用户密码,并且各个数据库的用户密码都需要相同,否则无法关闭。</p>
<p><img style="display: inline; background-image: none" title="image" src="https://img2020.cnblogs.com/blog/823295/202003/823295-20200328153037617-105938576.png" alt="image" width="335" height="104" border="0"></p>
<p>我们可以看一下使用mysqld_multi来关闭数据库实例的日志:</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre># <span style="color: rgba(0, 0, 255, 1)">cat</span> /usr/local/mysql/<span style="color: rgba(0, 0, 0, 1)">mysqld_multi.log

<span style="color: rgba(64, 128, 128, 1)"># 当执行:mysqld_multi report时,显示所有数据库均在运行</span>
Reporting MySQL servers
MySQL server from group: mysqld3306 is running
MySQL server from group: mysqld3307 is running
MySQL server from group: mysqld3308 is running
MySQL server from group: mysqld3309 is running
mysqld_multi log </span><span style="color: rgba(0, 0, 255, 1)">file</span> version <span style="color: rgba(128, 0, 128, 1)">2.16</span>; run: Sat Mar <span style="color: rgba(128, 0, 128, 1)">28</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">55</span>:<span style="color: rgba(128, 0, 128, 1)">16</span> <span style="color: rgba(128, 0, 128, 1)">2020</span></pre>
<span style="color: rgba(64, 128, 128, 1)"># 当执行:mysqld_multi stopt时,mysqld_multi会调用mysqladmin去关闭数据库,使用的是里面配置的账号密码,此时3306的密码是正确的,</span>
<pre><span style="color: rgba(0, 0, 0, 1)"><span style="color: rgba(64, 128, 128, 1)"># 其它都是错误的,因此3306关闭成功,而其它端口的实例因为密码错误而连接数据库失败,自然没有关闭数据库</span>
Stopping MySQL servers

mysqladmin: Using a password on the command line interface can be insecure.
mysqladmin: Using a password on the command line interface can be insecure.
mysqladmin: connect to server at </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">localhost</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> failed
error: </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">Access denied for user </span><span style="color: rgba(128, 0, 0, 1)">'</span>root<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">@</span><span style="color: rgba(128, 0, 0, 1)">'</span>localhost<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)"> (using password: YES)</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
mysqladmin: Using a password on the command line interface can be insecure.
mysqladmin: connect to server at </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">localhost</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> failed
error: </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">Access denied for user </span><span style="color: rgba(128, 0, 0, 1)">'</span>root<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">@</span><span style="color: rgba(128, 0, 0, 1)">'</span>localhost<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)"> (using password: YES)</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
mysqladmin: Using a password on the command line interface can be insecure.
mysqladmin: connect to server at </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">localhost</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> failed
error: </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">Access denied for user </span><span style="color: rgba(128, 0, 0, 1)">'</span>root<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">@</span><span style="color: rgba(128, 0, 0, 1)">'</span>localhost<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)"> (using password: YES)</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
mysqld_multi log </span><span style="color: rgba(0, 0, 255, 1)">file</span> version <span style="color: rgba(128, 0, 128, 1)">2.16</span>; run: Sat Mar <span style="color: rgba(128, 0, 128, 1)">28</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">55</span>:<span style="color: rgba(128, 0, 128, 1)">21</span> <span style="color: rgba(128, 0, 128, 1)">2020</span><span style="color: rgba(0, 0, 0, 1)">

<span style="color: rgba(64, 128, 128, 1)"># 结果:仅仅关闭了密码正确的3306端口数据库</span>
Reporting MySQL servers
MySQL server from group: mysqld3306 is not running
MySQL server from group: mysqld3307 is running
MySQL server from group: mysqld3308 is running
MySQL server from group: mysqld3309 is running
mysqld_multi log </span><span style="color: rgba(0, 0, 255, 1)">file</span> version <span style="color: rgba(128, 0, 128, 1)">2.16</span>; run: Sat Mar <span style="color: rgba(128, 0, 128, 1)">28</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">58</span>:<span style="color: rgba(128, 0, 128, 1)">07</span> <span style="color: rgba(128, 0, 128, 1)">2020</span></pre>
</div>
<p>既然知道了mysqld_multi是调用mysqladmin来关闭数据库的,那最好的办法还是直接使用mysqladmin来关闭各个数据库了,下面演示使用mysqladmin来关闭数据库实例。</p>
<p>&nbsp;</p>
<p>(6.2)使用mysqladmin来关闭实例</p>
<div class="cnblogs_code" style="padding: 5px; border: 1px solid rgba(204, 204, 204, 1); border-image: none; background-color: rgba(245, 245, 245, 1)">
<pre><span style="color: rgba(0, 0, 0, 1)"># mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3306 is running
MySQL server from group: mysqld3307 is running
MySQL server from group: mysqld3308 is running
MySQL server from group: mysqld3309 is running
#
#
# cd
# mysqladmin -h127.<span style="color: rgba(128, 0, 128, 1)">0.0</span>.<span style="color: rgba(128, 0, 128, 1)">1</span> -uroot -p -<span style="color: rgba(0, 0, 0, 1)">P3306 shutdown
Enter password:
#
# mysqladmin -h127.<span style="color: rgba(128, 0, 128, 1)">0.0</span>.<span style="color: rgba(128, 0, 128, 1)">1</span> -uroot -p -<span style="color: rgba(0, 0, 0, 1)">P3307 shutdown
Enter password:
# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3306 is not running
MySQL server from group: mysqld3307 is not running
MySQL server from group: mysqld3308 is running
MySQL server from group: mysqld3309 is running</span></pre>
</div>
<p>最终关闭了3306和3307数据库。</p>
<p><strong>&nbsp;</strong></p>
<p>【结束】</p>
<p>&nbsp;</p>
<table style="width: 800px" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" bgcolor="#ccff66" width="800">
<p><strong>相关文档集合:</strong></p>
<p><strong>1.在一台Linux服务器上安装多个MySQL实例(一)--使用mysqld_multi方式</strong></p>
<p>2.在一台Linux服务器上安装多个MySQL实例(二)--使用单独的MySQL配置文件</p>
</td>

</tr>

</tbody>

</table><br><br>
来源:https://www.cnblogs.com/lijiaman/p/12587630.html
頁: [1]
查看完整版本: 在一台Linux服务器上安装多个MySQL实例(一)--使用mysqld_multi方式