Detailed process of using mysqld_multi to deploy a single-host multi-instance

Source: Internet
Author: User

Detailed process of using mysqld_multi to deploy a single-host multi-instance

Preface: Multi-instance? Why?

 

With the development of hardware, multi-core linux systems have become a general trend, while mysql is a single-process multi-thread, so the exploitation of multi-process is not very high, although mysql 5.6 has improved a lot in this aspect, it has not reached 100%. to make full use of system resources, mysql has its own supplement, that is, it can deploy multiple instances, one instance and one port.

 

 

1. Prepare the mysql Environment

For how to install mysql in source code, refer to blog: login.

1.1. Prepare the installation environment

Groupaddmysql

Useradd-g mysql

 

Autoreconf -- force -- install

Libtoolize -- automake -- force

Automake -- force -- add-missing

 

Yuminstall-y libtoolize

Yuminstall cmake-y

Yuminstall gcc-c ++-y

Yuminstall-y ncurses-devel.x86_64

Yuminstall-y cmake. x86_64

Yuminstall-y libaio. x86_64

Yuminstall-y bison. x86_64

Yuminstall-y gcc-c ++. x86_64

Yuminstall make-y

 

1.2. Create the mysql compiling root directory

Mkdir-p/usr/local/mysql

 

1.3 decompress the source code package

Tar-xvf mysql-5.6.12.tar.gz

Cd mysql-5.6.12

 

1.4. Compile and install

Timecmake. -DCMAKE_INSTALL_PREFIX =/usr/local/mysql-DMYSQL_DATADIR =/home/data/mysql/data-DWITH_INNOBASE_STORAGE_ENGINE = 1-DMYSQL_UNIX_ADDR =/usr/local/mysql. sock-DMYSQL_USER = mysql-DDEFAULT_CHARSET = utf8-DDEFAULT_COLLATION = utf8_general_ci

 

Since time make takes a long time, it has been installed in advance

Timemake

Timemake install

 

 

2. Prepare the first instance 3307

 

2.1 create a directory

Mkdir/usr/local/mysql3307

Chown-R mysql. mysql/usr/local/mysql3307/

 

Mkdir-p/home/data/mysql3307/data

Chown-R mysql. mysql/home/data/mysql3307

Chown-R mysql. mysql/home/data/mysql3307/data

 

Mkdir-p/home/data/mysql3307/binlog

Chown-R mysql. mysql/home/data/mysql3307

 

Mkdir-p/home/data/mysql3307/relay_log/

Chown-R mysql. mysql/home/data/mysql3307/

 

 

2.2 configuration file

[Mysqld_multi]

Mysqld =/usr/local/mysql/bin/mysqld_safe

Mysqladmin =/usr/local/mysql/bin/mysqladmin

Log =/home/mysql/mydata/log/mysqld_multi.log

 

[Mysqld1]

Socket =/usr/local/mysql3307/mysql. sock

Port = 3307

Pid-file =/usr/local/mysql3307/mysqld. pid

Datadir =/home/data/mysql3307/data

 

Log_bin =/home/data/mysql3307/binlog

Servers-id = 1230

Relay_log =/home/data/mysql3307/relay_log/mysql-relay-bin

Log_slave_updates = 1

Read_only = 0

 

Innodb_buffer_pool_size = 128 M

Innodb_flush_log_at_trx_commit = 0

2.3 initialize the database

/Usr/local/mysql/scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/home/data/mysql3307/data

 

Bytes ----------------------------------------------------------------------------------------------------------------
<All Rights Reserved. This document can be reprinted, but the source address must be indicated by link. Otherwise, we will be held legally responsible.>
Original blog address: http://blog.csdn.net/mchdba/article/details/45798139
Original Author: Huang Shan (mchdba)
Bytes ----------------------------------------------------------------------------------------------------------------

3. Prepare the second instance 33083.1 to create a directory.

Mkdir/usr/local/mysql3308

Chown-R mysql. mysql/usr/local/mysql3308/

 

Mkdir-p/home/data/mysql3308/data

Chown-R mysql. mysql/home/data/mysql3308

Chown-R mysql. mysql/home/data/mysql3308/data

 

Mkdir-p/home/data/mysql3308/binlog

Chown-R mysql. mysql/home/data/mysql3308

 

Mkdir-p/home/data/mysql3308/relay_log/

Chown-R mysql. mysql/home/data/mysql3308/

 

 

