Home Database Mysql Tutorial MYSQL之插入极限分析_MySQL

MYSQL之插入极限分析_MySQL

Jun 01, 2016 pm 01:23 PM
client

bitsCN.com 1、如果同时从同一个客户端插入很多行,使用含多个 VALUE的INSERT语句同时插入几行。这比使用单行INSERT语句快(在某些情况下快几倍)。如果你正向一个非空表添加数据,可以调节 bulk_insert_buffer_size变量,使数据插入更快。参见5.3.3 节,“服务器系统变量”。

2、如果你从不同的客户端插入很多行,能通过INSERT DELAYED语句加快速度。参见13.2.4 节,“INSERT语法”。

3、用MyISAM,如果在表中没有删除的行,能在SELECT语句正在运行的同时插入行。

4、当从一个文本文件装载一个表时,使用LOAD DATA INFILE。这通常比使用很多INSERT语句快20倍。参见13.2.5 节,“LOAD DATA INFILE语法”。

5、当表有很多索引时,有可能要多做些工作使得LOAD DATA INFILE更快些。使用下列过程:

1). 有选择地用CREATE TABLE创建表。
2). 执行FLUSH TABLES语句或命令mysqladmin flush-tables。
3). 使用myisamchk --keys-used=0 -rq /path/to/db/tbl_name。这将从表中取消所有索引的使用。
4). 用LOAD DATA INFILE把数据插入到表中,因为不更新任何索引,因此很快。
5). 如果只想在以后读取表,使用myisampack压缩它。参见15.1.3.3 节,“压缩表特性”。
6). 用myisamchk -r -q /path/to/db/tbl_name重新创建索引。这将在写入磁盘前在内存中创建索引树,并且它更快,因为避免了大量磁盘搜索。结果索引树也被完美地平衡。
7). 执行FLUSH TABLES语句或mysqladmin flush-tables命令。

6、锁定表可以加速用多个语句执行的INSERT操作:

* LOCK TABLES a WRITE;
* INSERT INTO a VALUES (1,23),(2,34),(4,33);
* INSERT INTO a VALUES (8,26),(6,29);
* UNLOCK TABLES;

这样性能会提高,因为索引缓存区仅在所有INSERT语句完成后刷新到磁盘上一次。一般有多少INSERT语句即有多少索引缓存区刷新。如果能用一个语句插入所有的行,就不需要锁定。

对于事务表,应使用BEGIN和COMMIT代替LOCK TABLES来加快插入。bitsCN.com

Statement of this Website
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

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1268
29
C# Tutorial
1243
24
VMware Horizon Client cannot be opened [Fix] VMware Horizon Client cannot be opened [Fix] Feb 19, 2024 pm 11:21 PM

VMware Horizon Client helps you access virtual desktops conveniently. However, sometimes the virtual desktop infrastructure may experience startup issues. This article discusses the solutions you can take when the VMware Horizon client fails to start successfully. Why won't my VMware Horizon client open? When configuring VDI, if the VMWareHorizon client is not open, an error may occur. Please confirm that your IT administrator has provided the correct URL and credentials. If everything is fine, follow the solutions mentioned in this guide to resolve the issue. Fix VMWareHorizon Client Not Opening If VMW is not opening on your Windows computer

VMware Horizon client freezes or stalls while connecting [Fix] VMware Horizon client freezes or stalls while connecting [Fix] Mar 03, 2024 am 09:37 AM

When connecting to a VDI using the VMWareHorizon client, we may encounter situations where the application freezes during authentication or the connection blocks. This article will explore this issue and provide ways to resolve this situation. When the VMWareHorizon client experiences freezing or connection issues, there are a few things you can do to resolve the issue. Fix VMWareHorizon client freezes or gets stuck while connecting If VMWareHorizon client freezes or fails to connect on Windows 11/10, do the below mentioned solutions: Check network connection Restart Horizon client Check Horizon server status Clear client cache Fix Ho

