MySql工作中的常用命令

1.数据库相关

-- 登录数据库
mysql -h127.0.0.1 -P3306 -uroot -p;
--查看所有数据库
show databases;
--创建数据库
create database test;
--删除数据库
drop database test;
--使用数据库
use test;

2.表相关

--查看所有的表
show tables;
--创建表
create table test(id int, name varchar(10), age int, primary key(id), unique(name), key index_age(age));
--删除一个存在的表
drop table if exist test;
--修改表的名称
alter table test rename test_1;
rename table test to test_1;
--查看表结构
desc test;
--查看表的创建语句
show create table test;

3.表结构相关

--添加字段
alter table test add c varchar(2)  default '' comment '测试' after a;
--删除字段
alter table test drop c;
--修改字段名称和属性
alter table test change c d varchar(30);
--只修改字段属性
alter table test modify d varchar(50);

4.索引的操作

--添加主键索引
alter table test add primary key (id);
--删除主键索引
alter table test drop primary key;
--添加唯一键(带键名称)
alter table test add unique uk_name  (name);
----添加唯一键(不带键名称)
alter table test add unique (name);
--创建普通索引
alter table test add index a_index (a);
--创建联合索引
alter table test add index a_b_index (a,b);
--删除索引
drop index a_index on test;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值