Detailed description of data table operations in MySQL

Source: Internet
Author: User
With MySQL, you can choose between the three basic database tables. When creating a table, you can tell MySQL which table type it should use for the table. MySQL

With MySQL, you can choose between the three basic database tables. When creating a table, you can tell MySQL which table type it should use for the table. MySQL

With MySQL, you can choose between the three basic database tables. When creating a table, you can tell MySQL which table type it should use for the table. MySQL will always create a. frm file to save the table and column definitions. Indexes and data are stored in other files, depending on the table type.

You can use the alter table statement to convert different types of tables.

MyISAM

In MySQL 3.23, MyISAM is the default table type. It is based on the ISAM code and has many useful extensions. Indexes are stored in a file with the. MYI (MYindex) Extension and data is stored in a file with the. MYD (MYData) extension. You can use the myisamchk utility to check/repair the MyISAM table.

ISAM

You can also use the abandoned ISAM. This will soon disappear because MyISAM is a better implementation of the same thing. ISAM uses a B-tree index, which is stored in. files with the ISM extension and the data is stored in. in the ISD extension file, you can use the isamchk utility to check/repair the ISAM table. The ISAM table is not portable across OS/platform binary.

HEAP

HEAP tables use a hashed index and are stored in memory. This makes them faster, but if MySQL crashes, you will lose all the stored data. HEAP is available as a temporary table!

Use SHOW/DESCRIBE statements to display data table information

Syntax:

Show tables [FROM db_name] [LIKE wild]

Or show columns from tbl_name [FROM db_name] [LIKE wild]

Or show index from tbl_name [FROM db_name]

Or show table status [FROM db_name] [LIKE wild]

{DESCRIBE | DESC} tbl_name {col_name | wild}

You can use db_name.tbl_name as another option of tbl_name FROM db_name syntax.

Show tables lists TABLES in a given database. You can also run the mysqlshow db_name command to obtain the table.

Note: If a user does not have any permissions for a table, the table is not displayed in the output of show tables or mysqlshow db_name.

Show columns lists the COLUMNS in a given table. If the column type is different from what you expect to be based on the create table statement, note that MySQL sometimes changes the column type.

The DESCRIBE statement provides information similar to show columns. DESCRIBE provides information about columns in a table. Col_name can be a column name or a string containing the SQL "%" and "_" wildcards. This statement is provided for compatibility with Oracle.

Show table status (introduced in version 3.23) is similar to show status, but more information is provided for each TABLE. You can also run the mysqlshow -- status db_name command to obtain the table.

Show fields is a synonym for show columns, and show keys is a synonym for show index.

You can also use mysqlshow db_name tbl_name or mysqlshow-k db_name tbl_name to list the columns or indexes of a table.

Show index returns the INDEX information in a format similar to that called by ODBC SQLStatistics.

Use mysqlshow to obtain information

The following describes the usage of the mysqlshow utility. It is very convenient to get the database and table information.

Obtain the list of existing databases:

Shell> mysqlshow

List existing tables in a database db_name:

Shell> mysqlshow db_name

List the structure information of a database table db_name.tbl_name:

Shell> mysqlshow db_name tbl_name

List the indexes of a table:

Shell> mysqlshow-k db_name tbl_name

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.