PHP MQTT Client Development Guide PHP MQTT Client Development Guide Mar 27, 2024 am 09:21 AM

MQTT (MessageQueuingTelemetryTransport) is a lightweight message transmission protocol commonly used for communication between IoT devices. PHP is a commonly used server-side programming language that can be used to develop MQTT clients. This article will introduce how to use PHP to develop an MQTT client and include the following content: Basic concepts of the MQTT protocol Selection and usage examples of the PHPMQTT client library: Using the PHPMQTT client to publish and

What is the mobile client What is the mobile client Aug 16, 2023 pm 01:40 PM

A mobile client refers to an application that runs on a smartphone and provides users with various functions and services in the form of a native client or a web client. Mobile clients can be divided into two forms: original clients and web clients. Native clients refer to applications written for specific operating systems using specific programming languages ​​and development tools. The advantage of web clients is that they have good cross-platform compatibility. , can run on different devices without operating system restrictions, but compared to the native client, the performance and user experience of the web client may be reduced.

How to solve the problem that the Baidu Netdisk webpage cannot start the client? How to solve the problem that the Baidu Netdisk webpage cannot start the client? Mar 13, 2024 pm 05:00 PM

When many friends download files, they will first browse on the web page and then transfer to the client to download. But sometimes users will encounter the problem that the Baidu Netdisk webpage cannot start the client. In response to this problem, the editor has prepared a solution for you to solve the problem that the Baidu Netdisk webpage cannot start the client. Friends in need can refer to it. Solution: 1. Maybe Baidu Netdisk is not the latest version. Manually open the Baidu Netdisk client, click the settings button in the upper right corner, and then click version upgrade. If there is no update, the following prompt will appear. If there is an update, please follow the prompts to update. 2. The detection service program of Baidu Cloud Disk may be disabled. It is possible that we manually or use security software to automatically disable the detection service program of Baidu Cloud Disk. Please check it out

How to write an FTP client in PHP How to write an FTP client in PHP Aug 01, 2023 pm 07:23 PM

How to write an FTP client in PHP 1. Introduction FTP (File Transfer Protocol) is a protocol used for file transfer on the network. In web development, we often need to upload or download files through FTP. As a popular server-side language, PHP provides powerful FTP functions, allowing us to easily write FTP clients. This article will introduce how to write a simple FTP client using PHP and provide code examples. 2. Connect to the FTP server in PHP, we can use f

How to remove the shield logo above the Win11 client? How to remove the shield logo above the Win11 client? Jan 05, 2024 am 11:21 AM

Some Win11 users have noticed that the shield logo appears next to some software icons on their personal computers. This protects computer systems and even the important information and data stored in them from infringement. If you don't like it, you can solve it by the following method. How to remove the shield logo on the win11 client 1. Right-click the taskbar on the computer and select "Task Manager" 2. Then click "Start" above 3. Find "Windows Defender" here and right-click and select "Disable", then Just restart the computer.

The national server is confirmed to return! The new version of Warcraft has a simplified and Chinese logo, and a new 'harmony patch' exclusive to the national server has been added The national server is confirmed to return! The new version of Warcraft has a simplified and Chinese logo, and a new 'harmony patch' exclusive to the national server has been added Apr 02, 2024 pm 12:43 PM

If the previous series of news has not convinced some players that the national server is about to return, then the latest news below can basically confirm that the national server is ready. Recently, the well-known boss sora007 discovered some very interesting contents when disassembling the new version of the patch pack of World of Warcraft: The first one is that a simplified Chinese LOGO of World of Warcraft appeared in the new version of the patch pack. Although players of the Chinese server are familiar with this LOGO, after the closure of the Chinese server, this LOGO did not appear in the new version of World of Warcraft. Recently, there have been more and more news about the return of the Chinese server. Blizzard has added this LOGO to the new version during this time. The purpose is very clear. The second is a patch package exclusive to the national server. sora007

See all articles