MySQL 5.7多实例安装配置

1. 背景描述

a. MySQL多实例概念

简单的说,就是在一台服务器上面开启多个不同的服务端口(如:3306,3307),运行多个MySQL服务进程,这些服务通过不同的socket监听不同的服务端口来提供各自的服务。

b. MySQL多实例作用与问题

  • 有效利用服务器资源
    资源有剩余时,可充分利用剩余的资源提供服务;
  • 节约服务器资源
    当公司资金紧张,但是服务器又需要各自尽量独立提供服务;而且,需要主从同步技术时,多实例就再好不过了;
  • 资源互相抢占问题
    当某个服务并发很高或者有慢查询时,整个实例会消耗更多的内存,CPU,磁盘IO资源,导致服务器上其它实例提供服务的质量下降;

c. MySQL多实例应用场景

  • 资金紧张的公司
  • 并发访问不是特别大的业务
  • 门户网站应用MySQL多实例场景

2. 环境准备

a. 操作系统:CentOS Linux release 7.6.1810
b. MySQL:mysql-5.7.27.tar.gz,点击下载,准备MySQL的源码编译包
c. boost:boost_1_59_0.tar.gz,点击下载,安装MySQL 5.7的时候,需要依赖boost库,MySQL5.7对应的boost版本是1.59
d. cmake:cmake-2.8.12.2.tar.gz,点击下载,编译安装MySQL时,使用cmake的方式进行编译安装,因此,需要先安装cmake

3. 安装方法

3.1 编译安装cmake

#建议创建个tools目录,将所有的软件包放在一起

[[email protected]_MySQL_5_7_27 ~]# mkdir -p /home/tools/
[[email protected]_MySQL_5_7_27 ~]# cd /home/tools/
[[email protected]_MySQL_5_7_27 tools]# ls -l
total 143932
-rw-r--r--  1 root root 83709983 Jul 31 18:34 boost_1_59_0.tar.gz
-rw-r--r--  1 root root  6068231 Jul 31 18:36 cmake-2.8.12.2.tar.gz
-rw-r--r--  1 root root 54398696 Jul 31 18:34 mysql-5.7.27.tar.gz

#解压cmake安装包

[[email protected]_MySQL_5_7_27 tools]# tar xf cmake-2.8.12.2.tar.gz
[root[email protected]_MySQL_5_7_27 tools]# cd cmake-2.8.12.2
[[email protected]_MySQL_5_7_27 cmake-2.8.12.2]# ll
total 3056
-rwxr-xr-x   1  501 games   53974 Jan 17  2014 bootstrap
-rw-r--r--   1  501 games  254736 Jan 17  2014 ChangeLog.manual
-rw-r--r--   1  501 games 2603523 Jan 17  2014 ChangeLog.txt
-rw-r--r--   1  501 games    5465 Jan 17  2014 CMakeCPack.cmake
-rw-r--r--   1  501 games    3436 Jan 17  2014 CMakeCPackOptions.cmake.in
-rw-r--r--   1  501 games     153 Jan 17  2014 CMakeGraphVizOptions.cmake
-rw-r--r--   1  501 games   25439 Jan 17  2014 CMakeLists.txt
-rw-r--r--   1  501 games    4481 Jan 17  2014 CMakeLogo.gif
-rw-r--r--   1  501 games     796 Jan 17  2014 cmake_uninstall.cmake.in
-rw-r--r--   1  501 games    2515 Jan 17  2014 CompileFlags.cmake
-rwxr-xr-x   1  501 games      99 Jan 17  2014 configure
-rw-r--r--   1  501 games    2637 Jan 17  2014 Copyright.txt
-rw-r--r--   1  501 games    1050 Jan 17  2014 CTestConfig.cmake
-rw-r--r--   1  501 games    3338 Jan 17  2014 CTestCustom.cmake.in
-rw-r--r--   1  501 games     145 Jan 17  2014 CTestCustom.ctest.in
-rw-r--r--   1  501 games     809 Jan 17  2014 DartConfig.cmake
-rw-r--r--   1  501 games    4144 Jan 17  2014 DartLocal.conf.in
drwxr-xr-x   3 root root      142 Aug  1 14:32 Docs
-rw-r--r--   1  501 games   28046 Jan 17  2014 doxygen.config
drwxr-xr-x   4 root root       53 Aug  1 14:32 Example
drwxr-xr-x   9 root root    16384 Aug  1 14:32 Modules
-rw-r--r--   1  501 games    1946 Jan 17  2014 Readme.txt
drwxr-xr-x   7 root root    24576 Aug  1 14:32 Source
drwxr-xr-x   2 root root     4096 Aug  1 14:32 Templates
drwxr-xr-x 169 root root     8192 Aug  1 14:32 Tests
drwxr-xr-x  15 root root     4096 Aug  1 14:32 Utilities

