Home > Database > Mysql Tutorial > Linux uses mysqld_multi to start multiple MySQL instances on a single machine

Linux uses mysqld_multi to start multiple MySQL instances on a single machine

黄舟
Release: 2017-03-10 11:13:23
Original
1045 people have browsed it

1. Background description

In the past, when using mysql, it was mostly used to use only one mysql schema, or multiple schemas, but generally they were in the same database instance, that is, the same port.
                                                                         
                                                                                           
                                                      # Machine B. Then in the two-way hot backup, B also needs to be configured as the master, and A is configured as the slave. To put it bluntly, hot backup is configured twice. OK, now the hot backup of machine A has been completed, and it is B's turn. We mentioned that there is also a mysql schema (C) on machine B, which also needs to be configured as master, and the backup schema is placed on machine A, but here comes the problem: the backup mysql schema (B) has just been configured with mysql when configuring hot standby. Port number and master The role is bound. At this time, if C is configured as master, the previous configuration of B as master will be overwritten; then when C's backup database (D) is configured as master on machine A, A will be configured as master. Operation covered.

        Then in this process, configuring the two-way hot standby of schema A and B is completed on the default port 3306 on the two machines respectively. When configuring the two-way hot standby of schema C and D, you need to configure the two-way hot standby on the two machines respectively. Completed in different mysql instances (different port numbers), the following explains how to start multiple mysql instances.

2. Implementation steps

(1) By default, mysql has been installed and the basic configuration has been implemented.

(2) Configure my.cnf (only write out the configuration related to this article)

[mysqld_multi]

mysqld = /opt/mysql/server-5.6/bin/mysqld_safe #根据自己的mysql目录配置
mysqladmin = /opt/mysql/server-5.6/bin/mysqladmin

[mysqld1]
port = 3307
socket = /tmp/mysql.sock1
pid-file   = /opt/mysql/server-5.6/data3307/cloud3.pid3
basedir=/opt/mysql/server-5.6
datadir=/opt/mysql/server-5.6/data3307
log-bin=mysql1-9003-bin
user=cloud1

[mysqld2]
port = 3308
socket = /tmp/mysql.sock2
pid-file   = /opt/mysql/server-5.6/data3308/cloud3.pid2
basedir=/opt/mysql/server-5.6
datadir=/opt/mysql/server-5.6/data3308
log-bin=mysql2-9003-bin
user=cloud1
Copy after login

(3) Initialize the database directory (point to the directory according to the configuration)

cd /opt/mysql/server-5.6/;./scripts/mysql_install_db --datadir=/opt/mysql/server-5.6/data3307 --user=cloud1
cd /opt/mysql/server-5.6/;./scripts/mysql_install_db --datadir=/opt/mysql/server-5.6/data3308 --user=cloud1
Copy after login

Initialization If successful, OK will be prompted. Otherwise, check whether the database directory has permissions.

(4) Start the instance

Use the following parameters to start mysqld_multi: (Note: This command is in the bin directory of mysql).


 mysqld_multi [options] [GNR[,GNR]...]
Copy after login

start, stop and report refer to the operations you want to perform. You can specify an operation on a single service or on multiple services, as distinguished from the GNR list following the options. If no GNR list is specified, mysqld_multi will operate according to the option file in all services.

The value of each GNR is the sequence number of the group or the sequence number range of a group. The value of this item must be the last number of the group name. For example, if the group name is mysqld17, then the value of this item is 17. If specifying a range, use "-" (dash) to connect the two numbers. If the value of GNR is 10-13, it refers to group mysqld10 to group mysqld13.

mysqld_multi --defaults-file=/opt/mysql/server-5.6/my.cnf start 1-2
或者
mysqld_multi --defaults-file=/opt/mysql/server-5.6/my.cnf start 1
mysqld_multi --defaults-file=/opt/mysql/server-5.6/my.cnf start 2
Copy after login
### (5) Change password and log in###
mysqladmin -u root -p -P 3307 -S /tmp/mysql.sock1 password  //刚开始默认没有密码,如果要输入密码,直接回车
mysql -u root -p -P 3307 -S /tmp/mysql.sock1
Copy after login

The above is the detailed content of Linux uses mysqld_multi to start multiple MySQL instances on a single machine. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template