10 suggestions for MySQL SQL statement optimization _mysql

Source: Internet
Author: User
1. The fields that will be used frequently (such as frequently using these fields for sorting, or for searching), are best indexed.
2. The type of field can be as int or tinyint as possible. The other field uses not NULL as much as possible.
3. Of course, there are certain fields will be used to text, varchar and other character types, it is best to separate the text field out of another table (with the primary Key Association good)
4. The type of field, as well as the length, is a very elegant aspect of developer optimization. If the table data has a certain amount, may wish to use the procedure analyse () command to obtain the field optimization suggestion! (In phpMyAdmin You can view these suggestions by clicking "Propose table Structure" when viewing the table) so you can make your table-block structure more complete.
5.select * as little as possible, what fields do you want to select what fields to come out do not always use the * number! By the same token, use LIMIT 1 as long as one row of data
6. Never easily use ORDER by rand (), which is likely to lead to a MySQL disaster!!
7. Each table should be set an ID primary key, the best is an int type, and set on the automatic increase of the auto_increment flag, this should in fact be the first design table structure must do!!
8. Split a large DELETE or INSERT statement. Because these two operations will lock the table, the table is locked, the other operations are not in, as far as I am concerned, sometimes I would rather use a for loop to perform these operations.
9. Do not use permanent link mysql_pconnect (); Unless you are really sure that your program will not be an accident, it is likely to cause your MySQL to die.
10. Never use a complex MySQL statement to show your cleverness. As far as I'm concerned, seeing a three-and four-table statement at a time can only make people feel very unreliable.
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.