当前位置:网站首页>Technology sharing | MySQL shell customized deployment MySQL instance
Technology sharing | MySQL shell customized deployment MySQL instance
2022-07-28 16:58:00 【ActionTech】
author : Yang Taotao
Senior database expert , Specialized research MySQL More than ten years . Good at MySQL、PostgreSQL、MongoDB And other open source database related backup recovery 、SQL tuning 、 Monitoring operation and maintenance 、 High availability architecture design, etc . At present, I work in akerson , For major operators and bank financial enterprises MySQL Related technical support 、MySQL Related courses, training, etc .
In this paper, the source : Original contribution
* Produced by aikesheng open source community , Original content is not allowed to be used without authorization , For reprint, please contact the editor and indicate the source .
Previously written and used MySQL Shell Of DBA Components to build 、 Operation and maintenance MySQL InnoDB Cluster . Today, let's continue on DBA Extended introduction of components , Discuss how to use it to customize the deployment MySQL example .
One 、 How to deploy multiple versions MySQL example :
By default DBA When a component deploys multiple instances , Using the built-in MySQL edition , That is, in the environment variable $PATH Search in the included path mysqld To confirm the specific instance version . For example, on my machine , Default MySQL Version is 8.0 , So the instance version after direct deployment is also 8.0.
[email protected]:~# mysqlsh --py
MySQL Shell 8.0.29
...
MySQL Py > dba.deploy_sandbox_instance(3350);
A new MySQL sandbox instance will be created on this host in
/root/mysql-sandboxes/3350
...
Instance localhost:3350 successfully deployed and started.
Use shell.connect('[email protected]:3350') to connect to the instance.
For example, the above port is 3350 After the deployment is completed , Create a new connection , After success, the client will receive the specific version :Server version: 8.0.29 MySQL Community Server - GPL.
MySQL Py > \c [email protected]:3350
...
Your MySQL connection id is 12
Server version: 8.0.29 MySQL Community Server - GPL
If you want to deploy multiple different versions at the same time MySQL example , Just put the corresponding version of mysqld Path into $ PATH that will do . It should be noted that , New path and old $ PATH Splicing sequence : The new path comes first , The old $ PATH After ! After deployment , Remember to put it again $PATH Content restore .
For example, on my machine MySQL 5.7 The directory of the version installation package is :/root/opt/mysql/5.7.34 , Then add subdirectories of this directory bin To environment variable $PATH that will do :
[email protected]:~# export PATH=/root/opt/mysql/5.7.34/bin:$PATH
Re enter MySQL Shell Environmental Science , And above MySQL 8.0 The same deployment method : You can see , The newly deployed instance version is 5.7.34-log MySQL Community Server (GPL).
MySQL Py > dba.deploy_sandbox_instance(3351)
A new MySQL sandbox instance will be created on this host in
/root/mysql-sandboxes/3351
...
Instance localhost:3351 successfully deployed and started.
Use shell.connect('[email protected]:3351') to connect to the instance.
MySQL Py > \c [email protected]:3351
...
Your MySQL connection id is 7
Server version: 5.7.34-log MySQL Community Server (GPL)
Two 、 How to change the basic directory of a deployment instance :
The default deployment instance file is ~/mysql-sandboxes Next , Divide by instance port , One subdirectory per port . For example, the two previously deployed MySQL example , Corresponding to the directory /root/mysql-sandboxes/3350、/root/mysql-sandboxes/3351 .
There are two ways to change the basic directory of the deployment instance :
1. call dba.deploy_sandbox_instance when , Explicitly specify the deployment directory :
- sandboxDir: path where the new instance will be deployed.
For example, deploy a new instance 3352, Specify the basic directory as :/tmp/mysql-sandbox.
MySQL Py > dba.deploy_sandbox_instance(3352,{"sandboxDir":"/tmp/mysql-sandbox"})
A new MySQL sandbox instance will be created on this host in
/tmp/mysql-sandbox/3352
...
Instance localhost:3352 successfully deployed and started.
Use shell.connect('[email protected]:3352') to connect to the instance.
The biggest disadvantage of this method is that it is not universal for the deployment of subsequent new instances , You need to specify... For each new instance sandboxDir Option . If you don't explicitly specify , Then continue to use the default directory :~/mysql-sandboxes. For example, the following deployment example 3353, Still use the default directory .
MySQL Py > dba.deploy_sandbox_instance(3353)
A new MySQL sandbox instance will be created on this host in
/root/mysql-sandboxes/3353
The next way is directly in MySQL Shell Of Shell Specify the basic deployment directory in the component , It works for the overall situation .
2. Set explicitly shell Component's options Dictionary properties , modify KEY be known as sandboxDir The value of is the specified directory :
- sandboxDir: default path where the new sandbox instances for InnoDB cluster will be deployed
Set up sandboxDir by /tmp/mysql-sandbox : --persist For permanent effect , similar MySQL Inside set persist Grammatical effect .
MySQL Py > \option --persist sandboxDir /tmp/mysql-sandbox
Re enter MySQL Shell Environmental Science , Deploy two new instances , The corresponding ports are 3353 and 3354: Both instances are deployed in the directory /tmp/mysql-sandbox Next .
MySQL Py > for i in range(3353,3355):
-> dba.deploy_sandbox_instance(i)
->
A new MySQL sandbox instance will be created on this host in
/tmp/mysql-sandbox/3353
...
A new MySQL sandbox instance will be created on this host in
/tmp/mysql-sandbox/3354
...
3、 ... and 、 How to change the instance parameters of a new deployment :
No specific parameters are set for the above deployed instances , Only the default values are used . No matter what scenario the deployed instance is used in , Some parameters still need to change with the scene . There are two ways to change parameters :
1. Configure parameters while deploying instances : Suitable for changing a few parameters .
For example, deploy a new instance 3355, Specify the following parameters respectively :
server-id=1000
tmp_table_size=64M
read_buffer_size=1M
Add these parameters to mysqldOptions The array can be .
MySQL Py > dba.deploy_sandbox_instance(3355,{"mysqldOptions":["server_id=1000","tmp_table_size=64M","read_buffer_size=1M"]})
A new MySQL sandbox instance will be created on this host in
/tmp/mysql-sandbox/3355
...
Instance localhost:3355 successfully deployed and started.
Use shell.connect('[email protected]:3355') to connect to the instance.
confirm my.cnf Successfully changed :
[email protected]:/tmp/mysql-sandbox/3355# grep "server_id\|tmp_table_size\|read_buffer_size" my.cnf
server_id = 1000
tmp_table_size = 64M
read_buffer_size = 1M
2. Configure the parameters after deploying the instance : Suitable for changing a large number of parameters .
Directly change the corresponding my.cnf , After that, restart .
summary :
Use MySQL Shell Of DBA Components can be deployed easily MySQL example , But it is not recommended to produce , Because of entering MySQL Shell After environment , These instances can be maintained at will , Increased risk .
边栏推荐
- ERROR: transport library not found: dt_ socket
- parseJson
- 阿里大哥教你如何正确认识关于标准IO缓冲区的问题
- Do you really understand CMS garbage collector?
- Applet: get element node information
- 【深度学习】:《PyTorch入门到项目实战》第六天:多层感知机(含代码)
- 做题笔记5(有序数组的平方)
- Hdu1847 problem solving ideas
- Microsoft question 100 - do it every day - question 11
- Ansa secondary development - two methods of drawing the middle surface
猜你喜欢
随机推荐
Multiple commands produce '... /xxx.app/assets.car' problem
MD5 encryption verification
Exercise note 5 (square of ordered array)
【从零开始学习SLAM】将坐标系变换关系发布到 topic tf
大学生参加六星教育PHP培训,找到了薪水远超同龄人的工作
Hdu1847 problem solving ideas
How should I understand craft
阿里大哥教你如何正确认识关于标准IO缓冲区的问题
Learn to use MySQL explain to execute the plan, and SQL performance tuning is no longer difficult
阿里云-武林头条-建站小能手争霸赛
Some opinions on bug handling
TCP handshake, waving, time wait connection reset and other records
MySQL CDC if the binlog log file is incomplete, can you read all the data in the full volume stage
【深度学习】:《PyTorch入门到项目实战》第二天:从零实现线性回归(含详细代码)
获取时间戳的三种方法的效率比较
Ruoyi集成flyway后启动报错的解决方法
2020Q2全球平板市场出货大涨26.1%:华为排名第三,联想增幅最大!
技术分享 | 误删表以及表中数据,该如何恢复?
Alibaba cloud MSE supports go language traffic protection
RE14: reading paper illsi interpretable low resource legal decision making









