MySQL Note dot

Source: Internet
Author: User
Tags least privilege

MySQL optimization:

Each InnoDB table must have a primary key
Limit the number of indexes on a table and avoid establishing duplicate and redundant indexes
Careful selection of the order of compound index key values

Prioritize the smallest data types that meet storage needs
n in varchar (n) represents the number of characters, not the number of bytes
Use UTF8 to store Chinese characters varchar (255) = 765 bytes
Too much of the length will consume more memory
Avoid using TEXT,BLOB data types

Avoid using joins to correlate too many tables
One table per join consumes a portion of memory (join_buffer_size)
Generates temporary table operations that affect query efficiency
MySQL allows a maximum of 61 tables, with no more than 5 recommendations

Reduce the number of interactions with the database
Database is more suitable for batch operations
Combine multiple identical operations together to improve processing efficiency

Use in instead of or
In does not exceed 500 values
In operations can effectively use the index

Do not use ORDER by rand () to randomly sort
All eligible data is loaded into memory for sorting
Consumes a lot of CPU and IO and memory resources
It is recommended to get a random value in the program and then get the data from the database

function conversions and calculations for columns are prohibited in the WHERE clause
function conversions or calculations on columns can result in an unusable index

Use UNION ALL instead of union when there is clearly no duplicate value
Union will put all the data into the temporary table and then redo the operation
UNION all will no longer redo the result set
Super privilege can only be left to the DBA to handle the problem

For program connection database account, follow the principle of least privilege

Split complex large SQL into multiple small SQL
MySQL a SQL can only be calculated using one CPU
SQL split can improve processing efficiency by parallel execution

Batch write operations of more than 1 million lines, to be operated multiple times in batches
High-volume operations can cause severe master-slave delays
The Binlog log is a row format that generates a large number of logs
Avoid large transaction operations

Prohibit granting super privileges to accounts used by programs
Also allows 1 users with super privileges to connect when the maximum number of connections is reached

MySQL Note dot

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.