一个 MySQL 在线 DDL 工具 — pt-online-schema-change

MySQL 在线 DDL 工具之 pt-online-schema-change 为了解决这个问题,Percona Toolkit 提供了一个强大的工具,称为 pt-online-schema-change,它可以在不锁定表的情况下修改表结构,从而避免对数据库的影响。总结来说,pt-online-schema-change 是一个强大的 MySQL 在线 DDL 工具,可以在不锁定表的情况下对表结构进行修改。需要注意的是,pt-online-schema-change 不支持所有的 ALTER TABLE 语句,某些复杂的操作可能无法通过该工具来执行。如果不想使用默认的表名,可以使用。 阅读详情

在运维线上MySQL数据库时,我们总会对数据表进行 DDL 变更,修改添加字段或者索引。在对表进行 DDL 时,会锁表,当表比较小比如小于1w上时,对前端影响较小,当时遇到千万级别的表就会影响前端应用对表的写操作。

pt-online-schema-change 是 percona 公司开发的一个工具,在percona-toolkit包里面可以找到这个功能,它是一个在线DDL工具,可以实现在线数据表 DDL 操作。

使用方法

比如需要运行 SQL 的 DDL 语句

ADD COLUMN mode tinyint(4) DEFAULT NULL AFTER status

可以通过如下命令进行

nohup pt-online-schema-change \
	--charset=utf8 \
	--no-version-check \
	--user="数据库用户" \
	--password="数据库密码" \
	--host="数据库地址" \
	P=3306,D="数据库",t="数据表" \
	--alter "ADD COLUMN mode tinyint(4) DEFAULT NULL AFTER status" \
	--execute &

参数说明

--user=        连接mysql的用户名
--password=    连接mysql的密码
--host=        连接mysql的地址
P=3306         连接mysql的端口号
D=             连接mysql的库名
t=             连接mysql的表名
--alter        修改表结构的语句
--execute      执行修改表结构
--charset=utf8 使用utf8编码,避免中文乱码
--no-version-check  不检查版本,在阿里云服务器中一般加入此参数,否则会报错

工作过程

  1. 创建一个和要执行 alter 操作的表一样的新的空表结构(是 alter 之前的结构)

  2. 在新表执行 alter table 语句(速度应该很快)

  3. 在原表中创建触发器 3 个触发器分别对应 insert, update, delete 操作

  4. 以一定块大小从原表拷贝数据到临时表,拷贝过程中通过原表上的触发器在原表进行的写操作都会更新到新建的临时表

  5. Rename 原表到 old 表中,在把临时表 Rename 为原表

  6. 如果有参考该表的外键,根据 alter-foreign-keys-method 参数的值,检测外键相关的表,做相应设置的处理

  7. 默认最后将旧原表删除

安装方法

仅供参考(CentOS 7 验证)

sudo yum install -y perl-DBI perl-DBD-MySQL perl-Time-HiRes perl-IO-Socket-SSL perl-Digest-MD5 perl-TermReadKey.x86_64
sudo rpm -ivh percona-toolkit-3.1.0-2.el7.x86_64.rpm

参考资料

pt-online-schema-change

AUTOSAR从入门到精通-诊断事件管理模块(DEM)(四) 在 Autosar 中,诊断事件是指在车辆电子系统中发生的特定事件,可以用于诊断和故障排除。DEM模块通过EventId和相关的EventName来表示每个诊断事件。诊断事件的状态代表了监控器的结果,DEM模块通过RTE或其他BSW模块从SW-C接收监控器的结果。DEM模块使用EventId来管理系统中每个诊断事件的状态,并对各个测试结果执行所需的操作,例如存储冻结帧/拓展帧。所有监控器和BSW模块使用EventId作为符号化的EventName来管理诊断事件。 阅读详情

相关推荐

从《视觉SLAM十四讲》到项目实战:一文读懂拓扑地图与语义地图为何是服务机器人的未来

本文探讨了服务机器人地图技术的演进,从传统几何地图到拓扑地图与语义地图的跨越。通过分析栅格地图的局限性和拓扑地图、语义地图的优势,揭示了它们在动态开放环境中的智能应用。文章还介绍了多模态语义融合架构和动态语义更新技术,为服务机器人的未来发展提供了技术路线图。

weixin_30292843的博客 481

mysql 数据库-----免费在线使用(个人开发)

个人学习 python 的django 刚好找到免费的mysql 数据库,其他的会比较慢且提供的容量少。

weixin_44854422的博客 2719

告别PXE!用iPXE在CentOS 8.5上搭建一个能同时装Win11和Linux的万能网络启动盘

