MySQL Common commands

Source: Internet
Author: User

MySQL command on-line Baidu comes out is a lot of, this is just to tidy up more than usual instructions.

Baidu Library In this article can refer to http://wenku.baidu.com/view/b5e83a27ccbff121dd368357.html

Common types of data

The MySQL Terminator is ";" ends.

1. Show the host database

  show databases;

2. Deleting a database

  Drop database dbName;

3. Create a Database

  drop database [if not EXISTS] dbName;

The parentheses section is optional, and the database is determined to be created if it does not exist.

4. Switch, use the specified database

  Use DbName;

5. Display all table objects currently using the database

  Show tables;

6. Display the underlying structure describe (DESC)

  DESC TableName;

Use of 7.ALTER table

Show Table T1 first. Table T1 is created using the following methods:

CREATE TABLE T1 (a integer,b CHAR (10));

Rename the table T1 to T2:

ALTER TABLE T1 RENAME T2;

Change column A from interger to tinyint not NULL (the name remains the same), change column B from char (10) to char (20), and rename column B to column C:

ALTER TABLE T2 MODIFY A TINYINT not NULL, change b C CHAR (20);

Add a new timestamp column with the name D:

ALTER TABLE T2 ADD D TIMESTAMP;

To add an index to column D and column A:

ALTER TABLE T2 Add index (d), add index (a);

Delete Column C:

ALTER TABLE T2 DROP COLUMN C;

Add a new auto_increment integer column with the name C:

ALTER TABLE T2 ADD C INT UNSIGNED not NULL auto_increment,
ADD PRIMARY KEY (c);

Note that we indexed the C (as primary KEY) because the auto_increment column must be indexed. At the same time we define C as not NULL because the primary key column cannot be null

MySQL Common commands

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.