search
HomeDatabaseMysql Tutorialmysql大数据表改表结构方案_MySQL

bitsCN.com

有一个表有上千W数据, 用什么方法给这个表加一个字段最快?
1. alert
2. 建一个表和第一个表一样,只是多了要加的字段,然后用多个INSERT INTO SELECT语句limit写入
3. 就是导出多个文件,然后用loadfile
4. 其它?

试过2.5KW数据, alert要156m。
INSERT INTO SELECT 100W要5m46s

两个工具选择:

http://www.percona.com/software/percona-toolkit

http://www.percona.com/doc/percona-toolkit/2.2/pt-online-schema-change.html

 

第二个工具是比较好的选择,可以线上改表结构,试试再给报告给大家

 

正在使用第二个工具,也就是"Facebook 针对 MySQL 开源 Online Schema Change 代码" 

参考文档:

http://blog.chinaunix.net/uid-53720-id-3371360.html

http://blog.csdn.net/dbanote/article/details/18261377

 

正在测试环境测试,测试数据量大约是2500W左右,随后有测试报告,没什么问题就上生产环境了

 pt-online-schema-change --alter "ADD category tinyint(4) NOT NULL DEFAULT '0'" D=库名,t=表名 -uroot -p密码 --dry-run

 如果你的库有主从结构,执行上面的语句遇到如下问题:

Cannot connect to D=calsync,h=从库的IP,p=...,u=root
No slaves found. See --recursion-method if host localhost.localdomain has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.

请在从库上建一个root帐号且密码和上面的密码一样,且主库机可以访问

如果出现如下内容:

Found 1 slaves:
localhost.localdomain
Will check slave lag on:
localhost.localdomain

恭喜主从的没有问题了

bitsCN.com
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
mysql怎么替换换行符mysql怎么替换换行符Apr 18, 2022 pm 03:14 PM

在mysql中,可以利用char()和REPLACE()函数来替换换行符;REPLACE()函数可以用新字符串替换列中的换行符,而换行符可使用“char(13)”来表示,语法为“replace(字段名,char(13),'新字符串') ”。

mysql怎么将varchar转换为int类型mysql怎么将varchar转换为int类型May 12, 2022 pm 04:51 PM

转换方法:1、利用cast函数,语法“select * from 表名 order by cast(字段名 as SIGNED)”;2、利用“select * from 表名 order by CONVERT(字段名,SIGNED)”语句。

MySQL复制技术之异步复制和半同步复制MySQL复制技术之异步复制和半同步复制Apr 25, 2022 pm 07:21 PM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了关于MySQL复制技术的相关问题,包括了异步复制、半同步复制等等内容,下面一起来看一下,希望对大家有帮助。

带你把MySQL索引吃透了带你把MySQL索引吃透了Apr 22, 2022 am 11:48 AM

本篇文章给大家带来了关于mysql的相关知识,其中主要介绍了mysql高级篇的一些问题,包括了索引是什么、索引底层实现等等问题,下面一起来看一下,希望对大家有帮助。

mysql怎么判断是否是数字类型mysql怎么判断是否是数字类型May 16, 2022 am 10:09 AM

在mysql中,可以利用REGEXP运算符判断数据是否是数字类型,语法为“String REGEXP '[^0-9.]'”;该运算符是正则表达式的缩写,若数据字符中含有数字时,返回的结果是true,反之返回的结果是false。

mysql需要commit吗mysql需要commit吗Apr 27, 2022 pm 07:04 PM

在mysql中,是否需要commit取决于存储引擎:1、若是不支持事务的存储引擎,如myisam,则不需要使用commit;2、若是支持事务的存储引擎,如innodb,则需要知道事务是否自动提交,因此需要使用commit。

mysql-connector是什么mysql-connector是什么May 12, 2022 pm 04:04 PM

“mysql-connector”是mysql官方提供的驱动器,可以用于连接使用mysql;可利用“pip install mysql-connector”命令进行安装,利用“import mysql.connector”测试是否安装成功。

MySQL中的数据表压缩技术MySQL中的数据表压缩技术Jun 16, 2023 am 08:16 AM

MySQL是一种常见的关系型数据库,是许多网站和应用程序的核心组件。随着数据量越来越大,如何优化MySQL的性能就变得尤为重要。其中一个关键领域是数据表的压缩,在本文中我们将介绍MySQL中的数据表压缩技术。压缩表和非压缩表MySQL中有两种类型的数据表:压缩表和非压缩表。非压缩表是MySQL默认的表类型,它使用固定长度的行格式,对数据进行存储。这意味着数据

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),