本文详细介绍了如何在CentOS 8.5上使用iPXE搭建支持Windows 11和Linux双系统部署的全能网络启动盘。通过对比传统PXE的局限性,展示了iPXE在HTTP协议支持、多架构适配和智能脚本方面的优势,提供从环境准备、服务配置到智能菜单开发的完整解决方案,显著提升系统部署效率。

weixin_29278805的博客 273

Mysql 数据库免费使用

由于工作需要现在打算学习WPF开发,因为需要访问mysql数据,但是又不想在自己电脑上安装。于是就上网试着查了下,发现果然有提供免费数据库服务的网站。nice!所以就打算写一篇文章详细记录一下,供大家参考。这个网站实在太良心了,完美解决私有mysql服务器部署麻烦、客户端安装麻烦等问题!

m0_46043168的博客 6207

WPS专业版自带字体

WPS专业版其中一个好处就是自带了部分有版权的字体,就算你安装了没买授权,他也会给你在系统里面安装上这些字体,至于没授权继续用合不合规我不知道。但是带来的实实在在的好处就是有些子他支持的全啊。 /usr/share/fonts/wps-office/FZWBK.TTF: 方正魏碑_GBK,FZWeiBei\-S03:style=Regular /usr/share/fonts/wps-office/FZFSK.TTF: 方正仿宋_GBK,FZFangSong\-Z02:style=Regular /us

chenqioulin的博客 5726

保姆级教程:STK 11.0 从下载到安装成功(附Matlab互联配置与常见问题解决)

本文提供STK 11.0的完整安装指南,包括下载、安装步骤、Matlab互联配置及常见问题解决方案。详细介绍了系统要求核查、分步安装流程、关键文件替换和许可证配置,确保用户能够顺利完成STK 11.0的部署并实现与Matlab的无缝对接。

weixin_30698297的博客 349

免费在线SQL运行环境(工具)

目录 Netstat 简述 常见参数 netstat -ano netstat -ano | findstr "端口号" Netstat 简述 Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等等。 Netstat是控制台...

蚩尤后裔-汪茂雄 1万+

Vscode搭配Keil Assistant插件,头文件红色波浪线终极修复指南

本文详细解析了Vscode搭配Keil Assistant插件时出现头文件红色波浪线问题的根源,即ARMCC与ARMCLANG编译器的兼容性问题,并提供了三种实用解决方案:复制文件夹、创建符号链接和手动配置includePath,帮助开发者彻底修复错误,恢复代码跳转和自动补全功能。

q1w3e5r7t9y的博客 362

实用!5个在线 SQL 数据库环境

文章目录SQL FiddleDB Fiddledb<>fiddleSQL OnlineOracle Live SQL总结大今天给大家分享几个在线的免费 SQL 运行环境,也就...

SeizeeveryDay的博客 1527

【实战指南】利用CAN适配器高效调试CAN总线通信

本文提供了一份利用CAN适配器高效调试CAN总线通信的实战指南。文章从硬件连接、终端电阻配置、软件参数设置等基础环节入手,详细解析了CAN适配器作为关键调试工具的工作原理与使用方法,并针对常见的通信故障提供了系统化的问题排查思路,帮助工程师快速打通通信链路,提升调试效率。

weixin_28285943的博客 426

【CANoe】CAPL_ECU上电后首帧报文发出时间检测

【CANoe】CAPL_ECU上电后首帧报文发出时间检测,通过CANoe I/O口检测电压实现

星Yeah 的博客 2528

mysql如何运行 mysql 基本命令

mysql如何运行 如何进入mysql mysql基本命令

小蒟蒻的博客 6623

RK3568 低功耗设计全解析:DVFS 策略与 PMIC 电源管理

本文深入解析RK3568处理器的低功耗优化方案。从硬件架构分析入手,阐述四核Cortex-A55的功耗特性及分层电源域设计。重点介绍DVFS动态调压调频技术,包括Linux内核配置方法及场景化策略设计。详细讲解RK809 PMIC的电源管理优化,提供外设电源域控制与休眠唤醒配置的实战案例。通过智能终端应用实例,展示待机功耗从280mA降至65mA的优化效果,并推荐功率测试工具。文章强调需要平衡性能与功耗,结合场景定制策略,并指出AI负载预测等未来优化方向,为RK3568开发者提供系统性的低功耗解决方案。

远程部署调试 运行安装 项目调试 二次开发 项目技术新 持续迭代 部分源码免费分享 2079

MySQL 在线 DDL 工具:pt-online-schema-change

