What is information_schema in MySQL? (1)

Source: Internet
Author: User
Tags mysql in

When I get the self-increment ID, I use the following statement:

Select  from where " Table name ";

Look carefully, this is actually a query statement, query the information_schema database under the "Tables" table, with table_name as "table name" of a row of records The value of the Auto_increment field .

So what is the information_schema database ?

The "INFORMATION_SCHEMA database" is a MySQL-band that provides a way to access database metadata . What is meta data? Metadata is data about the data, such as the database name or table name, the data type of the column, or access permissions.
Some of the other terms used to express this information include the data dictionary and the system catalog.
In MySQL, "Information_schema" is regarded as a database, in fact, an information database. It holds information about all the other databases maintained by the MySQL server. such as database name, database table, table column data type and access permissions.
In "Information_schema" , there are several read-only tables . They are actually views , not basic tables, so you will not be able to see any files associated with them.

There is a readable table in Information_schema! Let's see if we can read the auto_increment from the inside!

Select the information_schema database:

 use Information_schema;

Query (inside theinformation_schema database) for all the tables in thetable :

Select  from tables;

OK all the self-increment IDs in the whole database have been queried, each line represents a data table!! (there are many null because the table does not have a self-increment primary key!) )


If we want to query the self-increment ID of the specified table, we can use the following statement:

Select  from WHERE table_name=' table name ';  Of course, if there is a data table with the same name, it is not just a record to find out. You can add the criteria for the specified database.  Selectfromwhere table_schema=' database name '  and table_name=' table name ';

OK, I want to modify the self-increment ID of the specified data table directly, using the following statement:

Update Set =  - where table_schema=' database ' and table_name= ' Table name ';

But why did you report the following error:

1044  for User ' Root '@'localhost'todatabase'information_ Schema'

The reason is very simple information_schema is a read-only table, cannot be modified!

See more information_schema database contents please go to MySQL in Information_schema is what? (2)

What is information_schema in MySQL? (1)

Related Article

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.