Twelve basic statement of mysql

In mysql, all statements with a semicolon marks the end!

 

1. connect to the server

Mysql -u username -p passwd

 

2. When connected to the server, the first face of the library, the library has one or more, so we wanted to operate on the table, then you must first choose the library :

use the library name;

 

3. If you do not know what library you want to see all of the libraries:

show databases;

 

 4 . Check the library all the following table:

show tables;

 

5. Create a database

create database database name;

Library name behind the increase charset character set (such as utf8); now can not add, in the configuration file has been set default encoding format.

After creation, data folder name will be one more library catalog

 

6. To delete a database

drop database library name;

 

7.MySQL database can not be renamed, table / column can be renamed

rename table oldname to new_tablename;

 

8. Create a table

 create table stu(    

  -> Finding an int,    

  -> sname varchar(10)    

  -> )engine myisam charset utf8;

engine means the table engine, and related performance characteristics.

 

9. Delete table

drop table 表名;

 

10. The insert data

mysql> insert into stu values    

  -> (1,'mike'),(2,'josn'),(3,'wiki');     

 

mysql> insert stu values    

  -> (4,'nana');

May not be added into

 

11. View Table

select * from 表名;

 

12. Empty table data

truncate 表名;

 

truncate and delete the difference between:

  • truncate the deleted table, the table structure is gone (empty table, and then reconstruction)
  • delete after deleting the table, the table structure is still there. (Delete data from the perspective of the line)
  • If you modify the data much, use delete,
  • If you modify a lot of data on the use of truncate

Guess you like

Origin www.cnblogs.com/sunbr/p/11704100.html