


Detailed explanation of the steps for deploying MySQL multi-instance in Linux environment
Apr 08, 2025 am 10:12 AMThe key to deploying MySQL multi-instances under Linux is to configure independent data directories and configuration files for each instance. Specific steps: 1. Create an independent instance directory; 2. Copy and modify the configuration file to ensure that the datadir and port parameters of each instance are unique; 3. Use mysql_install_db to initialize the database of each instance; 4. Register each instance as a system service for management; 5. Reasonably allocate system resources and perform performance tuning, and back up data regularly. Only by understanding the principles behind these steps can we effectively avoid errors and ensure the stable operation of multiple instances.
Play with MySQL multiple instances under Linux: A sharing of experience of an old bird
Many friends asked me how to deploy multiple MySQL instances on Linux systems, which cannot be done simply by copying and pasting. In this article, I will take you into the deep understanding of this process. It is not just a simple step, but more importantly, understanding the principles behind it and how to avoid those crazy pitfalls. After reading, you will be able to independently deploy and manage multiple MySQL instances and have a deeper understanding of the underlying mechanism of MySQL.
Basic knowledge lays the foundation: The limitations of single instances
Before we start, we need to understand why multiple instances are needed. A MySQL instance has only one listening port and can only serve one application. If you have multiple applications that require using MySQL databases, or need to isolate different database environments (such as development, testing, production), then a single instance seems to be overwhelming. Multi-instance deployment can perfectly solve this problem, making your MySQL service more flexible and robust.
Core: The magic of data directories and configuration files
The key to deploying multiple instances is to cleverly utilize data directories and configuration files. Each MySQL instance needs to have its own independent data directory (storage database files) and configuration files (my.cnf). In the configuration file, the most important parameters are datadir
(data directory) and port
(listening port). Remember, these two parameters must be unique in different instances.
Let's look at a practical example. Suppose we want to deploy two instances, named mysql57 and mysql80:
<code class="bash"># 創(chuàng)建兩個(gè)實(shí)例目錄<br>sudo mkdir -p /data/mysql57 /data/mysql80</code><h1> Copy the configuration files in the MySQL installation directory and modify the port and data directory</h1><p> sudo cp /etc/my.cnf /etc/my.cnf.mysql57<br> sudo cp /etc/my.cnf /etc/my.cnf.mysql80</p><h1> Modify /etc/my.cnf.mysql57</h1><p> sudo sed -i 's/port=3306/port=3307/g' /etc/my.cnf.mysql57<br> sudo sed -i 's#datadir=.*/var/lib/mysql#datadir=/data/mysql57#g' /etc/my.cnf.mysql57</p><h1> Modify /etc/my.cnf.mysql80</h1><p> sudo sed -i 's/port=3306/port=3308/g' /etc/my.cnf.mysql80<br> sudo sed -i 's#datadir=.*/var/lib/mysql#datadir=/data/mysql80#g' /etc/my.cnf.mysql80</p><h1> Initialize the database</h1><p> sudo mysql_install_db --user=mysql --datadir=/data/mysql57<br> sudo mysql_install_db --user=mysql --datadir=/data/mysql80</p><h1> Start the instance (the commands need to be adjusted according to your MySQL version and installation method)</h1><p> sudo systemctl start mysqld.mysql57<br> sudo systemctl start mysqld.mysql80</p><h1> verify</h1><p> sudo mysql -P 3307 -u root -p<br> sudo mysql -P 3308 -u root -p </p>
Code interpretation and trap evasion
In this code, we use the sed
command to modify the configuration file, which is an efficient batch modification method. However, be sure to double-check the modified configuration file to ensure there are no unexpected errors. A small error may cause the instance to fail to start or even the data is corrupted.
In addition, the mysql_install_db
command is used to initialize the database, which is a key step in creating a new instance. This command requires root permissions and requires the correct data directory to be specified.
Advanced Tips: System Service Management
To facilitate management, it is recommended to register each MySQL instance as a system service. This way, you can use the systemctl
command to start, stop and restart the instance. The specific registration method depends on your Linux distribution and MySQL installation method, please refer to the relevant documentation.
Performance Tuning and Best Practices
Multi-instance deployment consumes a lot of system resources, so resource allocation needs to be planned reasonably. The configuration file of each instance needs to be tuned according to actual conditions, such as adjusting the cache size, limiting the number of connections, etc. At the same time, data must be backed up regularly to prevent data loss. Code specifications and comments are also important, which facilitate future maintenance and upgrades.
Summary: It's not just steps, but also understanding
Remember that deploying multiple instances of MySQL is not just about copying the steps, but more importantly, understanding the principles behind it. Only by understanding the importance of data catalogs, configuration files and system service management can we truly master this technology and be able to deal with various emergencies. I hope this article can help you successfully complete the deployment of MySQL multi-instances and provide some help for your database management path. I wish you all the best!
The above is the detailed content of Detailed explanation of the steps for deploying MySQL multi-instance in Linux environment. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