3.2 configuration file

[Mysqld2]

Socket =/usr/local/mysql3308/mysql. sock

Port = 3308

Pid-file =/usr/local/mysql3308/mysqld. pid

Datadir =/home/data/mysql3308/data

 

Log_bin =/home/data/mysql3308/binlog

Servers-id = 2230

Relay_log =/home/data/mysql3308/relay_log/mysql-relay-bin

Log_slave_updates = 1

Read_only = 0

 

 

Innodb_buffer_pool_size = 128 M

Innodb_flush_log_at_trx_commit = 0

3.3 initialize the database

 

/Usr/local/mysql/scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/home/data/mysql3308/data

 

 

4. Prepare the third instance 33094.1 to create a directory.

Mkdir/usr/local/mysql3309

Chown-R mysql. mysql/usr/local/mysql3309/

 

Mkdir-p/home/data/mysql3309/data

Chown-R mysql. mysql/home/data/mysql3309

Chown-R mysql. mysql/home/data/mysql3309/data

 

Mkdir-p/home/data/mysql3309/binlog

Chown-R mysql. mysql/home/data/mysql3309

 

Mkdir-p/home/data/mysql3309/relay_log/

Chown-R mysql. mysql/home/data/mysql3309/

 

4.2 configuration file

[Mysqld3]

Socket =/usr/local/mysql3309/mysql. sock

Port = 3309

Pid-file =/usr/local/mysql3309/mysqld. pid

Datadir =/home/data/mysql3309/data

 

Log_bin =/home/data/mysql3309/binlog

Servers-id = 3230

Relay_log =/home/data/mysql3309/relay_log/mysql-relay-bin

Log_slave_updates = 1

Read_only = 0

 

Innodb_buffer_pool_size = 128 M

Innodb_flush_log_at_trx_commit = 0

4.3 initialize the database

 

/Usr/local/mysql/scripts/mysql_install_db -- user = mysql -- basedir =/usr/local/mysql -- datadir =/home/data/mysql3309/data

The initialization information is as follows:

  [mysql@data02 ~]$ /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/home/data/mysql3309/data
WARNING: cocould not write to config file/usr/local/mysql/my-new.cnf: insufficient Permissions
 
Installing MySQL system tables...2015-05-14 09:31:20 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-05-14 09:31:20 12307 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)
 
2015-05-14 09:31:20 12307 [Warning] Buffered warning: Changed limits: table_cache: 431 (requested 2000)
 
2015-05-14 09:31:20 12307 [Note] InnoDB: The InnoDB memory heap is disabled
2015-05-14 09:31:20 12307 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-05-14 09:31:20 12307 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-05-14 09:31:20 12307 [Note] InnoDB: Using CPU crc32 instructions
2015-05-14 09:31:20 12307 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-05-14 09:31:20 12307 [Note] InnoDB: Completed initialization of buffer pool
2015-05-14 09:31:20 12307 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2015-05-14 09:31:20 12307 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2015-05-14 09:31:20 12307 [Note] InnoDB: Database physically writes the file full: wait...
2015-05-14 09:31:20 12307 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2015-05-14 09:31:20 12307 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2015-05-14 09:31:21 12307 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2015-05-14 09:31:21 12307 [Warning] InnoDB: New log files created, LSN=45781
2015-05-14 09:31:21 12307 [Note] InnoDB: Doublewrite buffer not found: creating new
2015-05-14 09:31:21 12307 [Note] InnoDB: Doublewrite buffer created
2015-05-14 09:31:21 12307 [Note] InnoDB: 128 rollback segment(s) are active.
2015-05-14 09:31:21 12307 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-05-14 09:31:21 12307 [Note] InnoDB: Foreign key constraint system tables created
2015-05-14 09:31:21 12307 [Note] InnoDB: Creating tablespace and datafile system tables.
2015-05-14 09:31:21 12307 [Note] InnoDB: Tablespace and datafile system tables created.
2015-05-14 09:31:21 12307 [Note] InnoDB: Waiting for purge to start
2015-05-14 09:31:21 12307 [Note] InnoDB: 5.6.12 started; log sequence number 0
2015-05-14 09:31:21 12307 [Note] Binlog end
2015-05-14 09:31:21 12307 [Note] InnoDB: FTS optimize thread exiting.
2015-05-14 09:31:21 12307 [Note] InnoDB: Starting shutdown...
2015-05-14 09:31:22 12307 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
 
