Let me talk about the most practical "military regulations" on MYSQL. I hope everyone can remember to abide by
1. Core military regulations
- Do not perform calculations in the database: CPU calculations must be moved to the business layer
- Control the amount of data in a single table: the records in a single table are controlled at 1000w
- Control the number of columns: fields The number is controlled within 20
- Balance paradigm and redundancy: Sacrifice paradigm design and redundant data to improve efficiency
- Reject 3B: Reject large SQL, large things, large batches
2. Field Class Military Rules
’ s ’ s ’ s ‐ ‐ ‑Use well numeric types
int (4byte)
Bigint (8byte)
Bad Case: int (1)/int (11)
## -Character convert to numbers
Use int instead of char (15) storage IP
. Invalid
less - The performance of varchar will be much higher than text
If blob is unavoidable, please split the table - Do not store
pictures in the database
3. Index Military Rules
- Use indexes carefully and rationally
Improve queries and slow down
updates
The more indexes, the better Good (if you can’t add it, don’t add it. If you want to add it, you must add it) There are too many covered records that are not suitable for building an index, such as "Gender"
- Character fields must be built with prefix index-to do not do columns for index
Bad Case:
SELECT Id WHERE AGE 1 = 10; ## -InNodb Primary Recommended Main Books Main Key Create Cluster Index
using using using using ‐ . . #Upload picture transaction
-avoid using Trig/Func
# trigger
client program to replace
The above is the MySQL "military rules" I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
The above is the detailed content of MySQL 'military regulations'. For more information, please follow other related articles on the PHP Chinese website!