MySQL SQL语句优化的10条建议_MySQL
bitsCN.com
1.将经常要用到的字段(比如经常要用这些字段来排序,或者用来做搜索),则最好将这些字段设为索引。
2.字段的种类尽可能用int 或者tinyint类型。另外字段尽可能用NOT NULL。
3.当然无可避免某些字段会用到text ,varchar等字符类型,最好将text字段的单独出另外一个表出来(用主键关联好)
4.字段的类型,以及长度,是一个很考究开发者优化功力的一个方面。如果表数据有一定的量了,不妨用PROCEDURE ANALYSE()命令来取得字段的优化建议!(在phpmyadmin里可以在查看表时,点击 “Propose table structure” 来查看这些建议) 如此可以让你的表字段结构 趋向完善。
5.select * 尽量少用,你想要什么字段 就select 什么字段出来 不要老是用* 号!同理,只要一行数据时尽量使用 LIMIT 1
6.绝对不要轻易用order by rand() ,很可能会导致mysql的灾难!!
7.每个表都应该设置一个ID主键,最好的是一个INT型,并且设置上自动增加的AUTO_INCREMENT标志,这点其实应该作为设计表结构的第一件必然要做的事!!
8.拆分大的 DELETE 或 INSERT 语句。因为这两个操作是会锁表的,表一锁住了,别的操作都进不来了,就我来说 有时候我宁愿用for循环来一个个执行这些操作。
9.不要用永久链接 mysql_pconnect();除非你真的非常肯定你的程序不会发生意外,不然很可能也会导致你的mysql死掉。
10.永远别要用复杂的mysql语句来显示你的聪明。就我来说,看到一次关联了三,四个表的语句,只会让人觉得很不靠谱。bitsCN.com

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Please recommend which 1155-pin CPU is the best. The current 1155-pin CPU with the highest performance is Intel Corei7-3770K. It has 4 cores and 8 threads, a base frequency of 3.5GHz, and supports TurboBoost2.0 technology, which can reach up to 3.9GHz. In addition, it is equipped with 8MB of level 3 cache and is an excellent processor with the LGA1155 pin, the most powerful CPU Intel Core i73770K. The LGA1155 interface is the interface type used by second and third generation Core processors. The best performing one is Intel Core i73770K. The parameters of this processor are as follows: 1. Applicable type: desktop; 2. CPU series: Core i7; 3. CPU

Types and meanings of Linux file times In the Linux operating system, each file has three different types of timestamps, namely access time (atime), modification time (mtime) and change time (ctime). These three timestamps record file changes under different operations. Their meanings will be explained in detail below and corresponding code examples will be provided. Access time (atime): Access time refers to the last time the file was accessed. atime is updated when the file is read, run or browsed

Resources for any programming language include video lessons, notes, and e-books. Here I'll list the best resources for Python. Python official documentation Many websites provide Python resources, but the official documentation is the best. Let’s take a look at the resources they offer. Python Beginners Guide - https://wiki.python.org/moin/BeginnersGuide Python Developer Guide - https://devguide.python.org/Free Python Books − https://wiki.python.org/moin/PythonBooksPyth

With the rapid development of computer technology, graphics cards, as one of the important components of computers, play a pivotal role in games, graphic design and other fields. The graphics card interface is the bridge connecting the graphics card and the motherboard, affecting the performance and effect of the graphics card. So, which graphics card interface works best? Currently, there are three common graphics card interfaces on the market: PCI, AGP, and PCIe. Among them, the PCI interface is an early standard interface and is relatively outdated. For some old computers or simple office needs

When choosing a computer, most users now pay attention to the heat dissipation problem. Therefore, the current air-cooled radiators are very popular because they are affordable and cost-effective. However, most users do not quite understand which one is best. According to the current situation, The best is Valkyrie. Which air-cooled radiator is the best: A: According to the current ladder chart, the best one is Valkyrie’s “vk Star Ring GL360”. The performance of this water cooling is explosive, and the price is very good. For entry-level users, it will definitely not suffer. Related introduction of vk Starring GL360: 1. This water-cooled product looks very good, and the installation is relatively simple. It is also very convenient for novices to operate. 2. The fan is very simple overall. The logo also has a rotating circle, which is boring.

How to choose the best computer configuration With the continuous advancement of technology, computers have become an indispensable part of our lives. They not only meet our work needs, but also bring us entertainment and leisure. When choosing a computer, excellent configuration is very important. This article will introduce you to some important factors and tips when purchasing computer configurations. First, we need to consider our own needs. Different people use computers for different purposes. Some people mainly use them for daily office work and Internet browsing, while others may need high-performance games or professional

The win10 system is a highly user-friendly system that allows users to make settings changes according to their needs. Today, the editor brings you a tutorial on the best settings for win10 resolution! Friends in need, please come and take a look. , Win10 resolution best setting tutorial: Answer: It is best to follow the system recommendation. Everyone's system will give you a recommended resolution, and this value is generally the best. The best setting method for win10 resolution: 1. First click on the lower left corner to start, and then enter settings. 2. Then click System. 3. Click the drop-down menu under the resolution option on the right side of the screen options. You can see the recommended resolution and just set it.

Which website is the best to download win10? Nowadays, many friends like to download and install or reinstall the system online. This requires an excellent download platform. So which website is good for downloading the win10 system? Many friends don’t know how to operate in detail. The editor has compiled the download websites for the win10 system below. Good introduction, if you are interested, follow the editor to read below! A good introduction to win10 system download website Answer: System 520 is the best. The systems here are safe and reliable, and the installation method is also very simple, suitable for all users. 1. The system here has several benefits. 2. First of all, ensure safety and reliability. All systems can be installed normally without errors. 3. Secondly, the installation operation is very simple, and the system is installed with one click.
