【mysql】SQL常用指令

 
常用操作指令
  1. show databases;显示所有的数据库;
  2. use dbName; 使用指定数据库
  3. show tables; 显示所有的数据表;
  4. desc tableName; 查看数据表的字段信息;
  5. show create table tableName; 查询创建表的所有信息;
  6. show create database dbName; 查看数据库创建指令;
  7. show full processlist; 查看所有进程
  8. drop table tableName; 删除表
  9. alter table tableName add constraint 主键(如:PK_TableName) primary key  tableName(主键字段);添加主键约束
  10. alter table tableName add constraint 从表 (如:FK_从表_主表) foreign key 从表(外键字段) references 主表(主键字段) ;添加外键约束
  11. alter table tableName add constraint 唯一约束 (如:uk_t_1) unique(字段名); 添加唯一约束;
  12. alter table tableName drop primary key; 删除主键约束
  13. alter table tableName drop foreign key 外键(区分大小写);删除外键约束
  14. mysqldump -uroot -pXXXX -h19.168.5.2 -P30118 --databases mgmt >/tmp/mgmt.sql: 导出指定数据库

创建数据库:
  1. create database if not exists `myTestDB`;
 

创建数据表:
  1. create table if not exists `t_user`(
  2. `userid` int(11) not null auto_increment,
  3. `userName` varchar(32) not null DEFAULT '',
  4. `password` varchar(32) DEFAULT null,
  5. `createTime` timestamp not null DEFAULT CURRENT_TIMESTAMP,
  6. `status` smallint(4) default null,
  7. `lastLoginTime` datetime DEFAULT null,
  8. primary key (`userid`),
  9. UNIQUE key `userName`(`userName`)
  10. )ENGINE=InnoDB auto_increment=3 default CHARSET=utf8;



插入数据
 
在指定的列中插入数据
  1. insert into t_user(userName,password,createTime,status,lastLoginTime) values("Tom","12345","2016-12-12 13:45:12",1,"2016-12-12 13:45:12");
  2. insert into t_user(userName,password,createTime,status,lastLoginTime) values("Lily","12345","2016-12-12 14:45:12",1,"2016-12-12 14:45:12");
  3. insert into t_user(userName,password,status,lastLoginTime) values("Jenny","12345",1,"2016-12-12 14:45:12");

 
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值