Bereitstellung mehrerer Instanzen der MySQL-Datenbank
Vorwort
Diese Umgebung basiert auf dem Centos 7.8-System zum Erstellen von MySQL-5.7.14 für eine
bestimmte Konstruktion. Weitere Informationen finden Sie unter Aufbau der MySQL-5.7.14-Umgebung
In mehr Fällen stellen wir mehrere Anwendungsdatenbanken auf demselben Server bereit. Wenn sie jedoch auf demselben Datenbankdienst bereitgestellt werden, verursachen nachfolgende Produktaktualisierungen, Upgrades und Wartungsarbeiten viele Unannehmlichkeiten: Einflüsse. Daher löst die Bereitstellung mehrerer MySQL-Instanzen dieses Problem. Lässt mehrere Anwendungsdatenbankdienste unabhängig voneinander ausgeführt werden. Stellen Sie den effizienten, stabilen und sicheren Betrieb des Online-Geschäfts sicher.
Umgebungsbedingungen: mysql-5.7.14 universelle Bereitstellung von Binär- oder Quellcode
Erstens: Bereitstellung einer separaten Konfigurationsdatei für mysqld
Hinweis: Diese Bereitstellung basiert auf der Installation der MySQL-Quellumgebung
Die Bereitstellung von zwei MySQL-Service-
Ports für mehrere Instanzen erfolgt im
Datenbankverzeichnis 3306, 3307 : / mysql / 330 {6,7} / date
Öffentliches Verzeichnis: / usr / local / mysql
# 禁用数据库服务
[root@mysql-source_code ~]# systemctl stop mysqld
[root@mysql-source_code ~]# systemctl disable mysqld
# 创建多实例服务目录
[root@mysql-source_code ~]# mkdir /mysql/330{6,7}/data -p
# 分别提供配置文件
[root@mysql-source_code ~]# vim /mysql/3306/my.cnf
[client]
port = 3306
socket = /mysql/3306/mysql.sock
[mysqld]
user = mysql
port = 3306
socket = /mysql/3306/mysql.sock
basedir = /usr/local/mysql
datadir = /mysql/3306/data
server-id = 5
[mysqldump]
quick
max_allowed_packet = 16M
[mysqld_safe]
log-error=/mysql/3306/mysql_3306.err
pid-file=/mysql/3306/mysqld.pid
[root@mysql-source_code ~]# vim /mysql/3307/my.cnf
[client]
port = 3307
socket = /mysql/3307/mysql.sock
[mysqld]
user = mysql
port = 3307
socket = /mysql/3307/mysql.sock
basedir = /usr/local/mysql
datadir = /mysql/3307/data
server-id = 6
[mysqldump]
quick
max_allowed_packet = 16M
[mysqld_safe]
log-error=/mysql/3307/mysql_3307.err
pid-file=/mysql/3307/mysqld.pid
# 修改权限
[root@mysql-source_code ~]# chown -R mysql.mysql /mysql
# 初始化mysqld服务
[root@mysql-source_code ~]# /usr/local/mysql/bin/mysqld --initialize --datadir=/mysql/3306/data \
> --basedir=/usr/local/mysql --user=mysql
[root@mysql-source_code ~]# /usr/local/mysql/bin/mysqld --initialize --datadir=/mysql/3307/data \
> --basedir=/usr/local/mysql --user=mysql
# 启动服务
[root@mysql-source_code ~]# mysqld_safe --defaults-file=/mysql/3306/my.cnf &
[root@mysql-source_code ~]# mysqld_safe --defaults-file=/mysql/3307/my.cnf &
# 查看mysqld服务端口、进程状况
[root@mysql-source_code ~]# netstat -lnutp | grep 330
tcp6 0 0 :::3306 :::* LISTEN 2087/mysqld
tcp6 0 0 :::3307 :::* LISTEN 2288/mysqld
[root@mysql-source_code ~]# ps aux | grep mysqld
root 1914 0.0 0.0 113416 1584 pts/0 S 21:59 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/mysql/3306/my.cnf
mysql 2087 0.3 9.9 1833568 185824 pts/0 Sl 21:59 0:02 /usr/local/mysql/bin/mysqld --defaults-file=/mysql/3306/my.cnf --basedir=/usr/local/mysql --datadir=/mysql/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/mysql/3306/mysql_3306.err --pid-file=/mysql/3306/mysqld.pid --socket=/mysql/3306/mysql.sock --port=3306
root 2115 0.0 0.0 113416 1588 pts/0 S 22:00 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/mysql/3307/my.cnf
mysql 2288 0.3 9.8 1833568 183540 pts/0 Sl 22:00 0:03 /usr/local/mysql/bin/mysqld --defaults-file=/mysql/3307/my.cnf --basedir=/usr/local/mysql --datadir=/mysql/3307/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/mysql/3307/mysql_3307.err --pid-file=/mysql/3307/mysqld.pid --socket=/mysql/3307/mysql.sock --port=3307
root 2390 0.0 0.0 112812 972 pts/0 S+ 22:15 0:00 grep --color=auto mysqld
Melden Sie sich bei der Datenbank an
--- 3306
[root@mysql-source_code ~]# mysql -uroot -p -S /mysql/3306/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.14 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
--- 3307
[root@mysql-source_code ~]# mysql -uroot -p -S /mysql/3307/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.14
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user root@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql>
Stoppen Sie eine Datenbank mit mehreren Instanzen
[root@mysql-source_code ~]# mysqladmin -uroot -p123456 -S /mysql/3306/mysql.sock shutdown
[root@mysql-source_code ~]# mysqladmin -uroot -p123456 -S /mysql/3307/mysql.sock shutdown
2. Bereitstellung der gemeinsam genutzten Konfigurationsdatei von mysqld
# 禁用运行中的数据库
[root@mysql-source_code ~]# mysqladmin -uroot -p123456 -S /mysql/3306/mysql.sock shutdown
[root@mysql-source_code ~]# mysqladmin -uroot -p123456 -S /mysql/3307/mysql.sock shutdown
# 备份my.cnf文件
[root@mysql-source_code ~]# cp /etc/my.cnf /etc/my.cnf.bak
# 提供配置文件
[root@localhost ~]# cp /etc/my.cnf /etc/my.cnf.bak
[root@localhost ~]# vim /etc/my.cnf
[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = root
pass = 123456
[mysqld3306]
socket = /mysql/3306/mysql.sock
port = 3306
pid-file = /mysql/3306/mysql.pid
datadir = /mysql/3306/data
basedir = /usr/local/mysql
[mysqld3307]
socket = /mysql/3307/mysql.sock
port = 3307
pid-file = /mysql/3307/mysql.pid
datadir = /mysql/3307/data
basedir = /usr/local/mysql
# 启动服务
[root@mysql-source_code ~]# mysqld_multi start 3306,3307
# 查看mysqld服务端口、进程状况
[root@mysql-source_code ~]# netstat -lnutp | grep 330
tcp6 0 0 :::3306 :::* LISTEN 2022/mysqld
tcp6 0 0 :::3307 :::* LISTEN 2223/mysqld
[root@mysql-source_code ~]# ps aux | grep mysql
root 1849 0.0 0.0 113416 1588 pts/0 S 23:12 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/mysql/3306/my.cnf
mysql 2022 0.2 9.8 1833568 184216 pts/0 Sl 23:12 0:02 /usr/local/mysql/bin/mysqld --defaults-file=/mysql/3306/my.cnf --basedir=/usr/local/mysql --datadir=/mysql/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/mysql/3306/mysql_3306.err --pid-file=/mysql/3306/mysqld.pid --socket=/mysql/3306/mysql.sock --port=3306
root 2050 0.0 0.0 113416 1588 pts/0 S 23:12 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --defaults-file=/mysql/3307/my.cnf
mysql 2223 0.4 9.9 1833568 185988 pts/0 Sl 23:12 0:03 /usr/local/mysql/bin/mysqld --defaults-file=/mysql/3307/my.cnf --basedir=/usr/local/mysql --datadir=/mysql/3307/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/mysql/3307/mysql_3307.err --pid-file=/mysql/3307/mysqld.pid --socket=/mysql/3307/mysql.sock --port=3307
root 2276 0.0 0.1 133800 2516 pts/1 S+ 23:13 0:00 mysql -uroot -p -S /mysql/3307/mysql.sock
root 2470 0.0 0.0 112812 972 pts/0 S+ 23:25 0:00 grep --color=auto mysql
Melden Sie sich bei der Datenbank an
--- 3306
[root@mysql-source_code ~]# mysql -uroot -p -S /mysql/3306/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.14 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
--- 3306
[root@mysql-source_code ~]# mysql -uroot -p -S /mysql/3307/mysql.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.14 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Stoppen Sie eine Datenbank mit mehreren Instanzen
[root@mysql-source_code ~]# mysqld_multi stop 3306,3307