Detailed explanation of how to create multiple instances of MySQL 5.6 in centos7 environment

Detailed explanation of how to create multiple instances of MySQL 5.6 in centos7 environment

This article describes how to create multiple instances of MySQL 5.6 in a CentOS 7 environment. Share with you for your reference, the details are as follows:

1. MySQL installation directory description

mysql5.6 is installed as a binary installation package in /data/mysql56. The data directory is /data/mysql56/data. The configuration file is /etc/my.cnf.

2. Multi-Instance Directory Description

/mysql-instance
|-- 3308
|-- data #3308 Instance data directory
|-- 3309
|-- data #3309 Instance data directory

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

3. Copy the configuration file to the instance directory

> 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

4. Modify the configuration file

> vi /mysql-instance/3308/my.cnf
> vi /mysql-instance/3309/my.cnf

[client]
port = 3308
socket = /mysql-instance/3308/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = mysql
port = 3308
socket = /mysql-instance/3308/mysql.sock
basedir = /data/mysql56
datadir = /mysql-instance/3308/data
pid-file = /mysql-instance/3308/mysql.pid
relay-log = /mysql-instance/3308/relay-bin
relay-log-info-file = /mysql-instance/3308/relay-log.info
server-id = 12
[mysqld_safe]
log-error = /mysql-instance/3308/mysql.err
pid-file = /mysql-instance/3308/mysql.pid

The configuration of 3309 is the same as above, just replace 3308 with 3309

5. Create MySQL multi-instance startup file

>vi /mysql-instance/3308/mysql
>vi /mysql-instance/3309/mysql

#!/bin/sh
port=3308
mysql_user="root"
#Please fill in your own database password 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

6. Authorize mysql user directory permissions

> chown -R mysql.mysql /mysql-instance
> chmod 700 /mysql-instance/3308/mysql
> chmod 700 /mysql-instance/3309/mysql

7. Initialize MySQL multi-instance database files

> cd /daa/mysql56/scripts
> ./mysql_install_db --basedir=/data/mysql56 --datadir=/mysql-instance/3308/data --user=mysql
> ./mysql_install_db --basedir=/data/mysql56 --datadir=/mysql-instance/3309/data --user=mysql

8. Start multiple MySQL instances

> /mysql-instance/3308/mysql start
> /mysql-instance/3309/mysql start
> netstat -lntup|grep 330

9. Log in to the MySQL instance

> mysql -uroot -p -S /mysql-instance/3308/mysql.sock

Readers who are interested in more MySQL-related content can check out the following topics on this site: "MySQL query skills", "MySQL common functions summary", "MySQL log operation skills", "MySQL transaction operation skills summary", "MySQL stored procedure skills" and "MySQL database lock related skills summary"

I hope this article will be helpful to everyone's MySQL database design.

You may also be interested in:
  • MySQL multi-instance configuration solution
  • Deploy MySQL 5.7.17 binary installation and multi-instance configuration on CentOS 6.5
  • MySQL tutorial on how to deploy multiple instances on a single machine using mysqld_multi
  • Quickly implement MySQL deployment and one-machine multi-instance deployment
  • Installing MySQL multiple instances under Linux as a data backup server to achieve multi-master to one-slave multi-instance backup
  • In-depth analysis based on MySQL multi-instance installation
  • The shell uses mysqld_multi to automatically create multiple instance slave library scripts
  • CentOS7.5 uses mysql_multi to install MySQL5.7.28 multiple instances (detailed explanation)
  • MySQL database introduction: detailed explanation of multi-instance configuration method

<<:  Vue uses rules to implement form field validation

>>:  Analysis of the principles and usage of Linux hard links and soft links

Recommend

How to dynamically add ports to Docker without rebuilding the image

Sometimes you may need to modify or add exposed p...

How to build LNMP environment on Ubuntu 20.04

Simple description Since it was built with Centos...

Example of how to install kong gateway in docker

1. Create a Docker network docker network create ...

How to configure nginx+php+mysql in docker

First, understand a method: Entering a Docker con...

Use pure CSS to disable the a tag in HTML without JavaScript

In fact, this problem has already popped up when I...

CSS and HTML and front-end technology layer diagram

Front-end technology layer (The picture is a bit e...

Tutorial on installing AutoFs mount service under Linux

Whether it is Samba service or NFS service, the m...

Several skills you must know when making web pages

1. z-index is invalid in IE6. In CSS, the z-index...

How to use crontab to backup MySQL database regularly in Linux system

Use the system crontab to execute backup files re...

Summary of MySQL time statistics methods

When doing database statistics, you often need to...

HTML/CSS Basics - Several precautions in HTML code writing (must read)

The warning points in this article have nothing t...

Detailed explanation of CSS background and border tag examples

1. CSS background tag 1. Set the background color...

Native js drag and drop function to create a slider example code

Drag and drop is a common function in the front e...