MySQL database learning----MySQL database, table operations, and engine differences

Source: Internet
Author: User

Operation of MySQL Database

One: View all the databases in MySQL

SHOW DATABASES;

Two: Create a database

Cretae database name;

Three: Deleting a database

DROP database name;

Four: View the storage engines supported by the database

SHOW ENGINES;

Four: Connect MySQL database

Use database name;

Operation of tables in MySQL database

One: View all tables in the database

SHOW TABLES;

Second: View the structure of the table

DESC table name; (basic structure);

Or

SHOW CREATE table table name; (detailed structure);

Three: Create a table

CREATE Table table name (field name data type constraint, field name data type constraint,....);

Constraint conditions Description
PRIMARY KEY Indicates that the field is the primary key of the table and can uniquely identify the corresponding element
FOREIGN KEY Indicates that the field is a foreign key to the table and is the primary key of the table to which it is contacted
Not NULL Indicates that the field cannot be empty
UNIQUE Indicates that the value of the field is unique and does not duplicate
Auto_increment Indicates that the value of the field is automatically incremented
DEFAULT is the default value for the field

Four: Modify table name

ALTER tbale Old table name RENAME new table name;

V: Delete Table

DROP table name;

Six: Modifying field data types

ALTER table name MODIFY field name new data type;

Seven: Modify field sorting

ALTER table name MODIFY field name first/after field name;

Eight : Modify field Name

ALTER Table name change old field name new data type of new field name;

Nine : Add field (before/Insert "field name" before after/Insert "field name")

ALTER Table name ADD new field name new data type constraint [before/after field name];

Ten: Delete a field

ALTER table name DROP field name;

11: Change the storage engine for a table

ALTER table name engine= storage engine name;

Storage Engine Description
Inoodb Supports the logic of things, has event rollback, concurrency, and supports foreign keys.
MyISAM Small footprint, fast processing speed.
MEMORY Data tables stored in memory, fast, the disadvantage is that the data is easy to lose, short life cycle.

MySQL database learning----MySQL database, table operations, and engine differences

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.