#开始编译安装

[[email protected]_MySQL_5_7_27 cmake-2.8.12.2]# ./configure
...省略
CMake has bootstrapped.  Now run gmake.

#看到“Now run gmake”说明ok,可以进行gmake && gmake install

[[email protected]_MySQL_5_7_27 cmake-2.8.12.2]# gmake
...省略
[100%] Built target pseudonl_valgrind
[[email protected]_MySQL_5_7_27 cmake-2.8.12.2]# gmake install
...省略
-- Installing: /usr/local/share/cmake-2.8/completions/ctest

提示:
每一步结束后,可以使用echo $? ,当返回值为0时,说明编译过程正常

3.2 将boost库解压到/usr/local/目录

#指定解压到/usr/local/目录,使用 -C 参数

[[email protected]_MySQL_5_7_27 tools]# tar xf boost_1_59_0.tar.gz -C /usr/local/
[[email protected]_MySQL_5_7_27 tools]# cd /usr/local/
[[email protected]_MySQL_5_7_27 local]# mv boost_1_59_0/ boost
[[email protected]_MySQL_5_7_27 local]# ls -l
total 0
drwxr-xr-x. 2 root root   45 Jul 30 19:49 bin
drwx------  8  501 games 302 Aug 12  2015 boost
drwxr-xr-x  3 root root   23 Jul 30 19:49 doc
drwxr-xr-x. 2 root root    6 Apr 11  2018 etc
drwxr-xr-x. 2 root root    6 Apr 11  2018 games
drwxr-xr-x. 2 root root    6 Apr 11  2018 include
drwxr-xr-x. 2 root root    6 Apr 11  2018 lib
drwxr-xr-x. 2 root root    6 Apr 11  2018 lib64
drwxr-xr-x. 2 root root    6 Apr 11  2018 libexec
drwxr-xr-x  3 root root   18 Jul 30 19:49 man
drwxr-xr-x. 2 root root    6 Apr 11  2018 sbin
drwxr-xr-x. 7 root root   81 Jul 30 19:49 share
drwxr-xr-x. 2 root root    6 Apr 11  2018 src

3.3 解压MySQL 5.7,并进行编译安装

3.3.1 安装MySQL 5.7的依赖包

[[email protected]_MySQL_5_7_27 tools]# yum install ncurses-devel -y
...省略
Installed:
    ncurses-devel.x86_64 0:5.9-14.20130511.el7_4

Complete!
[[email protected]_MySQL_5_7_27 tools]# yum install libaio-devel -y
...省略
Installed:
  libaio-devel.x86_64 0:0.3.109-13.el7

Dependency Installed:
  libaio.x86_64 0:0.3.109-13.el7

Complete!

提示:
MySQL 5.7依赖的软件包:gcc gcc-c++ ncurses ncurses-devel bison make等供参考,安装前可以使用rpm -qa|grep ${软件包名称}检查一下

3.3.2 创建MySQL文件存放目录,用户和组

#创建MySQL多实例的相关文件目录

