标签:
查看数据库
show databases;
使用数据库
use [数据库名]
如:use mysql
创建数据库
CREATE DATABASE bruce DEFAULT CHARACTER SET utf8
删除数据库
drop database bruce
查询mysql版本
select version();
查询当前用户
select user();
显示当前库的所有表
show tables;
创建用户
create user ysb
赋予权限
GRANT ALL PRIVILEGES ON *.* TO ‘ysb‘@‘%‘ IDENTIFIED BY ‘ysb‘ WITH GRANT OPTION;
创建表
CREATE TABLE `cobar_test` ( `user_id` bigint(20) NOT NULL AUTO_INCREMENT, `user_name` varchar(100) DEFAULT NULL, `password` varchar(100) DEFAULT NULL, PRIMARY KEY (`user_id`) ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
查看表结构
DESCRIBE goods
删除表
drop table goods; drop table goods CASCADE CONSTRAINTS;//级联删除约束
语法:ALTER TABLE 【表名】ADD CONSTRAINT 【约束名】PRIMARY KEY(列名)
ALTER TABLE goods ADD CONSTRAINT goodsType_pk PRIMARY KEY (id);
删除主键约束
ALTER table goods DROP PRIMARY KEY
增加外键约束
ALTER TABLE goods ADD CONSTRAINT goods_fk foreign KEY (goodsType) references goodsType(id) ;
删除外键约束
ALTER table goods DROP FOREIGN KEY goods_fk
增加唯一性约束
ALTER TABLE itemDetail ADD CONSTRAINT itemDetail_uk UNIQUE (goodsId,orderId);
删除唯一约束
ALTER TABLE itemDetail DROP INDEX itemDetail_uk;
增加列
alter table file_info add convert_status varchar(50);
删除列
alter table file_info drop column convert_status;
修改列
alter table file_info change convert_status convert_status2 int(11);
标签:
原文地址:http://www.cnblogs.com/tangyanbo/p/4289942.html