日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql dba系统学习(4)mysql的多实例multi启动停止

發布時間:2025/3/21 数据库 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql dba系统学习(4)mysql的多实例multi启动停止 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

mysql的多實例配置安裝

?一,什么情況下我們會考慮一臺物理服務器上部署多個實例,大致有以下幾種情況:

1,采用了數據偽分布式架構的原因,而項目啟動初期又不一定有那多的用戶量,為此先一組物理數據庫服務器,但部署多個實例,方便后續遷移;

2,為規避mysql對SMP架構不支持的缺陷,使用多實例綁定處理器的辦法(NUMA處理器必須支持,不過現在大部分處理器都支持的!),把不同的數據庫分配到不同的實例上提供數據服務;

3,一臺物理數據庫服務器支撐多個數據庫的數據服務,為提高mysql復制的從機的恢復效率,采用多實例部署;

已經為雙主復制的mysql數據庫服務器架構,想部分重要業務的數據多一份異地機房的熱備份,而mysql復制暫不支持多主的復制模式,且不給用戶提供服務,為有效控制成本,會考慮異地機房部署一臺性能超好的物理服務器,甚至外加磁盤柜的方式,為此也會部署多實例;

4,傳統游戲行業的MMO/MMORPG,以及Web Game,每一個服都對應一個數據庫,而可能要做很多數據查詢和數據訂正的工作,為減少維護而出錯的概率,也可能采用多實例部署的方式,按區的概念分配數據庫;


?二,mysql的多實例的介紹

? ? ? ? ?mysqld_multi被設計為了管理實現多個mysqld服務進程 ??


?三,配置多實例mysqld及初始化

1,創建實例的數據文件目錄

[root@test4 ~]# cd /mysql/
[root@test4 mysql]# ls?
data
[root@test4 mysql]# mkdir data2/
[root@test4 mysql]# mkdir data3/

2,初始化多實例mysql
[root@test4 mysql]# mysql_install_db ? --datadir=/mysql/data2/ ?--user=mysqlInstalling?

MySQL system tables...
OK

[root@test4 mysql]# mysql_install_db ? --datadir=/mysql/data3/ ?--user=mysqlInstalling MySQL?

system tables...
OK
Filling help tables...
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h test4.wolf.org password 'new-password'
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. ?This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr/local/mysql ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/mysql/bin/mysqlbug script!

3,配置mysqld的多實例my.cnf文件

(1)配置my.cnf文件詳解

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 [root@test4 ~]# cat? /etc/my.cnf [mysqld_multi] mysqld =/usr/local/mysql/bin/mysqld_safe mysqladmin =/usr/local/mysql/bin/mysqladmin user =test password =test [client] #password?????? = your_password port??????????? =?3306 socket????????? = /tmp/mysql.sock [mysqld3306] port??????????? =?3306 socket????????? = /tmp/mysql3306.sock skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache =?64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M log-bin=mysql-bin binlog_format=mixed datadir = /mysql/data server-id?????? =?1 [mysqld3307] port??????????? =?3307 socket????????? = /tmp/mysql3307.sock skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache =?64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M log-bin=mysql-bin binlog_format=mixed datadir = /mysql/data2 server-id?????? =?1 [mysqld3308] port??????????? =?3308 socket????????? = /tmp/mysql3308.sock skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache =?64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M log-bin=mysql-bin binlog_format=mixed datadir = /mysql/data3 server-id?????? =?1 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout

(2)啟動多實例

[root@test4 ~]# /usr/local/mysql/bin/mysqld_multi ?--defaults-file=/etc/my.cnf ?start 3308

? ? ?[root@test4 ~]# ps aux|grep 3308
root ? ? ?4887 ?0.0 ?0.2 106012 ?1348 pts/1 ? ?S ? ?14:57 ? 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --port=3308 --socket=/tmp/mysql3308.sock --skip-external-locking --key_buffer_size=16M --max_allowed_packet=1M --table_open_cache=64 --sort_buffer_size=512K --net_buffer_length=8K --read_buffer_size=256K --read_rnd_buffer_size=512K --myisam_sort_buffer_size=8M --log-bin=mysql-bin --binlog_format=mixed --datadir=/mysql/data3 --server-id=1
mysql ? ? 5034 ?0.0 ?1.3 125304 ?6668 pts/1 ? ?Sl ? 14:57 ? 0:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/mysql/data3 --user=mysql --skip-external-locking --key_buffer_size=16M --max_allowed_packet=1M --table_open_cache=64 --sort_buffer_size=512K --net_buffer_length=8K --read_buffer_size=256K --read_rnd_buffer_size=512K --myisam_sort_buffer_size=8M --log-bin=mysql-bin --binlog_format=mixed --server-id=1 --log-error=/mysql/data3/test4.wolf.org.err --pid-file=/mysql/data3/test4.wolf.org.pid --socket=/tmp/mysql3308.sock --port=3308

(3)連接mysql多實例

[root@test4 ~]# mysql ?-S ?/tmp/mysql3308.sock?
Welcome to the MySQL monitor. ?Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.70-log Source distribution

Copyright (c) 2000, 2013, 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> show databases;
+--------------------+
| Database ? ? ? ? ? |
+--------------------+
| information_schema |
| mysql ? ? ? ? ? ? ?|
| test ? ? ? ? ? ? ? |
+--------------------+
3 rows in set (0.01 sec)
? (4)啟停多實例musql

? ? ? ? ? ? 由于是多實例的方式來管理mysql,所以暫時不可以通過如下方式來停止數據庫

[root@test4 ~]# /usr/local/mysql/bin/mysqld_multi ?--defaults-file=/etc/my.cnf ?stop ?3308

真正的關閉多實例MySQL的方法是通過配置在/etc/my.cnf中test用戶,?

? [root@test4 ~]# mysql -S ?/tmp/mysql3308.sock?
mysql> GRANT SHUTDOWN ON *.* TO 'test'@'localhost' IDENTIFIED BY 'TEST' WITH GRANT OPTION;

Query OK, 0 rows affected (0.00 sec)

? [root@test4 ~]# mysqld_multi ?--defaults-file=/etc/my.cnf ? stop 3306
[root@test4 ~]# mysqld_multi ?--defaults-file=/etc/my.cnf ? stop 3307
[root@test4 ~]# mysqld_multi ?--defaults-file=/etc/my.cnf ? stop 3308
[root@test4 ~]# ps aux|grep mysql
root ? ? ?6148 ?0.0 ?0.1 103152 ? 824 pts/1 ? ?S+ ? 15:48 ? 0:00 grep mysql

本文出自 “好好活著” 博客,請務必保留此出處http://wolfword.blog.51cto.com/4892126/1241304

總結

以上是生活随笔為你收集整理的mysql dba系统学习(4)mysql的多实例multi启动停止的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。