MySQL multi-instance installation boot auto-start service configuration process

MySQL multi-instance installation boot auto-start service configuration process

1.MySQL multiple instances

MySQL multi-instance means running multiple MySQL databases on one or more machines, which greatly saves overhead and facilitates the management of data content.

2. Environmental equipment

System version Installation method and version
centos8 mysql5.7 (binary installation)

3. Create a data directory

The steps of adding environment variables and owners to the installation package are omitted, and all kinds of gods will

[root@clq ~]# mkdir /opt/data/{3306,3307,3308} -p
[root@clq ~]# chown mysql.mysql /opt/data/*

4. Initialize the databases separately

[root@192 ~]# mysqld --initialize --datadir=/opt/data/3306 --user=mysql
[root@192 ~]# mysqld --initialize --datadir=/opt/data/3307 --user=mysql
[root@192 ~]# mysqld --initialize --datadir=/opt/data/3308 --user=mysql
#Save 3 mysql passwords respectively [root@192 ~]# echo 'wxa+r_N6ooYu' > 3306
[root@192 ~]# echo 'faiuehfaowh' > 3307
[root@192 ~]# echo 'fuahfu' > 3308

5. Install perl

Perl provides all the functionality of scripting languages ​​such as sed and awk

[root@clq ~]# yum -y install perl

6. Install the packages required by mysql

[root@clq ~]# dnf whatprovides libncurses.so.5
ncurses-compat-libs-6.1-7.20180224.el8.i686 : Ncurses compatibility libraries #See which package provides the repository:
@System matches source: Provided by: libncurses.so.5
[root@clq ~]# dnf -y install ncurses-compat-libs (compatibility library)

7. Configure /etc/my.cnf file

[root@192 ~]# cat /etc/my.cnf 
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe #Safe directory mysqladmin = /usr/local/mysql/bin/mysqladmin #Administrator login directory [mysqld3306]
datadir = /opt/data/3306
port = 3306
socket = /tmp/mysql3306.sock
pid-file = /opt/data/3306/mysql3306.pid
log-error = /var/log/3306.log
[mysqld3307] #Must be mysqld3307, not mysql3307
datadir = /opt/data/3307
port = 3307
socket = /tmp/mysql3307.sock
pid-file = /opt/data/3307/mysql3307.pid
log-error = /var/log/3307.log
[mysqld3308]               
datadir = /opt/data/3308
port = 3308
socket = /tmp/mysql3308.sock
pid-file = /opt/data/3308/mysql3308.pid
log-error = /var/log/3308.log

8. Run the database

*Prerequisite: You must specify a socket or local ip127.0.0.1 to connect

  • Method 1: [root@clq ~]# mysql -uroot -p't%rIkwKeI5Rl' -P3306 -S /tmp/mysql3306.sock
  • Method 2: [root@clq ~]# mysql -uroot -p't%rIkwKeI5Rl' -P3306 -h127.0.0.1

//Enter mysql separately and change the passwords one by one

9. One-key start and automatic start

#Copy the mysqld_multi service script to /etc/init.d/[root@mysql ~]# cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multi
#Modify the script. When the system script is started, it will be reloaded in the new terminal. Adding this line will find mysqld_multi under bindir
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
export PATH=$bindir:$PATH
systemctl daemon-reload system reloading service is enabled:
[root@mysql ~]# service mysqld_multi start 3306
[root@mysql ~]# service mysqld_multi start 3307
[root@mysql ~]# service mysqld_multi start 3308
Self-start:
[root@mysql ~]# chkconfig mysqld_multi on
[root@mysql ~]#reboot
[root@mysql ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process                               
LISTEN 0 80 *:3306 *:*                          
LISTEN 0 80 *:3307 *:*                          
LISTEN 0 80 *:3308 *:*   

#Close a single mysql and kill the process using the kill method

The above is the details of the MySQL multi-instance installation and startup service configuration process. For more information about the MySQL multi-instance installation and startup service configuration, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of the installation, configuration, startup and shutdown methods of the Mysql server
  • MySQL5.7 single instance self-starting service configuration process
  • MySQL configuration master-slave server (one master and multiple slaves)
  • MySQL in Windows net start mysql Start MySQL service error occurs System error solution
  • 5 MySQL GUI tools recommended to help you with database management
  • 19 MySQL optimization methods in database management
  • Detailed introduction to 5 commonly used MySQL database management tools
  • Summary of Common Commands for MySQL Database Management
  • MySQL service and database management

<<:  js handles account logout when closing the browser

>>:  Detailed process of modifying hostname after Docker creates a container

Recommend

Why should you be careful with Nginx's add_header directive?

Preface As we all know, the nginx configuration f...

Use of Docker image storage overlayfs

1. Overview The image in Docker is designed in la...

Loading animation implemented with CSS3

Achieve results Implementation Code <h1>123...

Implementation of MySQL's MVCC multi-version concurrency control

1 What is MVCC The full name of MVCC is: Multiver...

Solution to Apache cross-domain resource access error

In many cases, large and medium-sized websites wi...

Tutorial on installing Ubuntu 20.04 and NVIDIA drivers

Install Ubuntu 20.04 Install NVIDIA drivers Confi...

How to change the mysql password on the Xampp server (with pictures)

Today, I found out while working on PHP that if w...

Apache Bench stress testing tool implementation principle and usage analysis

1: Throughput (Requests per second) A quantitativ...

How to draw a mind map in a mini program

Table of contents What is a mind map? How to draw...

javascript:void(0) meaning and usage examples

Introduction to void keyword First of all, the vo...

A simple example of mysql searching for data within N kilometers

According to the coefficient of pi and the radius...