数据库操作相关(sql语句-命令行)

创建数据库:
create database books;
创建用户:
mysql> grant select,insert,delete,uptate
    -> on books.*
    -> to dada identified by 'yujianqi2011';
 
使用数据库:
use dbname;
use dada;
 
新建数据库表
create table tablename(columns);
create table demo(
     userid int unsigned not null auto_increment primary key,
     username char(50) not null,
     password char(20) not null,
     age int not null,
     city char(20) not null     
);
 
显示数据库表
show tables;
 
在数据库中插入数据
insert into demo values(NULL,"dada","yujianqi2011",27,"beijing");
insert into demo values(NULL,"xiaoyin","yujianqi2011",26,"shanghai");
 
查询数据
select name, city from customers where name="dada";
 
更新数据
update customers 
set address =  "北京市海淀区";
 
删除数据
delete from dada where name = "dada";
 
表的删除
DROP TABLE table;
 
数据删除
DROP DATABASE database;
posted @ 2013-07-02 13:43  snowinmay  阅读(1176)  评论(0编辑  收藏  举报