Summary of common MySql commands

Source: Internet
Author: User
Tags mysql commands

Summary of common MySql commands

User

Logon: mysql-u username-p Password

Add User: insert into mysql. user (host, user, password, select_priv ,...) value ('server name', 'username', 'Password', 'authorization ',...);

Manage databases:

Show database;

Create database;

Delete: drop database T

Open Database use T

Manage data tables:

Table creation: create table name (field name, field type, field attribute, field name, field type, field attribute );

Display data table structure: describe name

Modify Field Type: alter table Database Name change Field name new field name;

Add field: alter table database name add field Name field type

Delete field: alter table Database Name drop field name

Drop table

Table Name Change: rename table name to new table name

Manage records

Add record: insert into Table Name (field name) value ('field value ')

Batch Processing: source SQL. SQL

Delete record: delete from table name where condition expression

Delete all records from table names

Modify update table name set field name = field value where condition expression

Query a data table:

Query all: select * from Table Name

Query order: select ID card number, name, mobile phone from member order by ID card number

Multi-Table query:

Join query: select * form region, member where region. id = member. id

Three-table join query select * from nation, member, book where nation. id = member. id and region. id = book. id

Left join select * form a left join on B where a. id = B. id

Select * from a inner join on B where a. id = B. id

Wildcard:

Wildcard characters are used for string processing. % matches all characters. _ matches one character.

Query all users with the specified name in the user table.

Select * form user where name like 'sheet %'

Except for

Select * form user where name not like 'sheet %'

Find out that the names of all surnamed Zhang are two words.

Select * form user where name like 'sheet _'

Function:

Count (*) count the number of records

Select count (*) from member

Sum (field name) for the specified field name

Avg calculates the average value for the specified field name

Max (field name) calculates the maximum value

Min (field name) calculates the minimum value

Select count (distinct id) from member ID deduplication count

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.