首页 > 数据库 > MySQL > 正文

centos7环境下创建mysql5.6多实例的方法详解

2024-07-24 12:54:29
字体:
来源:转载
供稿:网友

本文实例讲述了centos7环境下创建mysql5.6多实例的方法。,具体如下:

一、mysql安装目录说明

mysql5.6以二进制安装包安装在/data/mysql56下
数据目录为/data/mysql56/data下
配置文件为/etc/my.cnf下

二、多实例目录说明

/mysql-instance
         |-- 3308
                  |-- data  #3308实例数据目录
         |-- 3309
                  |-- data  #3309实例数据目录

> mkdir -p /mysql-instance/3308/data> mkdir -p /mysql-instance/3309/data

三、复制配置文件到实例目录下

> cp /data/mysql56/support-files/my-default.cnf /mysql-instance/3308/my.cnf> cp /data/mysql56/support-files/my-default.cnf /mysql-instance/3309/my.cnf

四、修改配置文件

> vi /mysql-instance/3308/my.cnf> vi /mysql-instance/3309/my.cnf
[client]port = 3308socket = /mysql-instance/3308/mysql.sock[mysql]no-auto-rehash[mysqld]user = mysqlport = 3308socket = /mysql-instance/3308/mysql.sockbasedir = /data/mysql56datadir = /mysql-instance/3308/datapid-file = /mysql-instance/3308/mysql.pidrelay-log = /mysql-instance/3308/relay-binrelay-log-info-file = /mysql-instance/3308/relay-log.infoserver-id = 12[mysqld_safe]log-error = /mysql-instance/3308/mysql.errpid-file = /mysql-instance/3308/mysql.pid

3309的配置同上,只需把3308的地方换成3309

五、创建mysql多实例启动文件

> vi /mysql-instance/3308/mysql> vi /mysql-instance/3309/mysql
#!/bin/shport=3308mysql_user="root"#请填写自已数据库密码mysql_pwd="123456"cmd_path="/data/mysql56/bin"mysql_sock="/mysql-instance/${port}/mysql.sock"mysql_start() {  if [ ! -e "$mysql_sock" ];then    printf "mysql start ... /n"    /bin/sh ${cmd_path}/mysqld_safe --defaults-file=/mysql-instance/${port}/my.cnf 2>&1 > /dev/null &  else    printf "mysql is running ... /n"    exit  fi}mysql_stop() {  if [ ! -e "$mysql_sock" ];then    printf "mysql is stopped ... /n"    exit  else    printf "mysql stop ... /n"    ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /mysql-instance/${port}/mysql.sock shutdown  fi}mysql_restart() {  printf "mysql restart ... /n"  mysql_stop  sleep 2  mysql_start}case $1 in  start) mysql_start ;;  stop) mysql_stop ;;  restart) mysql_restart ;;*)printf "usage: /data/${port}/mysql {start|stop|restart}/n"esac

六、授权mysql用户目录权限

> chown -R mysql.mysql /mysql-instance> chmod 700 /mysql-instance/3308/mysql> chmod 700 /mysql-instance/3309/mysql            
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表