[[email protected]_MySQL_5_7_27 tools]# mkdir -p /application/mysql
[[email protected]_MySQL_5_7_27 tools]# mkdir -p /application/mysql/logs
[[email protected]_MySQL_5_7_27 tools]# mkdir -p /application/mysql/data/{3306,3307}/data
[[email protected]_MySQL_5_7_27 tools]# tree -L 3 /application/mysql/data/
/application/mysql/data/
|-- 3306
|   `-- data
`-- 3307
    `-- data

4 directories, 0 files

#创建mysql组和用户

[[email protected]_MySQL_5_7_27 tools]# groupadd mysql
[[email protected]_MySQL_5_7_27 tools]# useradd mysql -s /sbin/nologin -M -g mysql
[[email protected]_MySQL_5_7_27 tools]# id mysql
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)

说明:
-s /sbin/nologin 用户不能登录系统
-M 不创建用户的HOME目录
-g 指定用户登录组的GID或组名

3.3.3 编译安装MySQL 5.7

#解压源码mysql-5.7.27.tar.gz安装包

[[email protected]_MySQL_5_7_27 tools]# cd /home/tools/
[[email protected]_MySQL_5_7_27 tools]# tar xf mysql-5.7.27.tar.gz

#cmake配置编译参数

[[email protected]_MySQL_5_7_27 tools]# cd mysql-5.7.27
[[email protected]_MySQL_5_7_27 mysql-5.7.27]# cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql  -DMYSQL_DATADIR=/application/mysql/data  -DMYSQL_UNIX_ADDR=/application/mysql/tmp/mysql.sock  -DDEFAULT_CHARSET=utf8  -DDEFAULT_COLLATION=utf8_general_ci  -DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii  -DENABLED_LOCAL_INFILE=ON  -DWITH_INNOBASE_STORAGE_ENGINE=1  -DWITH_FEDERATED_STORAGE_ENGINE=1  -DWITH_BLACKHOLE_STORAGE_ENGINE=1  -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1  -DWITHOUT_PARTITION_STORAGE_ENGINE=1  -DWITH_ZLIB=bundled  -DWITH_EMBEDDED_SERVER=1  -DWITH_DEBUG=0  -DWITH_BOOST=/usr/local/boost

#看到如下信息,说明cmake编译完成,执行make继续安装

 -- Configuring done
 -- Generating done
 -- Build files have been written to: /home/tools/mysql-5.7.27

#继续执行make install继续安装

...省略
 Linking CXX executable my_safe_process
 [100%] Built target my_safe_process

#安装完成

...省略
 -- Installing: /application/mysql-5.7.27/share/aclocal/mysql.m4
 -- Installing: /application/mysql-5.7.27/support-files/mysql.server

提示:
如果上述操作未出现错误(每个步骤结束后,都可以使用echo $?看返回值是否为0,为0则表示正确),查看/application/mysql/目录,若其下有内容,则表示MySQL5.7.27源代码包采用cmake方式安装成功了

3.4 配置MySQL系统环境变量

[[email protected]_MySQL_5_7_27 ~]# echo ‘export PATH=/application/mysql/bin:$PATH‘ >>/etc/profile
[[email protected]_MySQL_5_7_27 ~]# tail -1 /etc/profile
export PATH=/application/mysql/bin:$PATH

#使/etc/profile配置文件立即生效

[[email protected]_MySQL_5_7_27 ~]# source /etc/profile
[[email protected]_MySQL_5_7_27 ~]# echo $PATH
/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

3.5 初始化数据库

3.5.1 配置my.cnf文件

#修改/etc/my.cnf文件,和5.6之前的版本不一样,5.7版本support-files目录下没有.cnf文件,因此,需要自己手动编辑

[[email protected]_MySQL_5_7_27 ~]# cp /etc/my.cnf /etc/my.cnf.bak
[[email protected]_MySQL_5_7_27 ~]# vim /etc/my.cnf
[mysqld_multi]
mysqld = /application/mysql/bin/mysqld
mysqladmin = /application/mysql/bin/mysqladmin
log = /application/mysql/logs/mysql_multi.log

[mysqld1]
port = 3306
user = mysql
character_set_server = utf8
socket = /application/mysql/data/3306/mysql.sock
datadir = /application/mysql/data/3306/data
pid-file = /application/mysql/data/3306/mysql.pid
log-bin = /application/mysql/data/3306/mysql-bin
server-id = 1
log-error = /application/mysql/data/3306/mysql_boyu3306.err

[mysqld2]
port = 3307
user = mysql
character_set_server = utf8
socket = /application/mysql/data/3307/mysql.sock
datadir = /application/mysql/data/3307/data
pid-file = /application/mysql/data/3307/mysql.pid
log-bin = /application/mysql/data/3307/mysql-bin
server-id = 3
log-error = /application/mysql/data/3307/mysql_boyu3307.err

提示:
新增MySQL实例时,注意变更my.cnf配置文件及启动脚本文件中的port和server-id,不要和已经运行的实例冲突;

3.5.2 修改my.cnf文件的属主和属组

[[email protected]_MySQL_5_7_27 ~]# chown mysql:mysql /etc/my.cnf

3.5.3 更改MySQL安装目录的属主和属组

[[email protected]_MySQL_5_7_27 ~]# chown -R mysql:mysql /application/mysql/

3.5.4 初始化数据库

[[email protected]_MySQL_5_7_27 data]# cd /application/mysql/
[[email protected]_MySQL_5_7_27 mysql]# ./bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data/3306/data/
2019-08-07T03:33:57.693586Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-07T03:33:57.973904Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-07T03:33:58.013774Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-07T03:33:58.070602Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 30a49b8b-b8c4-11e9-b40d-000c290943d8.
2019-08-07T03:33:58.072487Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
2019-08-07T03:33:58.074274Z 1 [Warning] [email protected] is created with an empty password ! Please consider switching off the --initialize-insecure option.
[[email protected]66012_MySQL_5_7_27 mysql]# ./bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data/3307/data/
2019-08-07T03:34:06.558576Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-07T03:34:06.792397Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-07T03:34:06.835971Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-07T03:34:06.893802Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 35e6eba6-b8c4-11e9-b7dc-000c290943d8.
2019-08-07T03:34:06.896053Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed‘ cannot be opened.
2019-08-07T03:34:06.897815Z 1 [Warning] [email protected] is created with an empty password ! Please consider switching off the --initialize-insecure option.

提示:
初始化时,data目录必须为空目录,否则初始化失败,会报错如下信息

2019-08-07T06:58:34.828541Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting.
2019-08-07T06:58:34.828576Z 0 [ERROR] Aborting

为什么要初始化数据库?
a.初始化的主要目的是创建基础的数据库,例如:生成MySQL库、表等
b.初始化后查看对应实例的数据目录,可以看到如下信息

[[email protected]_MySQL_5_7_27 mysql]# tree -L 3 /application/mysql/data/
/application/mysql/data/
|-- 3306
|   `-- data
|       |-- auto.cnf
|       |-- ib_buffer_pool
|       |-- ibdata1
|       |-- ib_logfile0
|       |-- ib_logfile1
|       |-- mysql
|       |-- performance_schema
|       `-- sys
`-- 3307
    `-- data
        |-- auto.cnf
        |-- ib_buffer_pool
        |-- ibdata1
        |-- ib_logfile0
        |-- ib_logfile1
        |-- mysql
        |-- performance_schema
        `-- sys

