MySQL multi-instance learning notes

Source: Internet
Author: User
Tags rehash

MySQL Multi-instance

The simple thing is to open several different service ports (such as 3306,3307, etc.) on a single machine to run multiple MySQL service processes, which provide their own services through different sockets that listen to different service ports


The function and problem of multi-instance

1. Efficient Use of servers

2. Conserve server resources

3, the resource of mutual preemption problem



Multi-instance application scenarios

1. Fund-tight Companies

2, concurrent access is not a particularly large business

3, the portal site application MySQL multi-instance scene


1. Create a MySQL multi-instance data file directory

First, turn off the single instance we started before.

[[email protected] ~]#/etc/init.d/mysqld stop

[Email protected] ~]# Mv/etc/init.d/mysqld/etc/init.d/dan.mysqld


[Email protected] ~]# mkdir-p/data/{3306,3307}/data

[Email protected] ~]# Tree/data

/data

|--3306

| '--data

'--3307

'--data


4 directories, 0 files


The multi-instance is done on the basis of our previous work order example, only in a single instance to

Ln-s/application/mysql-5.5.32//application/mysql This step is no longer to the following operation, this is not clear words can refer to the previous article installation, here will not repeat the operation


2. Create a MySQL multi-instance configuration file

[[email protected] ~]# vim /data/3306/my.cnf[client]port             = 3306socket           = /data/3306/mysql.sock[mysql]no-auto-rehash[mysqld]user    =  mysqlport    = 3306socket  = /data/3306/mysql.sockbasedir =  /application/mysqldatadir = /data/3306/dataopen_files_limit    = 1024back_ log = 600max_connections = 800max_connect_errors = 3000table_cache =  614external-locking = falsemax_allowed_packet =8msort_buffer_size = 1mjoin_buffer_ size = 1mthread_cache_size = 100thread_concurrency = 2query_cache_size =  2mquery_cache_limit = 1mquery_cache_min_res_unit = 2k#default_table_type =  innodbthread_stack =  192k#transaction_isolation = read-committedtmp_table_size = 2mmax_heap_table_size =  2mlong_query_time = 1#log_long_format#log-error = /data/3306/error.log# log-slow-queries = /data/3306/slow.logpid-file = /data/3306/mysql.pidlog-bin = / data/3306/mysql-binrelay-log = /data/3306/relay-binrelay-log-info-file = /data/3306/ relay-log.infobinlog_cache_size = 1mmax_binlog_cache_size = 1mmax_binlog_size =  2mexpire_logs_days = 7key_buffer_size = 16mread_buffer_size = 1mread_rnd_buffer_ size = 1mbulk_insert_buffer_size = 1mlower_case_table_names =  1skip-name-resolveslave-skip-errors = 1032,1062replicate-ignore-db=mysqlserver-id =  1innodb_additional_mem_pool_size = 4minnodb_buffer_pool_size = 32minnodb_data_file_path  = ibdata1:128m:autoextendinnodb_file_io_threadS = 4innodb_thread_concurrency = 8innodb_flush_log_at_trx_commit = 2innodb_log_ Buffer_size = 2minnodb_log_file_size = 4minnodb_log_files_in_group = 3innodb_max _dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_file_per_table = 0[ Mysqldump]quickmax_allowed_packet = 2m[mysqld_safe]log-error=/data/3306/mysql_martin3306.errpid-file =/data/3306/mysqld.pidvim /data/3307/my.cnf[client]port             = 3307socket          = / data/3307/mysql.sock[mysql]no-auto-rehash[mysqld]user    = mysqlport     = 3307socket  = /data/3307/mysql.sockbasedir = /application/ mysqldatadir = /data/3307/dataopen_files_limit    = 1024back_log =  600max_connections =&nbSp;800max_connect_errors = 3000table_cache = 614external-locking = falsemax_ allowed_packet =8msort_buffer_size = 1mjoin_buffer_size = 1mthread_cache_size =  100thread_concurrency = 2query_cache_size = 2mquery_cache_limit = 1mquery_ cache_min_res_unit = 2k#default_table_type = innodbthread_stack = 192k# transaction_isolation = read-committedtmp_table_size = 2mmax_heap_table_size =  2m#long_query_time = 1#log_long_format#log-error = /data/3307/error.log#log-slow-queries  = /data/3307/slow.logpid-file = /data/3307/mysql.pid#log-bin = /data/3307/ mysql-binrelay-log = /data/3307/relay-binrelay-log-info-file = /data/3307/ relay-log.infobinlog_cache_size = 1mmax_binlog_cache_size = 1mmax_binlog_size =  2mexpire_logs_days = 7key_buffer_size = 16mread_buffer_size = 1mread_rnd_buffer_size = 1mbulk_insert_buffer_size  = 1mlower_case_table_names = 1skip-name-resolveslave-skip-errors =  1032,1062replicate-ignore-db=mysqlserver-id = 3innodb_additional_mem_pool_size = 4minnodb_ Buffer_pool_size = 32minnodb_data_file_path = ibdata1:128m:autoextendinnodb_file_io_ Threads = 4innodb_thread_concurrency = 8innodb_flush_log_at_trx_commit = 2innodb _log_buffer_size = 2minnodb_log_file_size = 4minnodb_log_files_in_group =  3innodb_max_dirty_pages_pct = 90innodb_lock_wait_timeout = 120innodb_file_per_table =  0[mysqldump]quickmax_allowed_packet = 2m[mysqld_safe]log-error=/data/3307/mysql_ Martin3307.errpid-file=/data/3307/mysqld.pid


3. Create a multi-instance startup script

