Mysql video tutorial column introduces the development specifications of MySQL
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
TypeByteMinimum valueMaximum value##tinyint ## smallint1 -128 127 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>
Index taboo
<p>1.不在低基数列上建立索引、例如性别<br>2.不在索引列记性数学运算和函数运算<br></p>
Try not to use foreign keys
<p>1.外键用来保护参照完整性,可以业务端实现<br>2.对父表和字表的操作会互相影响,降低可用性<br></p>
Index naming
<p>1.非唯一索引必须以 inx_字段1_字段22.唯一索引必须以 uniq_字段1_字段2<br></p>
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!

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

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.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools

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),

SublimeText3 Linux new version
SublimeText3 Linux latest version
