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

mysql-5.6.36单/多实例部署

时间:2019-06-14 16:42:02      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:hat   mysq   orm   inux   long   地址   object   端口号   nod   

mysql多实例部署

实验环境

mysql-1:10.0.0.101
?
mysql-2:10.0.0.102
?
centos 6.9

 

 

mysql的源码安装

[root@mysql-1 3306]# cat /etc/redhat-release 
CentOS release 6.9 (Final)
关闭iptables和selinux
安装mysql-5.6.36
##安装前期准备
#1、创建安装目录及软件包下载目录
[ -e /tools ]||mkdir -p /tools
[ -e /application ]||mkdir -p /application
#2、创建mysql的虚拟用户mysql
 useradd mysql -M -s /sbin/nologin
##源码编译安装
#1、安装依赖
yum install -y ncurese-devel libaio-devel
#2、安装cmake
yum install -y cmake
#3、下载mysql-5.6.36 cd /tools目录
下载地址:https://www.mysql.com/downloads/
#4、解压mysql-5.6.36
 cd /tools
 tar xf mysql-5.6.36.tar.gz
#5、进入mysql-5-6-36的目录源码编译安装
  cd /tools/mysql-5.6.26
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.36 \
-DMYSQL_DATADIR=/application/mysql-5.6.36/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.6.36/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0
?
make && make install
?
##配置和启用
#1、创建软连接
ln -s /application/mysql-5.6.36 /application/mysql
#2、拷贝配置文件到/etc
\cp /application/mysql/support-files/my-default.cnf /etc/my.cnf
#3、初始化数据库
/application/mysql/scripts/mysql_install_db --basedir=/application/mysql --datadir=/application/mysql/data --user=mysql
#4、创建相关命令并授权
#创建mysql.sock所在目录/application/mysql/tmp并授权mysql的属主和属组
mkdir -p /application/mysql/tmp
chown -R /application/mysql/tmp
#创建mysql的数据存放目录/application/mysql/data并授权mysql的属主和属组
mkdir -p /application/mysql/data
chown -R /application/mysql/data
#5、复制启动脚本到/etc/init.d/mysqld
cd /applcation/mysql/support-files
\cp mysql.server /etc/init.d/mysqld
#6、配置mysql的环境变量
echo ‘PATH=/application/mysql/bin/:$PATH‘ >>/etc/profil
source /etc/profile
#7、启动数据库
/etc/init.d/mysqld start
?
Starting MySQL. SUCCESS!
[root@mysql-2 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.36 Source distribution
?
Copyright (c) 2000, 2017, 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>
?

多实例部署

什么是多实例?
   MySQL多实例就是在一台服务器上同时开启多个不同的服务端口(如3306、3307),同时运行多个MySQL服务进程,这些服务进程通过不同的socket监听不同的服务端口来提供服务。
这些MySQL多实例共用一套MySQL安装程序,使用不同的my.cnf配置文件、启动程序(也可以相同)和数据文件。在提供服务时,多实例MySQL在逻辑上看起来是各自独立的,它们根据配置文件的对应设定值来获得服务器相应数量的硬件资源。
?
  打个比方吧,MySQL多实例就相当于房子的多个卧室,每个实例可以看作是一间卧室,整个服务器就是一套房子,服务器的硬件资源(cpu、mem、disk)、软件资源(CentOS操作系统)可以看作是房子的卫生间、厨房、客厅,是房子的公用资源。若你是北漂的小伙伴,与朋友一起租房,相信对此能有更好地理解,大家蜗居在一起,休息时在自己的卧室,但出来活动肯定是要共用上述公共资源的。图4-1是MySQL多实例形象示意图。

技术图片

技术图片


作用:
  1、可以有效利用服务器资源。但单个服务器资源有剩余时,可以充分利用剩余的资源提供更多的服务,可以实现资源的逻辑隔离。
  2、节约服务资源。如果公司资金紧张,但是数据库又需要各自尽量独立地提供服务,而且还需要用到主从复制等技术,可以选择多实例。
缺点:
  存在资源互相抢占的问题。比如,会存在资源互相抢占的问题。当某个数据库实例并发很高或者有SQL慢查询时,整个实例会消耗大量的系统CPU、磁盘I/O等资源,导致服务器上的其他数据库实例提供服务的质量一起下降。这就相当于大家住在一个房子的不同卧室中,早晨起来上班,都要刷牙、洗脸等,这样卫生间就会长期处于占用状态,其他人则必须要等待。不同实例获取的资源是相对独立的,无法像虚拟化一样完全隔离。

单一配置文件、单一启动程序多实例部署方案(不推荐)

?
[mysqld_multi]
mysqld     = /application/mysql/bin/mysqld_safe
mysqladmin = /application/mysql/bin/mysqladmin
user       = mysql
[mysqld1]
socket     = /data/3306/mysql.sock
port       = 3306
pid-file   = /data/3306/mysql.pid
datadir   = /data/3306/data
user       = mysql
[mysqld2]
socket     = /data/3307/mysql.sock
port       = 3307
pid-file   = /data/3307/mysql.pid
datadir   = /data/3307/data
user       = mysql
skip-name-resolve
server-id=10
default-storage-engine=innodb
innodb_buffer_pool_size=512M
innodb_additional_mem_pool=10M
default_character_set=utf8
character_set_server=utf8
#read-only
relay-log-space-limit=3G
expire_logs_day=20
启动mysql
mysqld_multi --config-file=/data/mysql/my_multi.cnf start 1,2
?
了解即可,不推荐使用

多配置文件、多启动程序部署方案(推荐)

[root@mysql-1 ~]# tree -L 2 /data
/data
├── 3306
│   ├── data     #3306实例的数据文件
│   ├── my.cnf   #3306实例的配置文件
└── 3307
  ├── data     #3307实例的数据文件
  ├── my.cnf   #3307实例的配置文件
 
mysql-5.6.36的安装过程省略
#创建mysql多实例的数据文件目录
mkdir -p /data/{3306,3307}/data
[root@mysql-1 ~]# tree -L 2 /data
/data
├── 3306      #3306的实例目录
│   ├── data  #3306的数据目录

└── 3307      #3307的实例目录
    ├── data  #3307的数据目录
    
#创建mysql多实例的配置文件
#mysql5.6版本中有一个模板文件,mysql5.5及以下数据库默认为用户提供多个配置文件模板
[root@mysql-1 ~]# ll /application/mysql/support-files/*.cnf
-rw-r--r--. 1 mysql mysql 1126 Jun 14 02:08 /application/mysql/support-files/my-default.cnf
    
#给/etc目录下的my.cnf配置文件改名
mv /etc/my.cnf /etc/my.cnf.bak
    
注意:
    在系统的/etc目录下存在一个my.cnf,将其改名或删除,否则该配置文件会干扰源码安装的mysql的正确的配置文件,造成无法启动。
    启动mysql服务时,按照一定的顺序搜索my.cnf。先在/etc目录下查找,然后为$basedir/my.cnf,本例中就在/application/mysql/my.cnf,这是新版mysql的配置文件的默认位置。

#如果是单例的配置文件模板,可以直接覆盖/etc目录下的my.cnf配置文件
#如果是多实例,为了让mysql多实例之间彼此独立,需要为每一个实例建立一个my.cnf配置文件,让他们对应自己的数
#据文件目录data
vim /data/3306/my.cnf
vim /data/3307/my.cnf

vim /data/3306/my.cnf
[client]   #客户端模块
port = 3306 #客户端端口号
socket = /data/3306/mysql.sock 

[mysqld] #服务端模块
user = mysql
port = 3306
socket = /data/3306/mysql.sock
basedir = /application/mysql #mysql源码安装的路径
datadir = /data/3306/data #3306实例的数据文件
log-bin = /data/3306/datae
server-id = 101

[mysql-safe] #启动服务模块
log-errot = /data/3306/mysql_1.err #错误日志
pid-file = /data/3306/mysql.pid
vim /data/3307/my.cnf
[client]   #客户端模块
port = 3307 #客户端端口号
socket = /data/3307/mysql.sock 

[mysqld] #服务端模块
user = mysql
port = 3307
socket = /data/3307/mysql.sock
basedir = /application/mysql #mysql源码安装的路径
datadir = /data/3307/data #3307实例的数据文件
log-bin = /data/3307/datae
server-id = 102

[mysql-safe] #启动服务模块
log-errot = /data/3307/mysql_1.err #错误日志
pid-file = /data/3307/mysql.pid
[root@mysql-1 ~]# tree /data
/data
|-- 3306
|   |-- data
|   `-- my.cnf   #<==这个就是3306实例的配置文件。
`-- 3307
    |-- data
    `-- my.cnf   #<==这个就是3307实例的配置文件。
初始化mysql多实例的数据库
cd /application/mysql/scripts
./mysql_install_db --defaults-file=/data/3306/my.cnf --basedir=/application/mysql --datadir=/data/3306/data --user=mysql

./mysql_install_db --defaults-file=/data/3307/my.cnf --basedir=/application/mysql --datadir=/data/3307/data --user=mysql

--defaults-file指定配置文件的位置
初始化后的结果
tree /data
/data/
├── 3306
│   ├── data
│   │   ├── auto.cnf
│   │   ├── ibdata1
│   │   ├── ib_logfile0
│   │   ├── ib_logfile1
│   │   ├── mysql
│   │   │   ├── columns_priv.frm
│   │   │   ├── columns_priv.MYD
│   │   │   ├── columns_priv.MYI
│   │   │   ├── db.frm
│   │   │   ├── db.MYD
│   │   │   ├── db.MYI
│   │   │   ├── event.frm
│   │   │   ├── event.MYD
│   │   │   ├── event.MYI
│   │   │   ├── func.frm
│   │   │   ├── func.MYD
│   │   │   ├── func.MYI
│   │   │   ├── general_log.CSM
│   │   │   ├── general_log.CSV
│   │   │   ├── general_log.frm
│   │   │   ├── help_category.frm
│   │   │   ├── help_category.MYD
│   │   │   ├── help_category.MYI
│   │   │   ├── help_keyword.frm
│   │   │   ├── help_keyword.MYD
│   │   │   ├── help_keyword.MYI
│   │   │   ├── help_relation.frm
│   │   │   ├── help_relation.MYD
│   │   │   ├── help_relation.MYI
│   │   │   ├── help_topic.frm
│   │   │   ├── help_topic.MYD
│   │   │   ├── help_topic.MYI
│   │   │   ├── innodb_index_stats.frm
│   │   │   ├── innodb_index_stats.ibd
│   │   │   ├── innodb_table_stats.frm
│   │   │   ├── innodb_table_stats.ibd
│   │   │   ├── ndb_binlog_index.frm
│   │   │   ├── ndb_binlog_index.MYD
│   │   │   ├── ndb_binlog_index.MYI
│   │   │   ├── plugin.frm
│   │   │   ├── plugin.MYD
│   │   │   ├── plugin.MYI
│   │   │   ├── proc.frm
│   │   │   ├── proc.MYD
│   │   │   ├── proc.MYI
│   │   │   ├── procs_priv.frm
│   │   │   ├── procs_priv.MYD
│   │   │   ├── procs_priv.MYI
│   │   │   ├── proxies_priv.frm
│   │   │   ├── proxies_priv.MYD
│   │   │   ├── proxies_priv.MYI
│   │   │   ├── servers.frm
│   │   │   ├── servers.MYD
│   │   │   ├── servers.MYI
│   │   │   ├── slave_master_info.frm
│   │   │   ├── slave_master_info.ibd
│   │   │   ├── slave_relay_log_info.frm
│   │   │   ├── slave_relay_log_info.ibd
│   │   │   ├── slave_worker_info.frm
│   │   │   ├── slave_worker_info.ibd
│   │   │   ├── slow_log.CSM
│   │   │   ├── slow_log.CSV
│   │   │   ├── slow_log.frm
│   │   │   ├── tables_priv.frm
│   │   │   ├── tables_priv.MYD
│   │   │   ├── tables_priv.MYI
│   │   │   ├── time_zone.frm
│   │   │   ├── time_zone_leap_second.frm
│   │   │   ├── time_zone_leap_second.MYD
│   │   │   ├── time_zone_leap_second.MYI
│   │   │   ├── time_zone.MYD
│   │   │   ├── time_zone.MYI
│   │   │   ├── time_zone_name.frm
│   │   │   ├── time_zone_name.MYD
│   │   │   ├── time_zone_name.MYI
│   │   │   ├── time_zone_transition.frm
│   │   │   ├── time_zone_transition.MYD
│   │   │   ├── time_zone_transition.MYI
│   │   │   ├── time_zone_transition_type.frm
│   │   │   ├── time_zone_transition_type.MYD
│   │   │   ├── time_zone_transition_type.MYI
│   │   │   ├── user.frm
│   │   │   ├── user.MYD
│   │   │   └── user.MYI
│   │   ├── mysql-1.err
│   │   ├── performance_schema
│   │   │   ├── accounts.frm
│   │   │   ├── cond_instances.frm
│   │   │   ├── db.opt
│   │   │   ├── events_stages_current.frm
│   │   │   ├── events_stages_history.frm
│   │   │   ├── events_stages_history_long.frm
│   │   │   ├── events_stages_summary_by_account_by_event_name.frm
│   │   │   ├── events_stages_summary_by_host_by_event_name.frm
│   │   │   ├── events_stages_summary_by_thread_by_event_name.frm
│   │   │   ├── events_stages_summary_by_user_by_event_name.frm
│   │   │   ├── events_stages_summary_global_by_event_name.frm
│   │   │   ├── events_statements_current.frm
│   │   │   ├── events_statements_history.frm
│   │   │   ├── events_statements_history_long.frm
│   │   │   ├── events_statements_summary_by_account_by_event_name.frm
│   │   │   ├── events_statements_summary_by_digest.frm
│   │   │   ├── events_statements_summary_by_host_by_event_name.frm
│   │   │   ├── events_statements_summary_by_thread_by_event_name.frm
│   │   │   ├── events_statements_summary_by_user_by_event_name.frm
│   │   │   ├── events_statements_summary_global_by_event_name.frm
│   │   │   ├── events_waits_current.frm
│   │   │   ├── events_waits_history.frm
│   │   │   ├── events_waits_history_long.frm
│   │   │   ├── events_waits_summary_by_account_by_event_name.frm
│   │   │   ├── events_waits_summary_by_host_by_event_name.frm
│   │   │   ├── events_waits_summary_by_instance.frm
│   │   │   ├── events_waits_summary_by_thread_by_event_name.frm
│   │   │   ├── events_waits_summary_by_user_by_event_name.frm
│   │   │   ├── events_waits_summary_global_by_event_name.frm
│   │   │   ├── file_instances.frm
│   │   │   ├── file_summary_by_event_name.frm
│   │   │   ├── file_summary_by_instance.frm
│   │   │   ├── host_cache.frm
│   │   │   ├── hosts.frm
│   │   │   ├── mutex_instances.frm
│   │   │   ├── objects_summary_global_by_type.frm
│   │   │   ├── performance_timers.frm
│   │   │   ├── rwlock_instances.frm
│   │   │   ├── session_account_connect_attrs.frm
│   │   │   ├── session_connect_attrs.frm
│   │   │   ├── setup_actors.frm
│   │   │   ├── setup_consumers.frm
│   │   │   ├── setup_instruments.frm
│   │   │   ├── setup_objects.frm
│   │   │   ├── setup_timers.frm
│   │   │   ├── socket_instances.frm
│   │   │   ├── socket_summary_by_event_name.frm
│   │   │   ├── socket_summary_by_instance.frm
│   │   │   ├── table_io_waits_summary_by_index_usage.frm
│   │   │   ├── table_io_waits_summary_by_table.frm
│   │   │   ├── table_lock_waits_summary_by_table.frm
│   │   │   ├── threads.frm
│   │   │   └── users.frm
│   │   └── test
│   ├── my.cnf
│   ├── mysql-bin.000001
│   ├── mysql-bin.000002
│   ├── mysql-bin.000003
│   ├── mysql-bin.000004
│   └── mysql-bin.index
......省略


启动多实例
#先关闭单实例,并且开机不自启动
/etc/init.d/mysqld stop
chkconfig mysql off
#使用mysqld_safe命令来启动多实例
#启动3306实例
mysqld_safe --defaults-file=/data/3306/my.cnf > /dev/null 2>&1 &
#启动3307实例
mysqld_safe --defaults-file=/data/3307/my.cnf > /dev/null 2>&1 &

[root@mysql-1 ~]# ps -ef|grep mysql 
root      29404  27026  0 11:22 pts/0    00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf
mysql     29553  29404  0 11:22 pts/0    00:00:00 /application/mysql/bin/mysqld --defaults-file=/data/3306/my.cnf --basedir=/application/mysql --datadir=/data/3306/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/data/3306/data/mysql-1.err --pid-file=/data/3306/data/mysql-1.pid --socket=/data/3306/mysql.sock --port=3306
root      29577  27026  0 11:23 pts/0    00:00:00 /bin/sh /application/mysql/bin/mysqld_safe --defaults-file=/data/3307/my.cnf
mysql     29725  29577 21 11:23 pts/0    00:00:05 /application/mysql/bin/mysqld --defaults-file=/data/3307/my.cnf --basedir=/application/mysql --datadir=/data/3307/data --plugin-dir=/application/mysql/lib/plugin --user=mysql --log-error=/data/3307/data/mysql-1.err --pid-file=/data/3307/data/mysql-1.pid --socket=/data/3307/mysql.sock --port=3307

登录多实例

#登录实例3306
[root@mysql-1 ~]# mysql -S /data/3306/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.36-log Source distribution

Copyright (c) 2000, 2017, 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> 

#登录实例3307
[root@mysql-1 ~]# mysql -S /data/3307/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.36-log Source distribution

Copyright (c) 2000, 2017, 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> 

配置mysql管理员root密码

[root@mysql-1 ~]# mysqladmin -u root -S /data/3306/mysql.sock password ‘123456‘
Warning: Using a password on the command line interface can be insecure.

[root@mysql-1 ~]# mysqladmin -u root -S /data/3307/mysql.sock password ‘123456‘
Warning: Using a password on the command line interface can be insecure.
    
#测试实例3306登录
[root@mysql-1 ~]# mysql -u root -S /data/3306/mysql.sock -p123456
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 5
Server version: 5.6.36-log Source distribution

Copyright (c) 2000, 2017, 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> 

#测试3307实例登录
[root@mysql-1 ~]# mysql -u root -S /data/3307/mysql.sock -p123456
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 8
Server version: 5.6.36-log Source distribution

Copyright (c) 2000, 2017, 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> 


远程登录多实例

在mysql-2:10.0.0.102上登录mysql-1:10.0.0.101的多实例
为了方便我们验证登录的是那个实例的数据库,所有,我们在3306创建一个ywx3306的库;3307创建一个ywx3307的库

[root@mysql-1 ~]# mysql -u root -S /data/3306/mysql.sock -p123456 -e "show databases;"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| ywx3306            |
+--------------------+

[root@mysql-1 ~]# mysql -u root -S /data/3307/mysql.sock -p123456 -e "show databases;"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| ywx3307            |
+--------------------+


 

开通多实例3306和3307管理员用户root的远程访问在10.0.0.0/24

3306
[root@mysql-1 ~]# mysql -u root -p123456 -S /data/3306/mysql.sock
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 9
Server version: 5.6.36-log Source distribution

Copyright (c) 2000, 2017, 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> grant all on *.* to root@‘10.0.0.%‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.08 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | mysql-1   |                                           |
| root | 127.0.0.1 |                                           |
| root | ::1       |                                           |
|      | localhost |                                           |
|      | mysql-1   |                                           |
| root | 10.0.0.%  | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+-----------+-------------------------------------------+
7 rows in set (0.00 sec)

mysql> 
[root@mysql-1 ~]# mysql -u root -p123456 -S /data/3307/mysql.sock
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 10
Server version: 5.6.36-log Source distribution

Copyright (c) 2000, 2017, 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> grant all on *.* to root@‘10.0.0.%‘ identified by ‘123456‘;
Query OK, 0 rows affected (0.00 sec)

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

mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host      | password                                  |
+------+-----------+-------------------------------------------+
| root | localhost | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| root | mysql-1   |                                           |
| root | 127.0.0.1 |                                           |
| root | ::1       |                                           |
|      | localhost |                                           |
|      | mysql-1   |                                           |
| root | 10.0.0.%  | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
+------+-----------+-------------------------------------------+
7 rows in set (0.00 sec)

mysql> 

我们在mysql-2:10.0.0.102上远程访问多实例数据库
******要加上-P(大写),来确定访问实例的端口号******

[root@mysql-2 ~]# mysql -u root -p123456 -h 10.0.0.101 -P 3306 -e "show databases;"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| ywx3306            |
+--------------------+

    
[root@mysql-2 ~]# mysql -u root -p123456 -h 10.0.0.101 -P 3307 -e "show databases;"
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| ywx3307            |
+--------------------+

多实例的关闭

使用mysqladmin来关闭多实例
mysqladmin -u root -p123456 -S /data/3306/mysql.sock shutdown
mysqladmin -u root -p123456 -S /data/3307/mysql.sock shutdown

[root@mysql-1 ~]# ps -ef |grep mysql
root      29797  27026  0 11:52 pts/0    00:00:00 grep mysql

 

mysql-5.6.36单/多实例部署

标签:hat   mysq   orm   inux   long   地址   object   端口号   nod   

原文地址:https://www.cnblogs.com/yaokaka/p/11023706.html

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