10 directories, 10 files

3.5.5 实例开启SSL连接

[[email protected]_MySQL_5_7_27 mysql]# /application/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data/3306/data/
Generating a 2048 bit RSA private key
.....................+++
......+++
writing new private key to ‘ca-key.pem‘
-----
Generating a 2048 bit RSA private key
............+++
.................+++
writing new private key to ‘server-key.pem‘
-----
Generating a 2048 bit RSA private key
........................................................+++
...............................+++
writing new private key to ‘client-key.pem‘
-----
[[email protected]_MySQL_5_7_27 mysql]# /application/mysql/bin/mysql_ssl_rsa_setup --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data/3307/data/
Generating a 2048 bit RSA private key
..................................................................+++
..............................+++
writing new private key to ‘ca-key.pem‘
-----
Generating a 2048 bit RSA private key
.....+++
...............................................................+++
writing new private key to ‘server-key.pem‘
-----
Generating a 2048 bit RSA private key
.........+++
......+++
writing new private key to ‘client-key.pem‘
-----

3.5.6 修改data目录下的server-key.pem文件权限

[[email protected]_MySQL_5_7_27 ~]# cd /application/mysql/data/3306/data/
[[email protected]_MySQL_5_7_27 data]# chmod +r server-key.pem
[[email protected]_MySQL_5_7_27 data]# ls -lh server-key.pem
-rw-r--r-- 1 root root 1.7K Aug  7 15:07 server-key.pem
[[email protected]_MySQL_5_7_27 data]# cd /application/mysql/data/3307/data/
[[email protected]_MySQL_5_7_27 data]# chmod +r server-key.pem
[[email protected]_MySQL_5_7_27 data]# ls -lh server-key.pem
-rw-r--r-- 1 root root 1.7K Aug  7 15:07 server-key.pem