Filling help tables...2015-05-14 09:31:22 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-05-14 09:31:22 12332 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000)
 
2015-05-14 09:31:22 12332 [Warning] Buffered warning: Changed limits: table_cache: 431 (requested 2000)
 
2015-05-14 09:31:22 12332 [Note] InnoDB: The InnoDB memory heap is disabled
2015-05-14 09:31:22 12332 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2015-05-14 09:31:22 12332 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-05-14 09:31:22 12332 [Note] InnoDB: Using CPU crc32 instructions
2015-05-14 09:31:22 12332 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-05-14 09:31:22 12332 [Note] InnoDB: Completed initialization of buffer pool
2015-05-14 09:31:22 12332 [Note] InnoDB: Highest supported file format is Barracuda.
2015-05-14 09:31:22 12332 [Note] InnoDB: 128 rollback segment(s) are active.
2015-05-14 09:31:22 12332 [Note] InnoDB: Waiting for purge to start
2015-05-14 09:31:22 12332 [Note] InnoDB: 5.6.12 started; log sequence number 1625977
2015-05-14 09:31:22 12332 [Note] Binlog end
2015-05-14 09:31:22 12332 [Note] InnoDB: FTS optimize thread exiting.
2015-05-14 09:31:22 12332 [Note] InnoDB: Starting shutdown...
2015-05-14 09:31:24 12332 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
 
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
 
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
 
  /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
  /usr/local/mysql/bin/mysqladmin -u root -h data02 password 'new-password'
 
Alternatively you can run:
 
  /usr/local/mysql/bin/mysql_secure_installation
 
which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.
 
See the manual for more instructions.
 
You can start the MySQL daemon with:
 
  cd . ; /usr/local/mysql/bin/mysqld_safe &
 
You can test the MySQL daemon with mysql-test-run.pl
 
  cd mysql-test ; perl mysql-test-run.pl
 
Please report any problems with the ./bin/mysqlbug script!
 
The latest information about MySQL is available on the web at
 
  http://www.mysql.com
 
Support MySQL by buying support/licenses at http://shop.mysql.com
 
WARNING: Could not copy config file template /usr/local/mysql/support-files/my-default.cnf to
/usr/local/mysql/my-new.cnf, may not have access rights to do so.
You may want to copy the file manually, or create your own,
it will then be used by default by the server when you start it.
 
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

 

 

 

 

5. Start a multi-instance Database

Mkdir-p/home/mysql/data/log

 

[Mysql @ data02 data] $ mysqld_multi -- defaults-extra-file =/etc/my. cnf start 1, 2, 3

[Mysql @ data02 data] $

Background log information:

Starting MySQL servers

 

150514 09:36:14 mysqld_safe Logging to '/home/data/mysql3309/data/data02.err '.

150514 09:36:15 mysqld_safe Logging to '/home/data/mysql3308/data/data02.err '.

150514 09:36:15 mysqld_safe Logging to '/home/data/mysql3307/data/data02.err '.

150514 09:36:15 mysqld_safe Starting mysqlddaemon with databases from/home/data/mysql3308/data

150514 09:36:15 mysqld_safe Starting mysqlddaemon with databases from/home/data/mysql3307/data

150514 09:36:15 mysqld_safe Starting mysqlddaemon with databases from/home/data/mysql3309/data

6. view multiple instances

[Mysql @ data02 ~] $ Mysqld_multi -- defaults-extra-file =/etc/my. cnf report

Reporting MySQL servers

MySQL server from group: mysqld1 is running

MySQL server from group: mysqld2 is running

MySQL server from group: mysqld3 is running

[Mysql @ data02 ~] $

 

Background log information:

Reporting MySQL servers

MySQL server from group: mysqld1 is running

MySQL server from group: mysqld2 is running

MySQL server from group: mysqld3 is running

7. Stop multiple instances

Mysqld_multi -- defaults-extra-file =/etc/my. cnf stop 1, 2, 3

 

Background log information:

Stopping MySQL servers

 

150514 09:35:43 mysqld_safe mysqld from pidfile/usr/local/mysql3309/mysqld. pid ended

150514 09:35:43 mysqld_safe mysqld from pidfile/usr/local/mysql3307/mysqld. pid ended

150514 09:35:43 mysqld_safe mysqld from pidfile/usr/local/mysql3308/mysqld. pid ended

 