[[email protected] ~]# vim /data/3306/mysql#!/bin/sh#initport=3306mysql_user= "Root" mysql_ Pwd= "123456" cmdpath= "/application/mysql/bin" mysql_sock= "/data/${port}/mysql.sock" #startup   Functionfunction_start_mysql () {    if [ ! -e  "$mysql _sock"  ];then       printf  "starting mysql...\n"        /bin/sh ${cmdpath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 >  /dev/null &    else      printf  "MySQL is  running...\n "      exit    fi} #stop   Functionfunction_stop_mysql () {    if [ ! -e  "$mysql _sock"  ];then        printf  "mysql is stopped...\n"         exit    else       printf  "stoping mysql...\n"         ${cmdpath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -s / DATA/${PORT}/MYSQL.SOCK SHUTDOWN   FI} #restart  functionfunction_restart_mysql () {     printf  "restarting mysql...\n"     function_stop_mysql     sleep 2    function_start_mysql}case $1 instart)     function_start_mysql;; Stop)     function_stop_mysql;; Restart)     function_restart_mysql;; *)     printf  "usage: /data/${port}/mysql {start|stop|restart}\n" Esac[[email  protected] ~]# vim /data/3307/mysql#!/bin/sh#initport=3307mysql_user= "root" mysql_pwd= " 123456 "cmdpath="/application/mysql/bin "mysql_sock="/data/${port}/mysql.sock "#startup  functioNfunction_start_mysql () {    if [ ! -e  "$mysql _sock"  ];then       printf  "starting mysql...\n"       /bin/ sh ${cmdpath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/ null &    else      printf  "MySQL is  running...\n "      exit    fi} #stop   Functionfunction_stop_mysql () {    if [ ! -e  "$mysql _sock"  ];then        printf  "mysql is stopped...\n"         exit    else       printf  "Stoping mysql...\n"        ${cmdpath}/mysqladmin -u ${mysql_ User} -p${mysql_pwd} -s&nbSP;/DATA/${PORT}/MYSQL.SOCK SHUTDOWN   FI} #restart  functionfunction_restart_mysql () {     printf  "restarting mysql...\n"     function_stop_mysql     sleep 2    function_start_mysql}case $1 instart)     function_start_mysql;; Stop)     function_stop_mysql;; Restart)     function_restart_mysql;; *)     printf  "usage: /data/${port}/mysql {start|stop|restart}\n" Esac[[email  protected] ~]# tree /data/data|-- 3306|   |-- data|    |-- my.cnf|    '-- mysql '-- 3307    |-- data     |-- my.cnf     '-- mysql4 directories, 4 files[[ Email protected] ~]# chown -r mysql.mysql /data[[email protected] ~]# find /data -type f -name  "MySQL" |xargs ls - L-rw-r--r--.  1 mysql mysql 1018 jun 14 01:04 /data/3306/ Mysql-rw-r--r--.  1 mysql mysql 1017 jun 14 01:01 /data/3307/mysql[[ email protected] ~]# find /data -type f -name  "MySQL" |xargs chmod  700 [[email protected] ~]# find /data -type f -name  "MySQL" |XARGS LS -L     -RWX------.  1 mysql mysql 1018  JUN 14 01:04 /DATA/3306/MYSQL-RWX------.  1 mysql mysql 1017 Jun  14 01:01 /data/3307/mysql


4. Initialize the database

[Email protected] mysql-5.5.32]# Cd/application/mysql/scripts/[[email protected] scripts]#./mysql_install_db-- basedir=/application/mysql/--datadir=/data/3306/data/--user=mysql[[email protected] scripts]#./mysql_install_db- -basedir=/application/mysql/--datadir=/data/3307/data/--user=mysql


5. Start the database

[[Email protected] scripts]# /data/3306/mysql startstarting mysql ... [[Email protected] scripts]# /data/3307/mysql start starting mysql ... [[Email protected] scripts]# ss -lantup|grep 330tcp    listen      0      128                     *:3306                   *:*        users: (("mysqld", 20906,12)) tcp    listen      0      128                     *:3307                   *:*       users: (("mysqld", 21624,11) 


6. Login Database Test

[[Email protected] scripts]# mysql -s /data/3306/mysql.sock welcome to  the MySQL monitor.  Commands end with ; or \g.Your  mysql connection id is 1server version: 5.5.32-log source  distributioncopyright  (c)  2000, 2013, Oracle and/or its affiliates.  All rights reserved. oracle is a registered trademark of oracle corporation and/or  Itsaffiliates. other names may be trademarks of their respectiveowners . type  ' help; '  or  ' \h '  for help. Type  ' \c '  to clear the current input  statement.mysql> [[email protected] scripts]# mysql -s /data/3307/ Mysql.sock  welcome to the mysql monitor.  commands end&nBsp;with ; or \g.your mysql connection id is 1server version:  5.5.32 Source distributionCopyright  (c)  2000, 2013, oracle and/or  its affiliates. all rights reserved. oracle is a registered trademark of oracle corporation and/or  Itsaffiliates. other names may be trademarks of their respectiveowners . type  ' help; '  or  ' \h '  for help. Type  ' \c '  to clear the current input  statement.


650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/85/7C/wKioL1elViWQtOeDAAIK7kMXLVQ981.png "title=" 1.png " alt= "Wkiol1elviwqtoedaaik7kmxlvq981.png"/>


7, two databases are successful, you can create an instance 3308, here is no longer operation, simple look at the final effect

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/85/7C/wKioL1elVrWQefrqAAGRogAfy1g188.png "title=" 2.png " alt= "Wkiol1elvrwqefrqaagrogafy1g188.png"/>

This article from "Thick tak" blog, declined reprint!

MySQL multi-instance learning notes

Related Article

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.