Create mysql5.6 multiple instances under CENTOS7

Source: Internet
Author: User
Tags chmod

I. MySQL installation directory description
mysql5.6 installed under/data/mysql56 with a binary installation package
The Data directory is/data/mysql56/data
The configuration file is/etc/my.cnf

Second, multi-instance directory description
/mysql-instance
|--3308
|--Data #3308实例数据目录
|--3309
|--Data #3309实例数据目录

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


Third, 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


Iv. Modifying configuration files

> 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 of the configuration, just 3308 of the place to replace 3309

V. Create a MySQL multi-instance boot file

> 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        prin TF "MySQL is stopped ... \ n"        exit    else        printf "MySQL stop ... \ n"        ${cmd_path}/mysqladmin-u ${mysql_us ER}-p${mysql_pwd}-s/mysql-instance/${port}/mysql.sock shutdown    Fi}mysql_restart () {    printf "MySQL Restart. \ n "    mysql_stop    sleep 2 mysql_start}case" in    start) mysql_start;;    stop) mysql_stop;;    restart) Mysql_restart;; *) printf "usage:/data/${port}/mysql {start|stop|restart}\n" Esac


Vi. authorizing MySQL User directory permissions

> Chown-r mysql.mysql/mysql-instance> chmod 700/mysql-instance/3308/mysql> chmod 700/mysql-instance/3309/ Mysql


Vii. initializing 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


Eight, start MySQL multi-instance

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


Nine, login MySQL instance

> Mysql-uroot-p-s/mysql-instance/3308/mysql.sock

Create mysql5.6 multiple instances under CENTOS7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.