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

mysql多实例安装

时间:2018-09-29 23:50:39      阅读:419      评论:0      收藏:0      [点我收藏+]

标签:closed   安装mysql   table   data   isp   ref   oracle   chown   分享   

mysql多实例安装有两种形式:

  • 同一数据库版本的多实例安装。
  • 不同数据库版本的多实例安装。

同一数据库的多实例安装:

在同一台机器上安装4台mysql数据库实例

从官网下载MySQL5.6版本的二进制免编译安装包,地址如下MySQL5.6下载

和安装一台mysql实例一样,首先要创建mysql用户,创建datadir目录。

[root@test2 mysql]# useradd -M mysql
#创建dataidr目录,因为要安装4个MySQL数据库实例,需要创建4个datadir目录,如下
[root@test2 mysql]# cd /data
[root@test2 data]# ls
mysql  mysql1  mysql2  mysql3 
#修改datadir的目录权限均为MySQL
[root@test2 data]# chonw -R mysql:mysql mysql*

【单机MySQL5.6安装步骤】在MySQL的解压包中有一个INSTALL-BINARY文件,这里面包含了MySQL的单机安装步骤。

[root@test2 mysql]# ls
bin      data  etc      INSTALL-BINARY  man     my-new.cnf  mysql-test  scripts  sql-bench
COPYING  docs  include  lib             my.cnf  mysql.sock  README      share    support-files
[root@test2 mysql]# pwd
/usr/local/mysql
[root@test2 mysql]#

###因为文件比较内容比较多,仅贴了linux安装MySQL的步骤
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &

创建完目录之后需要实例化数据库,因为我们需要安装4个MySQL数据库实例,因此要实例化四次。

cd   /usr/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql1
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql2
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql3
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql4

实例化之后编写配置文件,MySQL的默认端口是3306,四个MySQL实例的端口分别为3306,3307,3308,3309.

技术分享图片
[mysqld_multi]
mysqld     =    /usr/local/mysql/bin/mysqld
mysqladmin =    /usr/local/mysql/bin/mysqladmin
log        =    /tmp/mysql-mulit.log
 
[mysqld0]
log_bin
user=mysql
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
server_id = 6
skip-grant-tables
socket = /tmp/mysql0.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

[mysqld1]
log_bin
user=mysql
basedir = /usr/local/mysql
datadir = /data/mysql1
port = 3307
server_id = 7
skip-grant-tables
socket = /tmp/mysql1.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld2]
log_bin
user=mysql
basedir = /usr/local/mysql
datadir = /data/mysql2
port = 3308
server_id = 8
skip-grant-tables
socket = /tmp/mysql2.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld3]
log_bin
user=mysql
basedir = /usr/local/mysql
datadir = /data/mysql3
port = 3309
server_id = 9
skip-grant-tables
socket = /tmp/mysql3.sock
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
cat /etc/my.cnf

说明: 我们使用了mysld_multi命令,因此在配置文件的开始,我们配置了mysqld_mulit命令的位置。mysqladmin也是一样。log指定了mysqld_multi的日志位置。

后面使用[mysqldX]的形式区分每一个mysql实例的基本配置,在每个实例中要区分每个MySQL的端口号,每个MySQL的套接字文件名,为了使用套接字本地连接,还有每个mysql的datadir指定到对应的目录,要设置每个数据库的server_id不一样。

然后就是启动mysql实例。

[root@test2 mysql]# mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld0 is not running
MySQL server from group: mysqld1 is not running
MySQL server from group: mysqld2 is not running
MySQL server from group: mysqld3 is not running
由上可知mysql实例并没有运行。
mysqld_multi start 0          #启动第一个MySQL实例
mysqld_multi stop 0           #停止指定的MySQL实例
mysqld_multi start              #启动所有的MySQL实例
mysqld_multi stop              #停止所有的MySQL实例

------------------------------------------------
[root@test2 mysql]# mysqld_multi start
[root@test2 mysql]# netstat -lntp
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      1018/sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1282/master         
tcp        0      0 :::22                       :::*                        LISTEN      1018/sshd           
tcp        0      0 :::3306                     :::*                        LISTEN      27486/mysqld        
tcp        0      0 :::3307                     :::*                        LISTEN      27563/mysqld        
tcp        0      0 :::3308                     :::*                        LISTEN      27566/mysqld        
tcp        0      0 :::3309                     :::*                        LISTEN      27569/mysqld        
[root@test2 mysql]# mysql -S /tmp/mysql3.sock    # 使用套接字连接MySQL,也可以指定对应的端口号1进行连接
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.28-log Source distribution

Copyright (c) 2000, 2015, 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多实例(同一版本)已经安装完毕。

不同版本的MySQL多实例安装

【待续】

 

mysql多实例安装

标签:closed   安装mysql   table   data   isp   ref   oracle   chown   分享   

原文地址:https://www.cnblogs.com/wxzhe/p/9726937.html

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