Software testing essential knowledge database

Whether it is operation and maintenance, development, testing, or architect, database technology is a must-pay artifact, it has been said that learning database, learn MySQL, in the end it is to learn what things? (Source: Thousand Feng software testing)

1, how to quickly master the MySQL?

Cultivate an interest

Interest is the best teacher, no matter what to learn knowledge, interest can greatly improve learning efficiency. Of course, learning MySQL is no exception.

 

Solid foundation

Great emphasis on the field of computer technology foundation, just learning may not realize this, along with in-depth technical applications, only has a solid foundation of knowledge, in order to go faster and farther on the road technology. For MySQL for learning, SQL statement is one of the most basic part, many of the operations are achieved through the SQL statement. So in the process of learning, readers should be more to write SQL statements, for the same function, using different implementations statement to complete, thus a deep understanding of their differences.

 

In time to learn new knowledge

Correct and effective use of search engines, you can search a lot of knowledge on MySQL. Meanwhile, referring to other people's ideas to solve the problem, we can also learn from the experience of others, timely access to the latest technical information.

 

More practice operation

Database system is highly operational, require more hands-on. The problem can be found in the actual operation, and ways of thinking and problem-solving ideas, the only way to improve the operational capacity of actual combat.

 

2, how to choose the type of server?

MySQL server configuration window of each parameter in the following meaning.

Server Configuration Type [] This option is used to set the type of server. Click the Options button to the right down, you can see include three options.

 

Specific meaning three options are as follows:

Development Machine (development machine): This option represents the typical personal desktop workstations. Running multiple applications on a desktop machine is assumed. The MySQL server is configured to use a minimum of system resources.

 

Server Machine (server): This option represents the server, MySQL server can be run in conjunction with other applications, such as FTP, email and web servers. MySQL server is configured to use an appropriate proportion of system resources.

 

DedicatedMySQL Server Machine (dedicated MySQL server): This option represents the only server running MySQL services. Assuming that runs without running other applications. MySQL server is configured to use all available system resources.

 

3, how to choose the storage engine

Different storage engines have their own characteristics, to suit different needs, as shown in the following table. In order to make a choice:

 

We first need to consider each different storage engine which provides the functionality. If you want to provide commit, rollback, and crash recovery capabilities of transaction-safe (ACID compliant) capabilities, and requirements to achieve concurrency control, InnoDB is a good choice. If the data table is mainly used to insert and query records, the MyISAM engine offers high efficiency; if only temporarily stored data, the amount of data, and does not require high data security, you can choose the data stored in the memory the Memory engine, MySQL use the engine as a temporary table to store intermediate results of the query. If only INSERT and SELECT operations, you can choose Archive engine, Archive storage engine to support high concurrent insert operation, but the transaction itself is not safe. Archive storage engine is adapted to store archival data, logging information may be used as Archive Engine.

 

Which engine using selected according to need to be flexible, a plurality of database tables may be used in different engines to meet various performance requirements and practical.

 

Use appropriate storage engine, it will improve the performance of the entire database.

 

4, how to view the default storage engine?                                

Use SHOW ENGINES statement to view the system in all storage engines, including the default storage engine. Can see the current database system has five storage engine, the default is MyISAM. You can also use a direct way to see the default storage engine. The results show a direct current default storage engine is MyISAM.

 

5, delete the table to be cautious

Table delete operation definition table will be deleted and the data tables together, and MySQL during a delete operation, without any confirmation prompt message, and therefore while the delete operation should be carefully. Before deleting the table, it is best to back up the data in the table, so that when operational errors, data can be restored in order to avoid irreversible consequences. Similarly, when using ALTER TABLE to modify the basic operating table, before you perform the procedures should also ensure a complete backup of the data, because changes to the database can not be revoked, if an unwanted field is added, you can delete it; the same, if you delete a column required, all data following the column will be lost.

 

6, each table must have a primary key it?

Not every table must have a primary key, in general, if the connecting operation between a plurality of tables, the need to use the primary key. And therefore it does not need to create a primary key for each table, and in some cases preferred not to use a primary key.

 

7, each table can choose the storage engine?

Foreign key constraints (FOREIGN KEY) can not be cross-engine use. MySQL supports multiple storage engine, each table can specify a different storage engines, but be warned: the foreign key constraint is used to ensure referential integrity of the data, if necessary correlation between foreign key table, but specify a different storage engine, between these tables can not create a foreign key constraint. So, choose the storage engine is not completely arbitrary.

 

8, with AUTO_INCREMENT field value is constrained from the beginning of it?

