Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql uses mysql_multi to configure multiple instances of a host.

Shulou Source: shulou.com Published: 2022-06-01 05:31:37 11月03日 Update

In the official Mysql help documentation, there are three ways to start Mysql: mysqld_safe, mysql.server, and mysql_multi. Introduction to mysql_multi:

Mysqld_multi can manage mysqld processes that connect multiple frames to listen to different Unix socket files and TCP/IP ports. It can start or stop servers or report their current status.

That is, multiple instances can be managed.

The author has also introduced the method of using mysqld_safe to enable multiple instances. Configuration files are specified for startup and shutdown, and the instances are opposed to each other and do not affect each other. Multiple instance master / slave Replication has been successfully deployed. Today, we also introduce mysql_multi multi-instance management, which is simple to configure and easy to manage.

1. First configure the my.cnf file and list my Mysql configuration file:

[mysqld_multi]

Mysqld = / usr/local/mysql/bin/mysqld_safe # configure according to your own mysql directory

Mysqladmin = / usr/local/mysql/bin/mysqladmin

[mysqld1]

Port = 3306

Socket = / tmp/mysql3306.sock

Basedir=/usr/local/mysql

Datadir=/mysqldata/data3306

Log-slow-queries=slow_query.txt

Long_query_time=2

Skip-locking

Skip-name-resolve

Skip-innodb

Max_allowed_packet = 256m

Query_cache_size=256M

Max_connections=2000

Max_connect_errors=10000

Key_buffer_size=6000M

Read_buffer_size=32M

Read_rnd_buffer_size = 32m

Myisam_sort_buffer_size=512M

Tmp_table_size=1024M

Old-passwords

Interactive_timeout=60

Wait_timeout=60

Connect_timeout=60

Table_cache=8192

Thread_cache_size=512

Sort_buffer_size=128M

Back_log = 500,

Thread_concurrency=48

Expire_logs_days=10

Log-bin=mysql-bin

[mysqld2]

Port = 3307

Socket = / tmp/mysql3307.sock

Basedir=/usr/local/mysql

Datadir=/mysqldata/data3307

Log-slow-queries=slow_query.txt

Long_query_time=2

Skip-locking

Skip-name-resolve

Skip-innodb

Max_allowed_packet = 256m

Query_cache_size=256M

Max_connections=2000

Max_connect_errors=10000

Key_buffer_size=6000M

Read_buffer_size=32M

Read_rnd_buffer_size = 32m

Myisam_sort_buffer_size=512M

Tmp_table_size=1024M

Old-passwords

Interactive_timeout=60

Wait_timeout=60

Connect_timeout=60

Table_cache=8192

Thread_cache_size=512

Sort_buffer_size=128M

Back_log = 500,

Thread_concurrency=48

Expire_logs_days=10

Log-bin=mysql-bin

[mysqldump]

Quick

Max_allowed_packet = 512m

[mysql]

No-auto-rehash

[isamchk]

Key_buffer = 512m

Sort_buffer_size = 32m

Read_buffer = 2m

Write_buffer = 2m

[myisamchk]

Key_buffer = 512m

Sort_buffer_size = 32m

Read_buffer = 2m

Write_buffer = 2m

[mysqlhotcopy]

Interactive-timeout

2. Initialize the database directory:

Shell > cd / usr/local/mysql/;./scripts/mysql_install_db-datadir=/mysqldata/data3307/-user=mysql

Shell > cd / usr/local/mysql/;./scripts/mysql_install_db-datadir=/mysqldata/data3306/-user=mysql

If the initial message is successful, OK will be prompted, otherwise, check to see if the database directory has permissions.

3. Start multiple instances:

Shell > / usr/local/mysql/bin/mysqld_multi start 1-2

Or

Shell > / usr/local/mysql/bin/mysqld_multi start 1

Shell > / usr/local/mysql/bin/mysqld_multi start 2

Note that 1 and 2 here correspond to the my.cnf configuration files mysqld1 and mysqld2 to distinguish.

4. Log in to Mysql locally, such as port 3307:

Shell > mysql-S / tmp/mysql3307.sock

Mysql > show variables like 'datadir'

+-- +

| | Variable_name | Value |

+-- +

| | datadir | / mysqldata/data3307/ |

+-- +

1 row in set (0.00 sec)

4. Close the database instance

Shell > / usr/local/mysql/bin/mysqld_multi stop 1-2

Or

Shell > / usr/local/mysql/bin/mysqld_multi stop 1

Shell > / usr/local/mysql/bin/mysqld_multi stop 2

Tags: Instance configuration file management multiple data database directory success port different master-slave socket official report document method method server permission Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei vpn Shulou Information Linux Microsoft