mySql common commands

First, the database operations

1. Create a database

the Create  Database  < database name > ; - for example, create a test database, create database test;

2, all database queries

show databases;

3, delete the database

drop  Database  < database name >

4, connect to the database 

use  < database name > ; - e.g., a test database, use test command;

5, view the database currently in use

select database(); 

6, view all current database table

show tables; 

7, export the database

mysqldump - U user name - the p-- default - Character - the SET = latin1 database name > exported file name (database default encoding is latin1)

8, export a table

mysqldump - U user name - the p-watches database name > exported file name

9, export the database structure

the mysqldump - U username - P - D - the Add - drop - Table database name > exported file name 

- -d no data -add-drop-table to add a drop table before each create statement   

 

Second, the operating table

1, create a table

Create  Table  < table name > ( < field name >  < type >  [ , .. <field name n> <n-type> ] );  

2, an acquisition table structure

desc table name, or the Columns Show from table

3, delete the table

drop table <表名>;

4, insert data 

INSERT  INTO  < table name >  [ (<field name> [, .. <field name n-> ] )] values (value) [ , (n-value) ]

5, the data look-up table

1 ), query all rows
 the SELECT  < fields, fields, ... >  from  < table >  the WHERE  < expression > ; 

the SELECT  *  from tableName;
 2 ), several lines of inquiry before
 the SELECT  *  from tableName limit 0 , 2 ;

6, delete table data

the Delete  from table where expressions  

7, update table data

update table set field = new value, ... the WHERE condition  

8, increase table field

ALTER  Table table add field types other;

9, to change the name of the table

the rename the Table original table to the new table name;

 

 

Guess you like

Origin www.cnblogs.com/BillyYoung/p/10973316.html