By default, in MySQL, AUTO_INCREMENT initial value is 1, each of the new record, the field value incremented by one. Set the self-energizing properties (the AUTO_INCREMENT) when inserted record can also specify the value of the self-energizing field of a first article, such self-energizing field value newly inserted record increments from the initial value, as in the first record is inserted in tb_emp8 , specify the id value 5, the value id after the inserted recording will increase from 6 starts up. When adding a unique primary key constraint, often you need to set the attribute field is automatically increased.

 

9, with the difference between the two TIMESTAMP DATATIME

TIMESTAMP and DATETIME addition to the different byte storage and support range, there is a maximum difference is: DATETIME, date data storage, according to the actual storage format of the input, i.e., what is stored on what input, regardless of the time zone; TIMESTAMP value and storage is UTC (Coordinated Universal time) to save the format to the current time zone conversion storage, and converted back to the current time zone upon retrieval. That is, when a query, depending on the current time zone, the time value displayed is different.

 

10, select what type of data the methods and skills are?

MySQL provides a number of data types, in order to optimize storage, improve database performance, should use the most precise type in all cases. I.e. all the column may indicate the type of value, stores the minimum type of use.

 

Integer and floating-point numbers

If no fractional part, is used to store the integer data; if necessary represent the fractional part, the use of floating point type. For floating point data column, the value will be stored in the column definition decimal rounding. For example, if the range of values ​​of the column is 199 999, the use of an integer, it is the best type MEDIUMINT UNSIGNED;? Decimals if necessary to store, use the FLOAT type. FLOAT and DOUBLE types, including floating-point type. DOUBLE FLOAT type than the type of high precision, therefore, when stored as high precision required, should be selected DOUBLE type.

 

Floating-point and fixed-point

Float FLOAT, DOUBLE DECIMAL fixed point with respect to the advantages: the length in certain circumstances, floating point data can represent a larger range. However, because floating-point error prone, thus when a relatively high accuracy requirements, it is recommended to store DECIMAL. DECIMAL string is stored in MySQL, used to define the currency for higher accuracy data requirements. In the data migration, float (M, D) is the definition of a non-standard SQL, database migration may be a problem, so it is best not to use. When the two floating-point subtraction and a comparison operation are also vulnerable, so when performing the calculation, must be careful. If the comparison value, DECIMAL type is preferably used.

 

Date and Time Types

MySQL has many data types for different kinds of dates and times, such as YEAR and TIME. If you only need to record year, YEAR type it can use; if only recording time, simply use the TIME type. If both need to record the date and time, or can be used TIMESTAMP DATETIME type. Since the range is less than the range TIMESTAMP DATETIME column, thus storing a large range DATETIME The date is preferably used. TIMESTAMP DATETIME also does not have a property. By default, when inserting a record but did not specify the value of TIMESTAMP this column, MySQL will TIMESTAMP column to the current time. Therefore, when the need to insert inserted simultaneously recording the current time, it is convenient to use TIMESTAMP, TIMESTAMP further more effective in space than DATETIME.

 

Features and choose between CHAR and VARCHAR

CHAR and VARCHAR difference:

Is the fixed length character CHAR, VARCHAR is a variable length character; CHAR trailing spaces will automatically delete the inserted data, VARCHAR trailing spaces are not deleted.

 

CHAR is a fixed length, so that its processing speed is faster than VARCHAR, but its drawback is a waste of storage space. Therefore, little storage, but the speed requirements may be used in the type of CHAR, VARCHAR type may be used and vice versa is achieved.

 

Storage Engine selection for CHAR and VARCHAR effects:

For MyISAM storage engine: a fixed length data is preferably used instead of a column of variable length data sequence. This allows the entire table static, so that faster data retrieval, a space for time.

 

For InnoDB storage engine: using variable-length data string, because InnoDB table storage format regardless of the fixed length and variable length, the use is not necessarily better than VARCHAR CHAR, VARCHAR but the actual length is stored, more to save space, so the disk I / O and the amount of data stored better.

 

ENUM and SET

ENUM can only take a single value, which is an enumerated list of data collection. Its legal value list allows up to 65 535 members. Thus, the need to select from a plurality of values ​​can be used when ENUM. For example: for gender field defined as ENUM type, you can only take one value from a 'male' or 'female' in. Preferably the multi-value SET. It's a legitimate list of supported maximum of 64 members. An empty string is a valid SET value. When you need to take multiple values ​​for the use of SET type, such as: To store a person of interest, best to use SET type. ENUM and SET value is based on the form of a string, but internally, MySQL store them as a numerical value.

 

BLOB and TEXT

A BLOB is a binary string, TEXT non-binary string, both of which can store large volumes of information. BLOB main store pictures, audio and other information, and TEXT can only store plain text files. The use should distinguish between the two.

Guess you like

Origin blog.csdn.net/IT_studied/article/details/90578451