日期:2014-05-16  浏览次数:20665 次

MYSQL命令小记

本人不才,记录一下SQL命令。使用MYSQL。

 

1、显示数据库:show databases;// 要加s

2、创建数据库:create database one;// 数据库名字为one(下面都是用one来代表),可通过show databases查看

3、删除数据库:drop database one;

4、进入数据库:use one;

5、查看数据库表:show tables;// 同样要s

6、建表:create table one_table (id int(4) not null primary key auto_increment,name char(20) not null);// 表明为one_table,id不可为空,主键,自增

7、查看表结构:show columns from one_table;或者DESCRIBE one_table;或者desc one_table;

8、查询表内容:select * from one_table;// 所有

9、插入表内容:insert into one_table values(1,'A'),(2,'B');

10、查询前几个的内容:select * from one_table order by id limit 0,2;或者select * from one_table limit 0,2;

11、删除内容:delete from one_table where id=1;// 通过id删除

12、修改表明:rename one_table to two_table;//表明从one_table修改为two_table;

13、修改表内容(替换):update one_table set name=replace(name,'b''bbbb');//修改name字段,值为b的全部修改为bbbb

        修改表内容(插入):update one_table set name=concat('wwwww, name);//这里的关键字是concat,在name字段中的值签名添加"wwww",是所有的值

删除表:drop table one_table;

待续。。。