8. log on to the mysql instance

You can log on to your mysql instance by specifying the socket to be started, as shown below:

[Mysql @ data02 ~] $ Mysql -- socket =/usr/local/mysql3308/mysql. sock

Welcome to the MySQL monitor. Commands end with; or \ g.

Your MySQL connection id is 2

Server version: 5.6.12-log Sourcedistribution

 

Copyright (c) 2000,201 3, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

Affiliates. Other names may be trademarksof their respective

Owners.

 

Type 'help; 'or' \ H' for help. type' \ C' toclear the current input statement.

 

Mysql> select @ port;

+ -------- +

| @ Port |

+ -------- +

| 1, 3308 |

+ -------- +

1 row in set (0.00 sec)

 

Mysql>

Mysql> create database d3308;

Query OK, 1 row affected (0.04 sec)

 

Mysql>

 

 

9. You can set up master-slave and master-master service 9.1 on multiple ports and create an account on instance 3307.

Copy account

Grantreplication slave, RELOAD, super on *. * TO repl @ '2017. 192.% 'identified by 'repl _ 100 ';

 

Backup account

GRANTRELOAD, SUPER, lock tables, replication client, create tablespace on *. * TO 'backup '@ '192. 192. %' identified by '123 ';

Grantall privileges on 'mysql'. * TO 'backup '@ '2017. 192.% ';

Grantevent on *. * TO 'backup '@ '2017. 192.% ';

 

 

9.2. synchronize data from the 3307 instance to the 3308 Port

 

Backup:

/Usr/local/mysql/bin/mysqldump-ubackup -- password = 123456 -- host = 192.168.52.138 -- socket =/usr/local/mysql3307/mysql. sock -- port = 3307-R-E -- skip-opt -- single-transaction -- flush-logs -- master-data = 2 -- add-drop-table -- create-option -- quick -- extended-insert = false -- set-charset -- disable-keys-A>/tmp/alldbfullbackup. SQL

 

Import:

/Usr/local/mysql/bin/mysql-uroot-p -- socket =/usr/local/mysql3308/mysql. sock -- port = 3308

 

 

9.3. Create a copy link on instance 3308

Find the replication point

More/tmp/alldbfullbackup. SQL

 

Start to create a copy Link

Change master TOMASTER_HOST = '192. 168.52.138 ', MASTER_PORT = 192,

MASTER_USER = 'repl ',

MASTER_PASSWORD = 'repl _ 1234 ',

MASTER_LOG_FILE = 'mysql-bin.000006 ',

MASTER_LOG_POS = 120;

 

Enable replication

Startslave;

 

View copy status

Showslave status \ G;

Mysql> show slave status \ G

* *************************** 1. row ***************************

Slave_IO_State: Waiting formaster to send event

Master_Host: 192.168.52.138

Master_User: repl

Master_Port: 3307

Connect_Retry: 60

Master_Log_File: mysql-bin.000011

Read_Master_Log_Pos: 120

Relay_Log_File: mysql-relay-bin.000005

Relay_Log_Pos: 283

Relay_Master_Log_File: mysql-bin.000011

Slave_IO_Running: Yes

Slave_ SQL _Running: Yes

......

Seconds_Behind_Master: 0

 

 

10. Manage a single instance

Stop instance 2:

[Root @ data03 ~] # Mysqld_multi -- defaults-extra-file =/etc/my. cnf stop 2

[Root @ data03 ~] #

 

Background log information:

Stopping MySQL servers

 

150517 06:53:43 mysqld_safe mysqld from pidfile/usr/local/mysql3308/mysqld. pid ended

Mysqld_multi log file version 2.16; run: July 22, May 17 06:53:48 2015

 

Start instance 2:

[Root @ data03 ~] # Mysqld_multi -- defaults-extra-file =/etc/my. cnf start 2

[Root @ data03 ~] #

 

Background log information:

Starting MySQL servers

 

150517 06:53:48 mysqld_safe Logging to '/home/data/mysql3308/data/data03.err '.

150517 06:53:48 mysqld_safe Starting mysqlddaemon with databases from/home/data/mysql3308/data

 

 

11. How to use multiple instances

In Multiple instances, resources of each instance are not shared. Therefore, you must allocate the memory, disks, and other resources of each instance properly to avoid the situation of out of memery or full disk.

 

 

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.