在数据库管理中,数据定义语言(DDL)操作,如 `CREATE`、`ALTER` 和 `DROP`,是进行数据库结构修改的关键。然而,传统的 DDL 操作在执行时可能会对数据库性能产生显著影响,尤其是对于在线服务的系统来说,可能会导致长时间的锁表或性能下降。因此,如何在不中断服务的情况下完成这些操作,成为了数据库管理员(DBA)亟待解决的难题。幸运的是,Percona 提供了一个强大的在线 DDL 工具 —— **`pt-online-schema-change`**。

1701

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Mysql5.6 借助工具pt-online-schema-change在线DDL(还有加索引)

MySQL在线ddl会阻塞所有insert,可以使用percona-toolkit中的pt-online-schema-change工具来对表进行online。 D=tpcctest 数据库名 t=customer 表名 [root@localhost bin]# ./pt-online-schema-change -u root -h127.0.0.1 -proot  --alter=

关注系统性能调优 2044

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

[资料收集]MySQL在线DDL工具pt-online-schema-change

MySQL在线DDL工具pt-online-schema-change pt-online-schema-change使用说明(未完待续) 官网

weixin_34005042的博客 102

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

mysql ddl工具_【转】MySQL在线DDL工具pt-online-schema-change

原理pt-online-schema-change模拟了MySQL内部alter table的方式,但是其操作所更新的是复制表,所以原表不会被锁住。其原理我们通过示例进行解读:shell> pt-online-schema-change –nocheck-replication-filters –recursion-method=none –alter “add newcol int” h=...

weixin_39955825的博客 272

MySQL在线DDL实战:pt-online-schema-change工具详解与不停机表结构修改指南

pt-online-schema-change(简称PT-OSC)是Percona Toolkit工具包中的一个重要组件,专门用于MySQL数据库的在线表结构变更操作。Percona Toolkit是一套由Percona公司开发和维护的高级命令行工具集,旨在帮助数据库管理员(DBA)和开发者更高效地管理MySQL和MariaDB数据库。PT-OSC的核心功能是在不锁定原始表或导致业务停机的情况下,安全地执行ALTER TABLE操作,例如添加、修改或删除列,调整索引,或更改表引擎类型。

zuiyuelong的博客 1450

MySQL在线DDL工具pt-online-schema-change

mysql5.6中虽然引进了online DDL的功能,但是因为支持不够全面而且部分操作还是会阻塞DML语句,所以OSC还是相当有必要的 mysql online DDL原理:http://blog.csdn.net/hubo890224/article/details/50465818 原理 pt-online-schema-change模拟了MySQL内部alter ta

hubo890224的专栏 958

MySQL 在线DDL工具 pt-online-schema-change

1、下载解压 wget percona.com/get/percona-toolkit.tar.gz tar -zxvf percona-toolkit.tar.gz 2、安装 yum install perl-DBD-MySQL perl Makefile.PL  如遇如下错误 则先执行一下这句      yum install perl-Ex

李轮清的博客 677

db2 删除schema中所有表_详解一款mysql在线DDL操作不锁表工具--pt-online-schema-change...

概述作为DBA,我们也常常会碰到这样的需求:需要在不影响线上业务的情况下给表添加一个字段或索引。如果是一张只有几百或几千条记录的小表,这样的需求是非常容易解决的。但如果所管理的表数据量已经上亿、而且应用与数据库交互非常频繁,不允许停机窗口的出现,这样的需求又该如何满足?大多数的alter table操作都会涉及lock-->copy to new table-->rename--&gt...

weixin_39585691的博客 382

Online DDL 和PT-OSC怎么选择

pt-osc无论是什么DDL SQL,都会新建新表来替换,不分DDL类型,但是执行期间允许DDL操作,而ONLINE DDL则分为了好几类DDL,有的DDL仅需修改元数据,有的DDL仅需在本身ibd文件上新建索引页,有的需要rebuild table,这三种类型执行期间支持DML操作,但是COPY TABLE 类型不支持DML操作。 如果MySQL版本是5.6之前,不支持online ddl操作的,pt-online-schema-change是一个非常好的选择; 如...

AF 401

mysql 外键(foreign key)的详解和实例_mysql在线DDL操作--pt-online-schema-change使用、限制与比较...

概述在 mysql 5.5 版本以前,修改表结构如添加索引、修改列,需要锁表,期间不能写入,对于大表这简直是灾难。从5.5特别是5.6里,情况有了好转,支持Online DDL,pt-online-schema-change是Percona-toolkit一员,通过改进原生ddl的方式,达到不锁表在线修改表结构。1、pt-osc工作过程1)创建一个和要执行 alter 操作的表一样的新的空表结构(...

weixin_39915171的博客 329
上一篇: 使用中间件记录Laravel慢请求
下一篇: ModStart:拥抱新技术,率先支持 Laravel 9.0
ModStartCMS
博客等级 码龄5年 28粉丝 209原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址