MySQL多实例就是在一台机器上开启多个不同的服务端口(如:3306,3307,3308),运行多个MySQL服务进程,通过不同的socket监听不同的服务端口来提供各自的服务。各个实例之间是相互独立的,每个实例的datadir, port, socket, pid都是不同的。
3、每一个实例单独一个my.cnf配置文件:
datadir: /mydata/data/3306 /mydata/data/3307 my.cnf: /mydata/data/3306/my.cnf /mydata/data/3307/my.cnf4、安装MySQL(通用二进制方式)
下面介绍开始安装:
1:添加用户和组
[root@CentOS mysql]# groupadd mysql [root@CentOS mysql]# useradd -r -g mysql mysql
[root@CentOS ~]# cd /tmp [root@CentOS tmp]# ll mysql-5.6.27-linux-glibc2.5-i686.tar.gz -rw-r--r--. 1 root root 304056226 11月 17 04:12 mysql-5.6.27-linux-glibc2.5-i686.tar.gz [root@CentOS tmp]# tar zxf mysql-5.6.27-linux-glibc2.5-i686.tar.gz -C /usr/local/ [root@CentOS tmp]# cd /usr/local/ [root@CentOS local]# mv mysql-5.6.27-linux-glibc2.5-i686/ mysql [root@CentOS local]# chown -R mysql:mysql mysql/
[root@CentOS local]# mkdir /mydata/data/{3306,3307}/data -p [root@CentOS mysql]# chown -R mysql:mysql /mydata [root@CentOS data]# tree /mydata/data/ /mydata/data/ ├── 3306 │ └── data └── 3307 └── data 4 directories, 0 files
[root@CentOS data]# cp /usr/local/mysql/support-files/my-default.cnf /mydata/data/3306/my.cnf [root@CentOS data]# cp /usr/local/mysql/support-files/my-default.cnf /mydata/data/3307/my.cnf [root@CentOS data]# tree /mydata/data/ /mydata/data/ ├── 3306 │ ├── data │ └── my.cnf └── 3307 ├── data └── my.cnf 4 directories, 2 files/mydata/data/3306/my.cnf# 这里是实验环境,所以简单配置。请各位看官根据实际需求调整
[root@CentOS 3306]# vi /mydata/data/3306/my.cnf [client] password = 123456 port = 3306 socket = /mydata/data/3306/mysql_3306.sock default-character-set=utf8 [mysqld] port = 3306 socket = /mydata/data/3306/mysql_3306.sock pid-file = /mydata/data/3306/mysql.pid user = mysql basedir = /usr/local/mysql datadir = /mydata/data/3306 character_set_server=utf8 character_set_client=utf8 collation-server=utf8_general_ci lower_case_table_names=1 max_connections=1000 [root@CentOS 3306]# vi /mydata/data/3307/my.cnf [client] password = 123456 port = 3307 socket = /mydata/data/3307/mysql_3307.sock default-character-set=utf8 [mysqld] port = 3307 socket = /mydata/data/3307/mysql_3307.sock pid-file = /mydata/data/3307/mysql.pid user = mysql basedir = /usr/local/mysql datadir = /mydata/data/3307 character_set_server=utf8 character_set_client=utf8 collation-server=utf8_general_ci lower_case_table_names=1 max_connections=1000
8、启动/关闭 实例
[root@CentOS 3307]# netstat -tulpn | grep -i mysql [root@CentOS 3307]# mysqld_safe --defaults-file=/mydata/data/3306/my.cnf 2>&1 > /dev/null & [1] 2026 [root@CentOS 3307]# mysqld_safe --defaults-file=/mydata/data/3307/my.cnf 2>&1 > /dev/null & [2] 2251 [root@CentOS 3307]# netstat -tulpn | grep -i mysql tcp 0 0 :::3306 :::* LISTEN 2229/mysqld tcp 0 0 :::3307 :::* LISTEN 2454/mysqld # 关闭实例,这里mysql的root用户并没有设置密码,密码提示直接敲 Enter即可 [root@CentOS 3306]# mysqladmin -uroot -p -S /mydata/data/3306/mysql_3306.sock shutdown Enter password: [1]- Done mysqld_safe --defaults-file=/mydata/data/3306/my.cnf &>/dev/null (wd: /mydata/data/3307) (wd now: /mydata/data/3306) [root@CentOS 3306]# mysqladmin -uroot -p -S /mydata/data/3307/mysql_3307.sock shutdown Enter password: [2]+ Done mysqld_safe --defaults-file=/mydata/data/3307/my.cnf &>/dev/null (wd: /mydata/data/3307) (wd now: /mydata/data/3306) [root@CentOS 3306]# netstat -tulpn | grep -i mysql
[root@CentOS /]# mysql -uroot -p -S /mydata/data/3306/mysql_3306.sock mysql> create database d3306; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | d3306 | | data | | mysql | | performance_schema | | test | +--------------------+ 6 rows in set (0.02 sec) mysql> exit; [root@CentOS /]# mysql -uroot -p -S /mydata/data/3307/mysql_3307.sock mysql> create database d3307; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | d3307 | | data | | mysql | | performance_schema | | test | +--------------------+ 6 rows in set (0.01 sec) mysql> system date 2015年 11月 19日 星期四 05:00:48 CST
http://www.linuxidc.com/Linux/2014-07/104508.htm