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

Implementing a puzzle game with js

This article shares the specific code of js to im...

Mysql WorkBench installation and configuration graphic tutorial

This article shares with you the installation and...

JavaScript implements the protocol example in which the user must check the box

In js, set the user to read a certain agreement b...

JavaScript event capture bubbling and capture details

Table of contents 1. Event Flow 1. Concept 2. DOM...

15 Best Practices for HTML Beginners

Here are 30 best practices for HTML beginners. 1....

Detailed explanation of MySQL's FreeList mechanism

1. Introduction After MySQL is started, BufferPoo...

Vue encapsulation component tool $attrs, $listeners usage

Table of contents Preface $attrs example: $listen...

Implement a simple data response system

Table of contents 1. Dep 2. Understand obverser 3...

HTML table tag tutorial (27): cell background image attribute BACKGROUND

We can set a background image for the cell, and w...

If I change a property randomly in Vue data, will the view be updated?

Interviewer: Have you read the source code of Vue...

Vue implements countdown between specified dates

This article example shares the specific code of ...