Home Database Mysql Tutorial Record MySQL development specifications

Record MySQL development specifications

Dec 21, 2020 am 09:56 AM
mysql

Mysql video tutorial column introduces the development specifications of MySQL

Record MySQL development specifications

Recommended (free): mysql video tutorial

##Basic specifications

  • Use innodb storage engine

  • Table character set uses utf-8

  • Add comments to all tables

  • It is recommended that the data volume of a single table be controlled within 5000W

  • No longer store big data such as graphs and files in the database

  • It is prohibited to create a database online Stress test

  • Prohibit test and development environments from directly connecting to the database

Naming convention

  • Library name, table name, field name must have a fixed naming length, within 12 characters

  • Library name, table name, field name cannot exceed 32 characters character. You must see the meaning of the name

  • It is forbidden to use MySQL reserved words in library names, table names, and field names

  • Temporary library and table names must start with tmp As the prefix, and use the date as the suffix

  • The backup library and table must be prefixed with bak, and use the date as the suffix

Development and design specifications for libraries, tables, and fields

  • It is prohibited to use partitioned tables

  • Split large fields and Turn over fields with low consulting frequency and separate hot and cold data

  • Use HASH to enter the scattered table, the suffix of the table name is a base number, and the subscript starts from 0

  • Table sharding by date and time must comply with the

    YYYY[MM][DD][HH] format

  • Use a suitable sharding strategy. For example, thousands of databases with ten tables, ten databases with hundreds of tables, etc.

  • Do not use text and blob types as much as possible

  • Use decimal instead of float and double storage Exact floating point numbers

  • The simpler the better: convert characters to numbers, use tinyint instead of enum type

  • All fields are not null

  • Use unsigned to store non-negative numbers

  • int type fixedly occupies 4 bytes of storage

  • Use timestamp storage time

  • Use int unsigned to store ipv4

  • Use varbinary to store case-sensitive variable-length strings

  • It is forbidden to store plain text passwords in the database, and the passwords must be encrypted and stored

  • Use numeric type fields well


    Type

    Byte

    Minimum value

    Maximum value

    ##tinyint1-128127## smallintmediumint




    2

    -32768

    32767

    3

    ##-8388608

    ##8388607

    int
    4

    -2147483648

    2147483647

    bigint
    8

    -9223372036854775808

    9223372036854775807

    If the numerical field is not that big, don’t use bigint

  • It is best to use int to store IP instead of char(15)

  • The use of enum is not allowed

  • Avoid using null fields

    Null fields are difficult to query, and the index of null fields requires additional Space, composite index on null field is invalid.

  • Index specifications

    • The number of indexes in a single table shall not exceed 5

    • The number of fields in a single index does not exceed 5

    • Use prefix index for strings, and the length of the prefix index does not exceed 8 characters

    • It is recommended to give priority to prefix indexes. If necessary, you can add pseudo columns and create indexes

    • The table must have a primary key

    • Do not use frequently updated columns as primary keys

    • Try not to select string columns as primary keys

    • Do not use uuid md5 hash these As the primary key - too discrete

    • The default is to use the non-null unique key as the primary key

    • It is recommended to choose auto-increment or numberer

    • Important SQL must be indexed, such as where condition columns of update and delete statements, order by, group by, distinct fields

    • Multiple table join Pay attention to the fields

    <p>1.区分度最大的字段放在前面<br>2.核SQL优先考虑覆盖索引<br>3.避免冗余和重复索引<br>4.索引要综合评估数据密度和分布以及考虑查询和更新比例<br></p>
    Copy after login
    • Index taboo

    <p>1.不在低基数列上建立索引、例如性别<br>2.不在索引列记性数学运算和函数运算<br></p>
    Copy after login
    • Try not to use foreign keys

    <p>1.外键用来保护参照完整性,可以业务端实现<br>2.对父表和字表的操作会互相影响,降低可用性<br></p>
    Copy after login
    • Index naming

    <p>1.非唯一索引必须以 inx_字段1_字段22.唯一索引必须以 uniq_字段1_字段2<br></p>
    Copy after login
    • The default value of the index field cannot be empty. Null greatly affects the query efficiency of the index.

    • Repeatedly check the SQL related to the table and build an index based on the characteristics of the leftmost prefix. For indexes with multiple fields that are repeated, it is necessary to modify the order of the statement condition fields and create a joint index for them to reduce the number of indexes.

    • If you can use a unique index, use a unique index

    • R&D should often use explain. If they find that the index selectivity is poor, they must learn to use hints .

    SQL specification

    • ##SQL statements are as simple as possible

    • Things should be simple, and the entire thing should not take too long.

    • Avoid using triggers, functions, and stored procedures

    • Reduce business coupling and leave room for sacle out and sharding

    • Avoid mathematical operations in the database, MySQL is not good at mathematical operations and logical judgment

    • Don’t use selecy *, just select those fields when querying those fields

    • If you use or in sql, rewrite it as in. The efficiency of or is not as high as that of in

    • The number of numbers in in is recommended to be within 1000

    • limit paging and pay attention to efficiency. The larger the limit, the lower the efficiency.

    • Use union all instead of union

    • Avoid joining large tables

    • Use group bu grouping , automatic sorting

    • Updates to data should be broken up and updated in batches, do not update too much data at one time

    • Reduce the number of interactions with the database

    • Pay attention to the use of performance analysis tools

    • SQL statements require all R&D, SQL keywords are all capitalized, and only one space is allowed per word

    • SQL statements cannot have implicit conversions

    • If you don’t need not in, don’t use it

    • Forbidden to use The prefix is ​​% like

    • Do not use negative queries, such as not in, not like

    • It is forbidden to run large queries in the database

    • Make precompiled statements and only pass parameters, which is more efficient than passing SQL statements. Reduce SQL injection.

    • Disable order by rand

    • Prohibit a single SQL statement from updating multiple tables at the same time

    Process specification

    • All table creation operations need to inform the query SQL involved in the table in advance

    • All table creation needs to determine which indexes are created before the table can be built online

    • All table structure modification and index adding operations require the query SQL involving the table to be issued. Notify the DBA and other relevant personnel

    • Before adding fields to the new table, the R&D team is required to send out an email at least 3 days in advance for evaluation, optimization and review by the DBA department

    • Batch import and export data must be notified to the DBA in advance to assist in observation

    • It is prohibited to perform back-end management and statistical queries from the online database

    • Prohibit the existence of application accounts with super permissions

    • No more batch updates and database queries during peak business periods

The above is the detailed content of Record MySQL development specifications. For more information, please follow other related articles on the PHP Chinese website!

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)

MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

How to install mysql in centos7 How to install mysql in centos7 Apr 14, 2025 pm 08:30 PM

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

Centos install mysql Centos install mysql Apr 14, 2025 pm 08:09 PM

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.

See all articles