Home Database Mysql Tutorial 总结MYSQL的优化_MySQL

总结MYSQL的优化_MySQL

Jun 01, 2016 pm 02:00 PM
Database Design

碰到过好几次这样的题目,可每次都不能答的完全正确.
现在大概列出如下:(忘各位补充)
1.数据库的设计
尽量把数据库设计的更小的占磁盘空间.
1).尽可能使用更小的整数类型.(mediumint就比int更合适).
2).尽可能的定义字段为not null,除非这个字段需要null.
3).如果没有用到变长字段的话比如varchar,那就采用固定大小的纪录格式比如char.
4).表的主索引应该尽可能的短.这样的话每条纪录都有名字标志且更高效.
5).只创建确实需要的索引。索引有利于检索记录,但是不利于快速保存记录。如果总是要在表的组合字段上做搜索,那么就在这些字段上创建索引。索引的第一部分必须是最常使用的字段.如果总是需要用到很多字段,首先就应该多复制这些字段,使索引更好的压缩。
6).所有数据都得在保存到数据库前进行处理。
7).所有字段都得有默认值。
8).在某些情况下,把一个频繁扫描的表分成两个速度会快好多。在对动态格式表扫描以取得相关记录时,它可能使用更小的静态格式表的情况下更是如此。
2.系统的用途
1).尽量使用长连接.
2).explain 复杂的SQL语句。
3).如果两个关联表要做比较话,做比较的字段必须类型和长度都一致.
4).LIMIT语句尽量要跟order by或者 distinct.这样可以避免做一次full table scan.
5).如果想要清空表的所有纪录,建议用truncate table tablename而不是delete from tablename.
6).能使用STORE PROCEDURE 或者 USER FUNCTION的时候.
7).在一条insert语句中采用多重纪录插入格式.而且使用load data infile来导入大量数据,这比单纯的indert快好多.
8).经常OPTIMIZE TABLE 来整理碎片.
9).还有就是date 类型的数据如果频繁要做比较的话尽量保存在unsigned int 类型比较快。
3.系统的瓶颈
1).磁盘搜索.
并行搜索,把数据分开存放到多个磁盘中,这样能加快搜索时间.
2).磁盘读写(IO)
可以从多个媒介中并行的读取数据。
3).CPU周期
数据存放在主内存中.这样就得增加CPU的个数来处理这些数据。
4).内存带宽
当CPU要将更多的数据存放到CPU的缓存中来的话,内存的带宽就成了瓶颈.

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

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 ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

Redundant Field Issues in Database Design: Best Practices in PHP Programming Redundant Field Issues in Database Design: Best Practices in PHP Programming Jun 22, 2023 am 11:02 AM

With the popularity of the Internet and the increasing number of application scenarios, database design has become an extremely important issue. In database design, redundant fields are a very important issue. Redundant fields refer to duplicate or unnecessary fields that appear when designing the database. Although redundant fields can improve query efficiency and speed to a certain extent, they also waste storage space, increase maintenance difficulty, and even affect data consistency and security. Therefore, in PHP programming, certain best practices should be followed to solve the problems caused by redundant fields.

Research on solutions to database design problems encountered in development using MongoDB technology Research on solutions to database design problems encountered in development using MongoDB technology Oct 08, 2023 pm 05:53 PM

Exploring solutions to database design problems encountered in the development of MongoDB technology Abstract: With the rapid development of big data and cloud computing, database design is particularly important in software development. This article will discuss common database design issues encountered during development and introduce MongoDB solutions through specific code examples. Introduction: In the software development process, database design is a key link. Traditional relational databases have some performance and scalability issues when processing large-scale data. And MongoD

Golang learning database design practice for web applications Golang learning database design practice for web applications Jun 24, 2023 am 10:33 AM

Golang is a programming language developed by Google. Its simplicity of use, superior performance, and cross-platform features make it increasingly popular in modern web application development. In web application development, database design is a very important part. In this article, we will introduce how to practice database design when developing web applications using Golang. Choosing a database First, we need to choose a suitable database. Golang supports a variety of databases, such as MySQL, Po

Design and application of PHP and MySQL databases Design and application of PHP and MySQL databases Jun 20, 2023 am 09:27 AM

PHP and MySQL are a powerful pair with a wide range of applications. In the Internet industry, PHP and MySQL have become the standard configuration of the technology stack, and a large number of websites, web applications, backend management systems and other applications have adopted this combination. This article will explore the design and application of PHP and MySQL databases and introduce some best practices. 1. Advantages of PHP and MySQL database PHP is an open source, cross-platform, server-side Web programming language with a wide range of application scenarios. MySQL is a

How to implement database design for multi-specification SKU of products in PHP How to implement database design for multi-specification SKU of products in PHP Sep 06, 2023 am 09:03 AM

How to implement database design for product multi-specification SKU in PHP In e-commerce platforms, product specifications are a very important concept. Product specifications can be understood as the different attributes and characteristics of the product, such as size, color, weight, etc. In practical applications, for different specifications, we often need to set different prices, inventory, pictures and other information for each combination. This requires us to design a suitable database structure to store and manage product specifications and related information. This article will introduce how to implement multi-specification SKU of products in PHP

Detailed explanation of the application of MySQL composite primary key in database design Detailed explanation of the application of MySQL composite primary key in database design Mar 15, 2024 am 11:33 AM

Detailed explanation of the application of MySQL composite primary key in database design MySQL composite primary key refers to a primary key composed of multiple fields. A record is uniquely identified by combining the values ​​of these fields. In database design, composite primary keys are widely used, especially when an entity needs to be uniquely identified. This article will introduce in detail the concept, design principles and specific code examples of MySQL composite primary keys. 1. The concept of MySQL composite primary key. In MySQL, the primary key is a field used to uniquely identify each row of data in the table.

What are the main steps in database design? What are the main steps in database design? Dec 29, 2020 pm 04:13 PM

Steps: 1. Collect and analyze requirements to obtain a data dictionary and data flow diagram; 2. Synthesize, summarize and abstract user requirements to form a conceptual model; 3. Convert the conceptual structure into a data model; 4. Design the physical structure of the database; 5. Establish a database, compile and debug applications, and organize data into the database; 6. Evaluate, adjust and modify the database system.

MySQL database design: ordering system menu table MySQL database design: ordering system menu table Nov 01, 2023 pm 12:40 PM

MySQL database design: ordering system menu list Introduction: In the catering industry, the design and implementation of the ordering system is crucial. One of the core data tables is the menu table. This article will introduce in detail how to design and create an effective menu table to support the functions of the ordering system. 1. Requirements analysis Before designing the menu list, we need to clarify the requirements and functions of the system. In the ordering system, the menu table needs to store relevant information about each dish, including dish name, price, classification, description, etc. In addition, you also need to consider the dishes

See all articles