Efficient MySQL database compilation

Source: Internet
Author: User
The following articles mainly introduce the correct solution for compiling efficient MySQL databases. We first use practical application tools such as Apach, Perl, PHP, and Python, to build a MySQL (the best combination with PHP), it is easy to use. However, ensuring that they run fast requires a little insight. This article is what you need to know.

The following articles mainly introduce the correct solution for compiling efficient MySQL databases. We first use practical application tools such as Apach, Perl, PHP, and Python, to build a MySQL (the best combination with PHP), it is easy to use. However, ensuring that they run fast requires a little insight. This article is what you need to know.

The following articles mainly introduce the correct solution for compiling efficient MySQL databases. We first use practical application tools such as Apach, Perl, PHP, and Python, to build a MySQL (the best combination with PHP), it is easy to use.

However, ensuring that they run fast requires a little insight. This article is what you need to know.

MySQL (the best combination with PHP) has a well-deserved reputation for becoming a very fast MySQL database server, which is also very easy to set and use. As its reputation grows as the backend database of the website, its effect has improved significantly since last year. However, many MySQL users (the best combination with PHP) know more about how to create a database and write queries to it. Just like thousands of people are learning Unix through Linux experiment when they are busy, many learn relational databases by playing MySQL (the best combination with PHP. Most of these new users of MySQL (the best combination with PHP) have no background in the MySQL database theory and have no time to read the full text of the MySQL (the best combination with PHP) manual.

Therefore, we decided to study some methods. You can adjust MySQL (the best combination of PHP and MySQL) with optimized performance ). After reading this article, you will understand some technologies that help you design your MySQL (the best combination with PHP) database and query. It is worth your use very efficiently. We will assume that you are familiar with MySQL (the best combination with PHP) and SQL basics, but not that you have extensive knowledge of these two aspects.

Only store the information you need

This sounds like common sense, but people often adopt "Kitchen sewers" for database design. They believe that everything may need to be stored and designed to store the data of the owner. You need to be realistic about your needs and determine what information you really need. You can usually generate some data without storing it in a MySQL database table. In this case, it makes sense to do so from the perspective of an application developer.

For example, the product table in the online catalog may contain the names, descriptions, sizes, weights, and prices of various products. In addition to the price, you may want to store tax and transportation costs related to each project. But you don't actually need. First, tax and transportation costs can be easily calculated by your application or MySQL (the best combination with PHP. Second, if the tax and transportation costs change, you may have to write the necessary query to update the tax and transportation rates in each product record.

Sometimes people think this is too difficult to add fields to MySQL database tables in the future, so they feel they have to define as many columns as possible. This is an obvious conceptual error. In MySQL (the best combination with PHP), you can use the alter table command to easily modify the TABLE definition to meet your changing needs.

For example, if you suddenly realize that you need to add a level column to your product table (You may want to allow users to rate the product in your directory), you can do this:

 
 
  1. ALTER TABLE products ADD rank INTEGER

This adds an integer-type level column to your product TABLE. For a complete description of what you can use alter table, see the MySQL (best combination with PHP) manual.

Only what you need-be clear

Like saying "only store what you need", this may seem to be common sense, but this is often ignored. Why? Because the demand for an application often changes during development, many queries eventually look like this:

 
 
  1. SELECT * FROM sometable

When you are not sure which column you will need, it is obviously the most effort-saving to require all columns. However, as your table continues to grow and change, this may become a performance problem. It is best to spend some time after your initial development and determine what you actually need from your queries:

 
 
  1. SELECT name, rank, description FROM products

This brings about a related point of view, that is, code maintenance is more important than performance. Most languages (Perl, Python, PHP, Java, etc.) allow access to a query result by field names and numbers, this means that you can access the named field or field 0 to get the same data.

For a long time, it is best to use the column name instead of its serial number location. Why? The relative position of columns in a table or query can be changed. They may change in the TABLE due to repeated use of alter table. They will change in the query because they overwrite the query and forget to update the application logic for matching.

Of course, you still need to be careful to change the column name! However, if you use a column name rather than a non-standard position, such as a column name change, you can use grep to search the source code or use the search capability of the editor to find the code you need to modify.

The above content is an introduction to teaching you how to write efficient MySQL database applications.

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.