Rotten mud: mysql5.5 multi-instance deployment

Source: Internet
Author: User
This article is first published in the dark world. To deploy MySQL Databases on multiple instances, follow these steps. 1. mysql multi-instance principle 2. mysql multi-instance features 3. mysql multi-instance Application Scenario 4. mysql5.5 multi-instance deployment method 1. mysql multi-instance principle mysql multi-instance, to put it simply, it is on a server

This article is first published in the dark world. To deploy MySQL Databases on multiple instances, follow these steps. 1. mysql multi-instance principle 2. mysql multi-instance features 3. mysql multi-instance Application Scenario 4. mysql5.5 multi-instance deployment method 1. mysql multi-instance principle mysql multi-instance, to put it simply, it is on a server

This article is first published in the dark world.

To deploy MySQL Databases on multiple instances, follow these steps.

1. mysql multi-instance principle

2. Features of mysql multi-instance

3. mysql multi-instance application scenarios

4. mysql5.5 multi-instance deployment Method

I. Principles of mysql multi-instance

Mysql multi-instance, simply put, is to open multiple mysql service ports (such as 3306, 3307) on a server and run multiple mysql service processes. These service processes listen to different service ports through different sockets to provide their own services.

These mysql instances share a set of mysql installation programs, using different my. cnf configuration files, startup programs, and data files. When providing services, mysql multiple instances are logically independent of each other. Each instance obtains related hardware resources of the server based on the value set in the configuration file.

Ii. Features of mysql multi-instance

2.1Effective use of server resources

When a single server resource is available, you can make full use of the remaining server resources to provide more services.

2.2Saving server resources

When the company has a shortage of funds, but the database needs to provide independent services, and master-slave synchronization and other technologies, it is best to use multiple instances.

2.3Mutual resource Preemption

When the service concurrency of an instance is high or slow, more memory, CPU, disk IO, and other resources of the server are consumed, in this case, the quality of access provided by other instances on the server is reduced, and server resources are preemptible.

Iii. mysql multi-instance application scenarios

3.1Selection of Capital Shortage companies

When the company's business traffic is not large, and it is reluctant to spend money, but it also wants the database services of different businesses to be independent, and requires technologies such as master-slave synchronization to provide backup or read/write splitting services, it is best to use multiple instances.

3.2Concurrent access is not a particularly large business

When the company's business traffic is not large and the server resources are mostly idle, this is very suitable for applications with multiple instances. If you optimize SQL statements, multiple instances are a very useful technology. Even if the concurrency is large, as long as the system resources are properly allocated, there will be no major problems.

Iv. mysql5.5 multi-instance deployment Method

4.1 mysql5.5Multi-instance deployment Method

Mysql5.5 multi-instance deployment method one is to start multiple different processes through multiple configuration files, the second is to use the built-in mysqld_multi.

The first method is to separate the configuration files of each instance for convenient management. The second method is to put multiple instances in a configuration file, which is not very convenient for management. So here we choose the first method, and all of the following experiments are carried out under this method.

4.2 mysql5.5Installation and configuration

To configure multiple instances of mysql5.5, we first need to install mysql5.5. for installation of mysql5.5, see the article "dirty mud: mysql5.5 database cmake source code compilation and installation.

After mysql5.5 is installed, do not start mysql because mysql is a single instance.

4.3Create a data directory for multiple mysql instances

Now let's create a data directory for multiple mysql 3306 instances. Here we create two mysql instances 3307 and. Create a data directory as follows:

Mkdir-p/data/{3306, 3307}/data

Tree-L 2/data/

650) this. width = 650; "title =" clip_image001 "style =" border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px; "border =" 0 "alt =" clip_image001 "src =" http://www.68idc.cn/help/uploads/allimg/151111/121Q51K4-0.jpg "width =" 376 "height =" 185 "/>

4.4Modify the mysql5.5 multi-instance my. cnf File

After the data directories of instances 3306 and 3307 are created, we will configure the my. cnf configuration file for instances 3306 and 3307.