提示:
如果不给文件server-key.pem其他用户和组可读权限的话,当启动数据库的时候,会报如下错误
2019-08-07T06:39:24.111526Z 0 [ERROR] SSL error: Unable to get private key from ‘server-key.pem‘
2019-08-07T06:39:24.111555Z 0 [Warning] Failed to set up SSL because of the following SSL library error: Unable to get private key

3.6 启动MySQL数据库

3.6.1 拷贝启动脚本到/etc/init.d/目录下,改名mysqld_multi,并赋予可执行权限

[[email protected]_MySQL_5_7_27 ~]# cd /application/mysql
[[email protected]_MySQL_5_7_27 mysql]# cp support-files/mysqld_multi.server /etc/init.d/mysqld_multi
[[email protected]_MySQL_5_7_27 mysql]# chmod +x /etc/init.d/mysqld_multi
[[email protected]_MySQL_5_7_27 mysql]# ll /etc/init.d/mysqld_multi
-rwxr-xr-x 1 root root 1061 8月   7 11:38 /etc/init.d/mysqld_multi

3.6.2 修改脚本中MySQL安装目录和bin目录绝对路径

[[email protected]_MySQL_5_7_27 mysql]# diff /application/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multi
17,18c17,18
< basedir=/usr/local/mysql
< bindir=/usr/local/mysql/bin
---
> basedir=/application/mysql
> bindir=/application/mysql/bin

提示:
如果MySQL不是安装在/usr/local/目录下,需要修改多实例mysqld_multi启动脚本,将basedir=${MySQL安装目录},bindir=${MySQL安装目录下的bin目录},否则执行启动脚本会报“Can‘t execute /usr/local/mysql/bin/mysqld_multi from dir /usr/local/mysql”错误;

3.6.3 重新加载系统服务,将MySQL数据库加入开机自启动

[[email protected]_MySQL_5_7_27 mysql]# /bin/systemctl daemon-reload
[[email protected]_MySQL_5_7_27 mysql]# /bin/systemctl enable mysqld_multi
mysqld_multi.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld_multi on
[[email protected]_MySQL_5_7_27 mysql]# chkconfig --list

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use ‘systemctl list-unit-files‘.
      To see services enabled on particular target use
      ‘systemctl list-dependencies [target]‘.

mysqld_multi    0:off   1:off   2:on    3:on    4:on    5:on    6:off
netconsole      0:off   1:off   2:off   3:off   4:off   5:off   6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

3.6.4 启动MySQL数据库,并检查端口监听状态

[[email protected]_MySQL_5_7_27 mysql]# /etc/init.d/mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is not running
MySQL server from group: mysqld2 is not running
[[email protected]_MySQL_5_7_27 mysql]# /etc/init.d/mysqld_multi start
[[email protected]_MySQL_5_7_27 mysql]# netstat -lntup
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      6568/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      6814/master
tcp6       0      0 :::3306                 :::*                    LISTEN      7404/mysqld
tcp6       0      0 :::3307                 :::*                    LISTEN      7407/mysqld
tcp6       0      0 :::22                   :::*                    LISTEN      6568/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      6814/master

3.7 连接MySQL数据库

3.7.1 指定socket登陆3306数据库

[[email protected]_MySQL_5_7_27 mysql]# mysql -S /application/mysql/data/3306/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27-log Source distribution

Copyright (c) 2000, 2019, 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> \q
Bye

3.7.2 指定socket登陆3307数据库

[[email protected]_MySQL_5_7_27 mysql]# mysql -S /application/mysql/data/3307/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.27-log Source distribution

Copyright (c) 2000, 2019, 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> \q
Bye

