Deploy multiple versions of MySQL in Linux at the same time

Source: Internet
Author: User

Deploying multiple MySQL services on the same Linux server can effectively improve machine utilization. In addition, it is safer to classify different content into different services.

MySQL provides mysqld_multi, but it is not used in actual applications. Disadvantages:

1. Suspending and restarting all services will stop.

2. The configuration file is lengthy, causing trouble in splitting and migration.

A common method in the industry is to put database data files and configuration files, and enable and disable scripts in a directory. When a service is started, it acts as a separate service. When it is disabled, it has no impact on other services. During the migration, you only need to migrate the directory to the target machine.

A typical example:

 

 

10.10.82.83 [server2] $ cat start. sh
#! /Bin/sh
Rundir = "/opt/server2 ";
Echo $ rundir;
/Usr/local/mysql/bin/mysqld_safe -- defaults-file = "$ rundir"/my. cnf -- pid-file = "$ rundir"/mysql. pid -- datadir = "$ rundir"/var -- socket = "$ rundir"/mysql. sock -- log-error = "$ rundir"/err. log -- log-slow-queries = "$ rundir"/slow_query.log &

In the preceding example, MySQL is installed in/usr/local/mysql according to official suggestions.

Sometimes you need to use multiple different versions on the same server, for example, test the new version. According to the above logic, install the new MySQLD under/usr/local/mysql-new and change start. sh to/usr/local/mysql-new/bin/mysqld_safe. The database can be started normally, but it is not a new version. Why?

The official explanation is: You need to download the source code version and specify the running directory during compilation. This is not necessary.

Study the mysqld_safe file and find that the logic is:

A. Obtain the configuration parameters from the command line.

B. Obtain the configuration parameters from the configuration file.

C. For the mysqld directory (basedir) and data file directory (datadir), if none of the above are specified in the configuration, first check whether the current directory is available, otherwise, set/usr/local/mysql to the default value.

Therefore, although mysqld_safe under mysql-new is used, it is still running/usr/local/mysql/bin/mysqld, that is, the old version. You need to modify the startup script or the configuration file accordingly:

#! /Bin/sh
Rundir = "/opt/server0 ";
Echo $ rundir;
/Usr/local/mysql-new/bin/mysqld_safe -- defaults-file = "$ rundir"/my. cnf -- ledir =/usr/local/mysql-new/bin -- basedir =/usr/local/mysql-new -- pid-file = "$ rundir"/mysql. pid -- datadir = "$ rundir"/var -- socket = "$ rundir"/mysql. sock -- log-error = "$ rundir"/err. log -- log-slow-queries = "$ rundir"/slow_query.log &

In this way, you can run multiple Mysql versions on the same machine at the same time.

# -------------------------- The following section shows my experiment...

The above part is a little different from my own practice, but the principles are the same, on the server, I directly set the parameters in/usr/local/mysql5/bin/mysqld_safe -- defaults-file =/etc/my5.cnf & TO THE my5.cnf file. now, so it looks a little short. In fact, the most important thing is -- defaults-file. This parameter is too short to know about it, which may lead to many detours. faint.

  • 1
  • 2
  • Next Page

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.