Copy the my-medium.cnf under the mysql5.5 installation directory support-files to my. cnf and change the content. Take the instance 3306 as an example:

[Client]

Port = 3306

Socket =/data/3306/mysql. sock

[Mysqld]

Port = 3306

Socket =/data/3306/mysql. sock

Basedir =/usr/local/mysql

Data =/data/3306/data

Skip-external-locking

Key_buffer_size = 16 M

Max_allowed_packet = 1 M

Table_open_cache = 64

Sort_buffer_size = 512 K

Net_buffer_length = 8 K

Read_buffer_size = 256 K

Read_rnd_buffer_size = 512 K

Myisam_sort_buffer_size = 8 M

Skip-name-resolve

Log-bin = mysql-bin

Binlog_format = mixed

Max_binlog_size = 500 M

Server-id = 1

[Mysqld_safe]

Log-error =/data/3306/ilanni. err

Pid-file =/data/3306/ilanni. pid

[Mysqldump]

Quick

Max_allowed_packet = 16 M

[Mysql]

No-auto-rehash

[Myisamchk]

Key_buffer_size = 20 M

Sort_buffer_size = 20 M

Read_buffer = 2 M

Write_buffer = 2 M

[Mysqlhotcopy]

Interactive-timeout

650) this. width = 650; "title =" clip_image002 "style =" border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px; "border =" 0 "alt =" clip_image002 "src =" http://www.68idc.cn/help/uploads/allimg/151111/121Q54G3-1.jpg "width =" 342 "height =" 460 "/>

Note that the ** marked part in the figure is the main modification, and the others remain unchanged by default.

The above is the my. cnf configuration file of instance 3306. Now we will configure my. cnf of instance 3307. In the configuration file my. cnf of instance 3307, we directly copy the my. cnf file of instance 3306, and then use the sed command to change 3306 in this file to 3307. As follows:

Cp/data/3306/my. cnf/data/3307/my. cnf

Sed-I's/3306/3307/3307/G'/data/my. cnf

Or

Sed-e's/3306/3307/G'/data/3306/my. cnf>/data/3307/my. cnf

650) this. width = 650; "title =" clip_image001 [4] "style =" border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; "border =" 0 "alt =" clip_image001 [4] "src =" http://www.68idc.cn/help/uploads/allimg/151111/121Q53554-2.jpg "width =" 548 "height =" 292 "/>

4.5Initialize multiple mysql instances

After modifying the my. cnf configuration files of instances 3306 and 3307, We need to initialize these two instances and use the mysql_install_db command. As follows:

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

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

Note that mysql_install_db of mysql5.5 is in the/usr/local/mysql/scripts/mysql_install_db directory of mysql5.5.

650) this. width = 650; "title =" clip_image004 "style =" border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px; "border =" 0 "alt =" clip_image004 "src =" http://www.68idc.cn/help/uploads/allimg/151111/121Q52361-3.jpg "width =" 782 "height =" 120 "/>

650) this. width = 650; "title =" clip_image005 "style =" border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px; "border =" 0 "alt =" clip_image005 "src =" http://www.68idc.cn/help/uploads/allimg/151111/121Q52648-4.jpg "width =" 773 "height =" 121 "/>

Check the status of the instance after initialization as follows:

Tree-L 3/data/

650) this. width = 650; "title =" clip_image006 "style =" border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px; "border =" 0 "alt =" clip_image006 "src =" http://www.68idc.cn/help/uploads/allimg/151111/121Q52206-5.jpg "width =" 341 "height =" 364 "/>

We can see that the mysql instance will create a basic database after initialization.

Now let's take a look at the attributes of the initial file creation, as shown below:

650) this. width = 650; "title =" clip_image007 "style =" border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px; "border =" 0 "alt =" clip_image007 "src =" http://www.68idc.cn/help/uploads/allimg/151111/121Q51F5-6.jpg "width =" 458 "height =" 288 "/>

We can see that all the files created during initialization belong to the mysql user.

Why?

