Guidance:The use of the MySQL database engine can improve the efficiency of work, so the MySQL database engine is favored by many large and small enterprises. If you want to learn the quick guidance of the MySQL database engine, continue to read it below, I believe it will not disappoint you.
How do you feel if you are a racing driver and you can immediately change the engine without driving the car to the garage to change the size capsule? What MySQL database does for developers is like changing the engine by pressing a button. It lets you select a database engine and gives you a simple way to switch between it.
MySQL's built-in engine must be enough, but in some cases, other engines may be more suitable for completing tasks than they are used at hand. If you want to, you can even use MySQL ++ API to create your own database engine, just like hitting the cylinder and installing your own carburetor. Now let's take a look at how you choose an engine and how to switch between available engines.
Select your engine
The database engine you can use depends on how MySQL is compiled during installation. To add a new engine, you must recompile MySQL. The concept of compiling an application just to add a feature may be strange for Windows developers, but it has become a standard in the UNIX world. By default, MySQL supports three engines: ISAM, MyISAM, and HEAP. The other two types of InnoDB and Berkley (BDB) are also frequently used.
ISAM is a well-defined and time-tested data table management method. It is designed to take into account that the number of database queries is much larger than the number of updates. Therefore, ISAM performs read operations quickly without occupying a large amount of memory and storage resources. The two major disadvantages of ISAM are that it does not support transaction processing or fault tolerance: If your hard disk crashes, data files cannot be recovered. If you are using ISAM in a key task application, you must always back up all your real-time data. With its copy feature, MySQL can support such backup applications.
MyISAM is the MySQL ISAM extension format and default database engine. In addition to providing a large number of functions for indexing and field management not available in ISAM, MyISAM also uses a table lock mechanism to optimize multiple concurrent read/write operations. The cost is that you need to run the OPTIMIZETABLE command frequently to restore the space occupied by the update mechanism. MyISAM also has some useful extensions, such as the MyISAMChk tool used to fix database files and the MyISAMPack tool used to restore wasted space.
MyISAM emphasizes fast read operations, which may be the main reason why MySQL is so favored by Web development: In Web development, a large number of data operations you perform are read operations. Therefore, most VM providers and Internet platform providers (InternetPresenceProvider, IPP) are only allowed to use the MyISAM format.
HEAP allows only temporary tables in memory. HEAP is faster than ISAM and MyISAM in the memory, but the data it manages is unstable. If it is not saved before shutdown, all the data will be lost. When a row is deleted, HEAP does not waste much space. HEAP tables are useful when you need to use SELECT expressions to SELECT and manipulate data. Remember to delete the table after the table is used up. Let me repeat it again: do not forget to delete the table after you have used up the table.
InnoDB and BerkleyDB
The InnoDB and BerkleyDB (BDrolexB) database engines are both direct products that make MySQL flexible. This technology is MySQL ++ API. When using MySQL, almost every challenge you face comes from the fact that the ISAM and MyISAM database engines do not support transaction processing or foreign keys. Although it is much slower than ISAM and MyISAM engines, InnoDB and BDB include support for transaction processing and Foreign keys, both of which are not available in the first two engines. As mentioned above, if your design requires one or both of these features, you will be forced to use one of the two engines.
If you feel that you are indeed highly skilled, you can also use MySQL ++ to create your own database engine. This API provides you with the functions of operation fields, records, tables, databases, connections, and security accounts, as well as all the other numerous functions required to create DBMS such as MySQL. An in-depth explanation of the API is beyond the scope of this article, but you need to understand the existence of MySQL ++ and the technology behind the interchangeable engine. This is very important. It is estimated that the plug-in database engine model can even be used to create a local XML provider for MySQL ). (Any MySQL ++ developer reading this article may regard this as a requirement .)
What makes all the flexibility possible is the MySQL extension provided to ANSISQL ?? TYPE parameter. MySQL allows you to specify the database engine at the table layer, so they sometimes refer to tableformats. The following sample code shows how to create tables using the MyISAM, ISAM, and HEAP engines. Note that the code for creating each table is the same except for the final TYPE parameter, which is used to specify the Data Engine.
PRIMARYKEY (id ),
) TYPE = MyISAM
PRIMARYKEY (id ),
) TYPE = ISAM
PRIMARYKEY (id ),
) TYPE = Heap
You can also use the ALTERTABLE command to move the original table from one engine to another. The following code shows how to use ALTERTABLE to move a MyISAM table to the InnoDB engine:
ALTERTABLEtblMyISAMCHANGETYPE = InnoDB
MySQL uses three steps to achieve this goal. First, a copy of the table is created. Then, any changes to input data are queued, and the copy is moved to another engine. Finally, any changes made to data in the queue are sent to a new table, and the original table is deleted.
Step 1: ALTERTABLE shortcuts
To update a table from ISAM to MyISAM, you can use the mysql_convert_table_format command without having to write an ALTERTABLE expression.
You can use the SHOWTABLE command (another extension of MySQL to the ANSI standard) to determine which engine is managing specific tables. SHOWTABLE returns a result set with multiple data columns. You can use this result set to query all types of information: the database engine name is in the Type field. The following sample code illustrates the usage of SHOWTABLE:
Step 3,SHOWTABLE replacement method
You can use SHOWCREATETABLE [TableName] to retrieve information that can be retrieved by SHOWTABLE.
Finally, if you want to use an engine that is neither compiled into MySQL nor activated, it is useless. MySQL will not prompt this. However, it only provides you with a table in the default format (MyISAM. In addition to using the default table format, there are also ways to make MySQL give an error message, but for now, if you are not sure whether a specific database engine is available, you need to use SHOWTABLE to check the table format.
More options mean better performance
Engines used for specific tables need to be re-compiled and tracked. Considering this extra complexity, why do you still want to use non-default database engines? The answer is simple: you need to adjust the database to meet your requirements.
Certainly, MyISAM is indeed fast, but if your logic design requires transaction processing, you can freely use the engine that supports transaction processing. Further, because MySQL allows you to use the database engine at the table layer, You can optimize the performance of the tables that require transaction processing, instead, the tables that do not need to be processed are handed over to the MyISAM engine, which is lighter. For MySQL, flexibility is the key.