Posts Mysql常见指令
Post
Cancel

Mysql常见指令

一些不太常用的指令,每次要用都要去查一遍很麻烦费时间,记录一下,下次要用直接来博客里面翻


外键

  • 已创建的表,增加外键约束
1
2
ALTER TABLE camera ADD CONSTRAINT `fk_2` FOREIGN KEY (group_id) REFERENCES groups(group_id);

  • 撤销外键
1
ALTER TABLE infos DROP FOREIGN KEY `fk_1`;

主键

  • 撤销主键
1
alter table table_test drop primary key;
  • 增加主键
1
alter table table_test add primary key(id);

更改列属性

  • 修改列属性
1
ALTER TABLE infos MODIFY COLUMN user_id VARCHAR(20);

数据库导出

mysqldump -u root -p hgd_new > hgd.sql

数据库恢复

1
2
3
4
5
1. 进入mysql
输入 mysql -u root -p   按回车
2. show databases 
3. use database
4. source /foo.sql
This post is licensed under CC BY 4.0 by the author.

Contents

Trending Tags