To enable PHP containers to support automatic construction, the core lies in configuring the continuous integration (CI) process. 1. Use Dockerfile to define the PHP environment, including basic image, extension installation, dependency management and permission settings; 2. Configure CI/CD tools such as GitLabCI, and define the build, test and deployment stages through the .gitlab-ci.yml file to achieve automatic construction, testing and deployment; 3. Integrate test frameworks such as PHPUnit to ensure that tests are automatically run after code changes; 4. Use automated deployment strategies such as Kubernetes to define deployment configuration through the deployment.yaml file; 5. Optimize Dockerfile and adopt multi-stage construction

Select logging method: In the early stage, you can use the built-in error_log() for PHP. After the project is expanded, be sure to switch to mature libraries such as Monolog, support multiple handlers and log levels, and ensure that the log contains timestamps, levels, file line numbers and error details; 2. Design storage structure: A small amount of logs can be stored in files, and if there is a large number of logs, select a database if there is a large number of analysis. Use MySQL/PostgreSQL to structured data. Elasticsearch Kibana is recommended for semi-structured/unstructured. At the same time, it is formulated for backup and regular cleaning strategies; 3. Development and analysis interface: It should have search, filtering, aggregation, and visualization functions. It can be directly integrated into Kibana, or use the PHP framework chart library to develop self-development, focusing on the simplicity and ease of interface.

Directory What is Bitcoin? How does Bitcoin work? Why is Bitcoin not scalable? What is BIP (Bitcoin Improvement Proposal)? What is Bitcoin Taproot Update? Pay to Taproot (P2TR): Benefits of Taproot: Space-saving privacy advantages Security upgrade conclusion: ?Bitcoin is the first digital currency that can send and receive funds without using a third party. Since Bitcoin is software, like any other software, it needs updates and bug fixes. Bitcoin Taproot is such an update that introduces new features to Bitcoin. Cryptocurrency is a hot topic now. People have been talking about it for years, but now with prices rising rapidly, suddenly everyone decides to join and invest in them. Message

The total amount of Bitcoin is 21 million, which is an unchangeable rule determined by algorithm design. 1. Through the proof of work mechanism and the issuance rule of half of every 210,000 blocks, the issuance of new coins decreased exponentially, and the additional issuance was finally stopped around 2140. 2. The total amount of 21 million is derived from summing the equal-scale sequence. The initial reward is 50 bitcoins. After each halving, the sum of the sum converges to 21 million. It is solidified by the code and cannot be tampered with. 3. Since its birth in 2009, all four halving events have significantly driven prices, verified the effectiveness of the scarcity mechanism and formed a global consensus. 4. Fixed total gives Bitcoin anti-inflation and digital yellow metallicity, with its market value exceeding US$2.1 trillion in 2025, becoming the fifth largest capital in the world

MySQL needs to be optimized for financial systems: 1. Financial data must be used to ensure accuracy using DECIMAL type, and DATETIME is used in time fields to avoid time zone problems; 2. Index design should be reasonable, avoid frequent updates of fields to build indexes, combine indexes in query order and clean useless indexes regularly; 3. Use transactions to ensure consistency, control transaction granularity, avoid long transactions and non-core operations embedded in it, and select appropriate isolation levels based on business; 4. Partition historical data by time, archive cold data and use compressed tables to improve query efficiency and optimize storage.

Windowsisbetterforbeginnersduetoeaseofuse,seamlesshardwarecompatibility,andsupportformainstreamsoftwarelikeMicrosoftOfficeandAdobeapps.2.LinuxoutperformsWindowsonolderorlow-resourcehardwarewithfasterboottimes,lowersystemrequirements,andlessbloat.3.Li

Install Git: Install Git through the package manager on the server and verify the version; 2. Create a dedicated Git user: Use adduser to create a git user and optionally restrict its shell access; 3. Configure developer SSH access: Set the .ssh directory and authorized_keys file for git users, and add the developer's public key; 4. Create a bare repository: Initialize the bare repository on the server and set correct ownership; 5. Client cloning and push: Developer cloning the repository through SSH, submit changes and successfully push code to complete the construction of a private Git server.

The failure to register a Binance account is mainly caused by regional IP blockade, network abnormalities, KYC authentication failure, account duplication, device compatibility issues and system maintenance. 1. Use unrestricted regional nodes to ensure network stability; 2. Submit clear and complete certificate information and match nationality; 3. Register with unbound email address; 4. Clean the browser cache or replace the device; 5. Avoid maintenance periods and pay attention to the official announcement; 6. After registration, you can immediately enable 2FA, address whitelist and anti-phishing code, which can complete registration within 10 minutes and improve security by more than 90%, and finally build a compliance and security closed loop.