提示:
a. 本地登录

  • 多实例本地端登陆通过socket文件来指定登陆到哪个实例,此文件具体位置在mysql初始化时指定的,在本机登陆时登陆程序通过socket文件来判断登陆的数据库实例
  • mysql.sock <== 文件是服务器与本地客户端进行通信的Unix套接字文件
  • 例如:mysql -S /application/mysql/data/3306/mysql.sock 登陆3306数据库实例

b. 远程登录

  • 远程登录指定多实例主机中的一个实例,TCP/IP端口(port)来指定所要登录的mysql实例,此端口是在MySQL配置文件my.cnf中指定的。
  • port <== 端口是一种“逻辑连接位置”,客户端程序被分派计算机上特殊服务程序的一种方式
  • 远程登陆案例:
  • grant all privileges on . to [email protected]"192.168.66.11" identified by "boyu123"; #在MySQL服务端给客户端192.168.66.11赋予所有的权限,包括远程访问权限
  • flush privileges; #重新加载mysql授权表
  • select user,host from mysql,user; #查看更改后的结果
  • mysql -uroot -p‘boyu123‘ -h 192.168.66.12 -P 3306 #在192.168.66.11上面执行此条命令,可以远程登陆到数据库

3.8 数据库基本操作

3.8.1 修改多实例登陆密码

[[email protected]_MySQL_5_7_27 mysql]# mysqladmin -u root -p password "boyu123" -S /application/mysql/data/3306/mysql.sock
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[[email protected]_MySQL_5_7_27 mysql]# mysqladmin -u root -p password "boyu123" -S /application/mysql/data/3307/mysql.sock
Enter password:
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.

3.8.2 优雅关闭多实例数据库

#使用MySQL自带的脚本

[[email protected]_MySQL_5_7_27 mysql]# /etc/init.d/mysqld_multi stop
[[email protected]_MySQL_5_7_27 mysql]# ps aux|grep mysqld
root      23962  0.0  0.0 112708   976 pts/0    S+   20:39   0:00 grep --color=auto mysqld

提示:此种方法会同时关闭服务器上面的所有数据库,如果想一个一个关闭的话,可以使用mysqladmin方法

#使用mysqladmin的方法

[[email protected]_MySQL_5_7_27 mysql]# mysqladmin -uroot -p"boyu123" -S /application/mysql/data/3307/mysql.sock shutdown
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
[[email protected]_MySQL_5_7_27 mysql]# ps aux|grep mysqld
mysql     24058  0.1 10.1 1181012 188944 pts/0  Sl   20:39   0:01 /application/mysql/bin/mysqld --port=3306 --user=mysql --character_set_server=utf8 --socket=/application/mysql/data/3306/mysql.sock --datadir=/application/mysql/data/3306/data --pid-file=/application/mysql/data/3306/mysql.pid --log-bin=/application/mysql/data/3306/mysql-bin --server-id=1 --log-error=/application/mysql/data/3306/mysql_boyu3306.err
root      28235  0.0  0.0 112708   976 pts/0    S+   20:51   0:00 grep --color=auto mysqld

原文地址:https://blog.51cto.com/14463906/2427362

时间: 2024-09-29 13:00:38

MySQL 5.7多实例安装配置的相关文章

MySQL多实例安装配置

MySQL多实例安装配置 一.基本概念 MySQL多实例就是,在一台机器上开启多个不同的服务端口(如:3306,3307,3308...),运行多个MySQL服务进程,这些服务进程通过不同的socket监听不同的端口提供服务. MySQL可以共用一套安全程序,使用不同的my.cnf配置文件,启动程序,数据文件. 逻辑上是独立的,但是一个实例过载过高的时候会对其他造成影响. MySQL多实例的作用与问题: 1.有效利用服务器资源 2.节约服务器资源 3.资源互相抢占问题 当某个服务实现并发生很高的

mysql单实例安装配置指南

1.操作系统:CentOS 2.数据库: mysql-5.1.73.tar.gz 3.任务:单实例安装配置指南 提示:下载数据库有两种方式:一种是官网,另一种途径是国内镜象网站:国内镜象下载资源的速度比官网要快,例如,我们这次下载的就是国内搜狐镜象: http://mirrors.sohu.com/mysql/MySQL-5.1/ http://mirrors.sohu.com/ 整个安装过程: [[email protected] tools]#wget http://mirrors.sohu

