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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

MySQL5.6多实例部署

發(fā)布時間:2025/6/15 数据库 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MySQL5.6多实例部署 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

無論是迫于預(yù)算,亦或者是領(lǐng)導(dǎo)要求,多實例的安裝也是DBA必須掌握的技術(shù),她的啟停和登錄方式和單實例安裝數(shù)據(jù)庫略有不同,本文記錄下如何完成MySQL5.6多實例部署。

首先我們看一下my.cnf和單實例的區(qū)分:

[root@HE1 scripts]#
cat /etc/my.cnf
[client]
#port = 3306
#socket = /tmp/mysql.sock
#default-character-set = utf8
? ?
[mysql]
#default-character-set = utf8
? ?
[mysqld3306]
port = 3306
basedir = /usr/local/mysql
datadir = /data/mysql_3306
socket? = /tmp/mysql_3306.sock
slow_query_log_file = /data/mysql_3306/slow.log
log-error = /data/mysql_3306/error.log
log-bin = /data/mysql_3306/mysql-bin
sync_binlog = 1
binlog_format = row
transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 100m
? ?
[mysqld3308]
port = 3308
basedir = /usr/local/mysql
datadir = /data/mysql_3308
socket = /tmp/mysql_3308.sock
slow_query_log = 1
slow_query_log_file = /data/mysql_3308/slow.log
log-error = /data/mysql_3308/error.log
long_query_time = 1
log-bin = /data/mysql_3308/mysql-bin
sync_binlog = 1
binlog_cache_size = 4M
default-storage-engine = InnoDB
binlog_format = row
transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 100m
? ?
[mysqld_multi]
mysqld=/usr/local/mysql/bin/mysqld_safe
mysqladmin=/usr/local/mysql/bin/mysqladmin
? ?
? ?
[mysqldump]
quick
max_allowed_packet = 32M

可以看出,多實例的my.cnf實際上就是如上所示,本文為了演示實驗環(huán)境,innodb_buffer_pool_size僅僅開了100m,真實的生產(chǎn)庫中多實例部署該參數(shù)要開大些,兩個實例該參數(shù)的值達(dá)到內(nèi)存的50%-80%都可以。

下面開始初始化我們的數(shù)據(jù)庫
首先創(chuàng)建我們的數(shù)據(jù)目錄
[root@HE1 ~]#mkdir -p /data/mysql_3306
[root@HE1 ~]#mkdir -p /data/mysql_3308
[root@HE1 ~]#echo "export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib" >>/etc/profile

進(jìn)入到mysql的scripts文件夾下對數(shù)據(jù)庫進(jìn)行初始化,這里我們對3306端口數(shù)據(jù)庫進(jìn)行初始化
[root@HE1 scripts]#./mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql_3306 --defaults-file=/etc/my.cnf --user=mysql

這里我們對3308端口數(shù)據(jù)庫進(jìn)行初始化
[root@HE1 scripts]# ./mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql_3308 --defaults-file=/etc/my.cnf --user=mysql

初始化完成后,我們便可以啟停數(shù)據(jù)庫了,和單實例不同,多實例采用mysqld_multi來啟停數(shù)據(jù)庫
[root@HE1 bin]# ./mysqld_multi --defaults-file=/etc/my.cnf --user=root --password=MANAGER start 3306,3308

可以利用mysqld_multi的report命令來檢測多實例的運行狀況
1234 [root@HE1 bin]#./mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld3306 is running
MySQL server from group: mysqld3308 is running

登錄方式和單實例大體相同,不過由于多實例的存在,我們需要指定不同的端口號
[root@HE1 bin]# mysql -uroot -p -P3306 -h 192.168.1.48
Enter password:
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 6 Server version: 5.6.16-log MySQL Community Server (GPL)
? ?
Copyright (c) 2000,
2014, 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
|
| 3306db? ? ? ? ? ? ?|
| mysql? ? ? ? ? ? ? |
| performance_schema
|
| test? ? ? ? ? ? ? ?|
+--------------------+
5 rows in set (0.00 sec)

當(dāng)然,利用socket文件登錄也是可以的
[root@HE1 bin]#mysql -uroot -p -S /data/mysql_3306/mysql_3306.sock
Enter password:
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 7 Server version: 5.6.16-log MySQL Community Server (GPL)
? ?
Copyright (c) 2000,
2014, 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
|
| 3306db? ? ? ? ? ? ?|
| mysql? ? ? ? ? ? ? |
| performance_schema
|
| test? ? ? ? ? ? ? ?|
+--------------------+
5 rows in set (0.00 sec)

這里是登錄3308端口數(shù)據(jù)庫
[root@HE1 bin]#mysql -uroot -p -P3308 -h 192.168.1.48
Enter password:
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 8 Server version: 5.6.16-log MySQL Community Server (GPL)
? ?
Copyright (c) 2000,
2014, 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.
? ?
? ?
Type 'help;' or '\h'
for help. Type '\c' to clear the current input statement.
? ?
mysql> show databases;
+--------------------+
| Database? ? ? ? ? ?|
+--------------------+
| information_schema
|
| 3308db? ? ? ? ? ? ?|
| mysql? ? ? ? ? ? ? |
| performance_schema
|
| test? ? ? ? ? ? ? ?|
+--------------------+
5 rows in set (0.00sec)
? ?
mysql> quit
Bye

利用3308端口的socket文件登錄數(shù)據(jù)庫
[root@HE1 bin]#mysql -uroot -p -S /data/mysql_3308/mysql_3308.sock
Enter password:
Welcome to the MySQL monitor.? Commands end with ; or \g.
Your MySQL connection id is 9 Server version: 5.6.16-log MySQL Community Server (GPL)
? ?
Copyright (c) 2000,
2014, 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
|
| 3308db? ? ? ? ? ? ?|
| mysql? ? ? ? ? ? ? |
| performance_schema
|
| test? ? ? ? ? ? ? ?|
+--------------------+
5 rows in set (0.00sec)

至此,MySQL5.6多實例部署完成。


轉(zhuǎn)載于:https://blog.51cto.com/wenzengliu/1851831

《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀

總結(jié)

以上是生活随笔為你收集整理的MySQL5.6多实例部署的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。