This is because the -- user = mysql option is added during initialization. Of course, this is what we need, because it increases the security of mysql.

4.6Modify the database directory permission of a mysql instance

After the initialization of the mysql instance, we now re-grant the data directory permissions of instance 3306 and instance 3307 to the mysql user. As follows:

Chown-R mysql: mysql/data/3306

Chown-R mysql: mysql/data/3307

650) this. width = 650; "title =" clip_image008 "style =" border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px; "border =" 0 "alt =" clip_image008 "src =" http://www.68idc.cn/help/uploads/allimg/151111/121Q5G63-7.jpg "width =" 380 "height =" 207 "/>

We recommend that you perform this operation again. Otherwise, an error will be prompted when starting the mysql instance. The mysql instance cannot be started.

4.7Start multiple instances of mysql5.5

Let's start the instance now. Run the following command:

/Usr/local/mysql/bin/mysqld_safe -- defaults-file =/data/3306/my. cnf &

/Usr/local/mysql/bin/mysqld_safe -- defaults-file =/data/3307/my. cnf &

Ps aux | grep mysqld

650) this. width = 650; "title =" clip_image009 "style =" border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px; "border =" 0 "alt =" clip_image009 "src =" http://www.68idc.cn/help/uploads/allimg/151111/121Q524N-8.jpg "width =" 759 "height =" 382 "/>

We can see that both instance 3306 and instance 3307 have started properly. It also indicates that our mysql5.5 multi-instance has been configured successfully.

In fact, mysql is started on a single instance through the mysqld_safe command. It loads the/etc/my. cnf file by default.

4.8Log on to multiple instances of mysql5.5

When logging on to a multi-instance database, we need to add the socket file of the instance to log on normally. Now we use the 3306 instance as an example.

Log on to the 3306 instance as follows:

Mysql-uroot-p-S/data/3306/mysql. sock

650) this. width = 650; "title =" clip_image010 "style =" border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px; "border =" 0 "alt =" clip_image010 "src =" http://www.68idc.cn/help/uploads/allimg/151111/121Q56391-9.jpg "width =" 569 "height =" 253 "/>

After logging in locally, we create an ilanni3306 database on instance 3306. As follows:

Create database ilanni3306;

Show databases;

650) this. width = 650; "title =" clip_image011 "style =" border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px; "border =" 0 "alt =" clip_image011 "src =" http://www.68idc.cn/help/uploads/allimg/151111/121Q53C9-10.jpg "width =" 445 "height =" 422 "/>

Now we remotely log on to instance 3306 and view the newly created database. As follows:

Mysql-h192.168.1.213-u root-p-S/data/3306/mysql. sock

650) this. width = 650; "title =" clip_image012 "style =" border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; padding-right: 0px; border-top-width: 0px; "border =" 0 "alt =" clip_image012 "src =" http://www.68idc.cn/help/uploads/allimg/151111/121Q53404-11.jpg "width =" 549 "height =" 381 "/>

Or: mysql-h192.168.1.213-uroot-p-P 3306

650) this. width = 650; "src =" http://www.68idc.cn/help/uploads/allimg/151111/121Q5E28-12.jpg "title =" 2014-11-27_145008.png "alt =" wKiom1R2ytKwKGhPAAHVloWUMaY090.jpg "/>

We can see that the remote connection to the 3306 instance is also possible.

4.9Modify mysql5.5 multi-instance root Password

Modify the root password of instance 3306 and run the mysqladmin command. As follows:

Mysqladmin-uroot-p password 123456-S/data/3306/mysql. sock

650) this. width = 650; "title =" clip_image013 "style =" border-right-width: 0px; background-image: none; border-bottom-width: 0px; padding-top: 0px; padding-left: 0px; padding-right: 0px; border-top-width: 0px; "border =" 0 "alt =" clip_image013 "src =" http://www.68idc.cn/help/uploads/allimg/151111/121Q5L15-13.jpg "width =" 567 "height =" 396 "/>

By now, the mysql multi-instance deployment has been completed.

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.