mysql物理备份工具Xtrabackup安装配置

mysql物理备份工具Xtrabackup安装配置 1????Xtrabackup工具介绍 Xtrabackup是一个对InnoDB做物理数据备份的工具,支持在线热备份(备份时不影响数据读写),是商业备份工具InnoDB Hotbackup的一个很好的替代品. Xtrabackup有两个主要的工具:xtrabackup.innobackupex (1)xtrabackup只能备份InnoDB和XtraDB两种数据表,而不能备份MyISAM数据表. (2)innobackupex是用来备份非Inn

BIND服务企业实例安装配置

BIND服务企业实例安装配置 防伪码:思而不学则罔,学而不思则殆. 前言:BIND是一款开放源码的DNS服务器软件,Bind由美国加州大学Berkeley分校开发和维护的,全名为Berkeley  Internet  Name Domain 它是目前世界上使用最为广泛的DNS. 理论知识: DNS的分类: 主DNS服务器:就是一台存储着原始资料的DNS服务器. 从DNS服务器:使用自动更新方式从主DNS同步数据的DNS服务器.也称为辅助DNS服务器. 缓存服务器:不负责本地解析,采用递归方式转发

MySQL 5.7.9 免安装配置

MySQL 5.7.9 免安装配置 环境:win10 64位 mysql版本:mysql-5.7.9-winx64.zip (http://dev.mysql.com/downloads/mysql/) 首先声明一下,5.7.9这个版本的配置方式跟之前的免安装版配置不一样.(.msi安装版和其他版本的可以忽略该方法) 步骤: 1,在官网上下载了mysql-5.7.9-winx64.zip 这个文件之后, 解压到指定目录:F:\java\mysql\mysql-5.7.9-winx64 2,在F:

Keepalived+Mysql互为主从高可用安装配置

Keepalived+Mysql互为主从高可用安装配置环境介绍:keepalived_vip=192.168.1.210    (写虚拟ip)mysql_master01      eth0:192.168.1.211  eth1:172.20.27.211 (1核1G)mysql_master02      eth0:192.168.1.212  eth1:172.20.27.212 (1核1G) 1.安装mysql数据库(所有节点安装)  //此处省略安装mysql服务2.编辑my.cnf配

Linux 下 MySQL 的彻底卸载和安装配置字符集

前言: Linux环境下MySQL的安装和配置在网上已经有很多教程了.之所以写这篇文章是因为在配置字符集的时候找了网上的一些教程发现并不能用导致折腾了一阵子.下面的教程均是亲自实践. MySQL的彻底卸载 首先查看一下自己是否已经安装了MySQL.代码如下: 1 ps -aux|grep mysql 如未安装则不显示任何内容,若安装则会显示如下的信息: 关于mysql的彻底卸载有很多方法,人工去卸载和删除冗余文件比较麻烦,只需依次执行以下三条指令即可: 1 sudo apt-get autore

Linux下MySQL的彻底卸载和安装配置字符集

前言: Linux环境下MySQL的安装和配置在网上已经有很多教程了.之所以写这篇文章是因为在配置字符集的时候找了网上的一些教程发现并不能用导致折腾了一阵子.下面的教程均是亲自实践. MySQL的彻底卸载 首先查看一下自己是否已经安装了MySQL.代码如下: 1 ps -aux|grep mysql 如未安装则不显示任何内容,若安装则会显示如下的信息: 关于mysql的彻底卸载有很多方法,人工去卸载和删除冗余文件比较麻烦,只需依次执行以下三条指令即可: 1 sudo apt-get autore

MySQL 5.7.10 免安装配置

# 配置环境:windows 64bit # 安装版本:mysql-5.7.10-win32(zip archive版本) 1. ZIP Archive版是免安装的,只需把mysql-5.7.10-win32.zip解压到安装目录即可. 2. 在D:\Program Files\mysql-5.7.10-win32文件夹下新建配置默认文件my.ini,在此文件中需要配置字符编码.该文件会替换文件夹下面的my-default.ini文件(.ini文件是windows里面的配置文件,保存里面各种默认