码迷,mamicode.com
首页 > 数据库 > 详细

MySQL 5.7多实例安装配置

时间:2019-08-07 16:18:28      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:https   RoCE   stc   ESS   一起   mct   简单   fir   cto   

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目录,将所有的软件包放在一起

[root@192168066012_MySQL_5_7_27 ~]# mkdir -p /home/tools/
[root@192168066012_MySQL_5_7_27 ~]# cd /home/tools/
[root@192168066012_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安装包

[root@192168066012_MySQL_5_7_27 tools]# tar xf cmake-2.8.12.2.tar.gz
[root@192168066012_MySQL_5_7_27 tools]# cd cmake-2.8.12.2
[root@192168066012_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

#开始编译安装

[root@192168066012_MySQL_5_7_27 cmake-2.8.12.2]# ./configure
...省略
CMake has bootstrapped.  Now run gmake.

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

[root@192168066012_MySQL_5_7_27 cmake-2.8.12.2]# gmake
...省略
[100%] Built target pseudonl_valgrind
[root@192168066012_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 参数

[root@192168066012_MySQL_5_7_27 tools]# tar xf boost_1_59_0.tar.gz -C /usr/local/
[root@192168066012_MySQL_5_7_27 tools]# cd /usr/local/
[root@192168066012_MySQL_5_7_27 local]# mv boost_1_59_0/ boost
[root@192168066012_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的依赖包

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

Complete!
[root@192168066012_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多实例的相关文件目录

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

4 directories, 0 files

#创建mysql组和用户

[root@192168066012_MySQL_5_7_27 tools]# groupadd mysql
[root@192168066012_MySQL_5_7_27 tools]# useradd mysql -s /sbin/nologin -M -g mysql
[root@192168066012_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安装包

[root@192168066012_MySQL_5_7_27 tools]# cd /home/tools/
[root@192168066012_MySQL_5_7_27 tools]# tar xf mysql-5.7.27.tar.gz

#cmake配置编译参数

[root@192168066012_MySQL_5_7_27 tools]# cd mysql-5.7.27
[root@192168066012_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系统环境变量

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

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

[root@192168066012_MySQL_5_7_27 ~]# source /etc/profile
[root@192168066012_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文件,因此,需要自己手动编辑

[root@192168066012_MySQL_5_7_27 ~]# cp /etc/my.cnf /etc/my.cnf.bak
[root@192168066012_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文件的属主和属组

[root@192168066012_MySQL_5_7_27 ~]# chown mysql:mysql /etc/my.cnf

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

[root@192168066012_MySQL_5_7_27 ~]# chown -R mysql:mysql /application/mysql/

3.5.4 初始化数据库

[root@192168066012_MySQL_5_7_27 data]# cd /application/mysql/
[root@192168066012_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] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
[root@192168066012_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] root@localhost 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.初始化后查看对应实例的数据目录,可以看到如下信息

[root@192168066012_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连接

[root@192168066012_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‘
-----
[root@192168066012_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文件权限

[root@192168066012_MySQL_5_7_27 ~]# cd /application/mysql/data/3306/data/
[root@192168066012_MySQL_5_7_27 data]# chmod +r server-key.pem
[root@192168066012_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
[root@192168066012_MySQL_5_7_27 data]# cd /application/mysql/data/3307/data/
[root@192168066012_MySQL_5_7_27 data]# chmod +r server-key.pem
[root@192168066012_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,并赋予可执行权限

[root@192168066012_MySQL_5_7_27 ~]# cd /application/mysql
[root@192168066012_MySQL_5_7_27 mysql]# cp support-files/mysqld_multi.server /etc/init.d/mysqld_multi
[root@192168066012_MySQL_5_7_27 mysql]# chmod +x /etc/init.d/mysqld_multi
[root@192168066012_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目录绝对路径

[root@192168066012_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数据库加入开机自启动

[root@192168066012_MySQL_5_7_27 mysql]# /bin/systemctl daemon-reload
[root@192168066012_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
[root@192168066012_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数据库,并检查端口监听状态

[root@192168066012_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
[root@192168066012_MySQL_5_7_27 mysql]# /etc/init.d/mysqld_multi start
[root@192168066012_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数据库

[root@192168066012_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数据库

[root@192168066012_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 root@"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 修改多实例登陆密码

[root@192168066012_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.
[root@192168066012_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自带的脚本

[root@192168066012_MySQL_5_7_27 mysql]# /etc/init.d/mysqld_multi stop
[root@192168066012_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的方法

[root@192168066012_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.
[root@192168066012_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

MySQL 5.7多实例安装配置

标签:https   RoCE   stc   ESS   一起   mct   简单   fir   cto   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!