环境 说明

  1. 10.0.0.121 CentOS 7.3

[root@slave2 tmp]# cat /etc/*release

CentOS Linux release 7.3.1611 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="http://www.qdr.ib358.com/"
BUG_REPORT_URL="http://www.ib911.com/68/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.3.1611 (Core)
CentOS Linux release 7.3.1611 (Core)

MySQL Community Server (GPL) 5.7.21

?

初始化

mysqld --defaults-file=/usr/local/mysql/3306/my.cnf --initialize --basedir=/usr/local/mysql/3306 --datadir=/data/mysql/3306
mysqld --defaults-file=/usr/local/mysql/3307/my.cnf --initialize --basedir=/usr/local/mysql/3307 --datadir=/data/mysql/3307

?

启动多实例

[root@mysql01 ~]# mysqld_safe --defaults-file=/usr/local/mysql/3306/my.cnf &
[root@mysql01 ~]# mysqld_safe --defaults-file=/usr/local/mysql/3307/my.cnf &

?

连接多实例并修改密码

mysql -uroot -pd%+8eIshm?f. -S /tmp/mysql3306.sock

mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.21

Copyright (c) 2000, 2018, 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> set password for root@localhost = password('123');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit


mysql -uroot -p#;rYJI.UP8Lh -S /tmp/mysql3307.sock

停止多实例

[root@mysql01 ~]# mysqladmin -uroot -p123 -S /tmp/mysql3306.sock shutdown
[root@mysql01 ~]# mysqladmin -uroot -p123 -S /tmp/mysql3307.sock shutdown

创建监控用户

????????? 1.为3306实例创建监控用户

[root@slave2 tmp]# mysql -uroot -p123 -S /tmp/mysql3306.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> CREATE USER 'monitor'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO? 'monitor'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye

?

2. 为3307实例创建监控用户

[root@slave2 tmp]# mysql -uroot -p123 -S /tmp/mysql3307.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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>? CREATE USER 'monitor'@'%' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO? 'monitor'@'%';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye