用了一段时间的mysql数据库了,现在对mysql数据库中经常用的命令小总结一下,以免以后忘记:
1,连接数据库:
mysql -u root -p root
2,退出数据库:
quit;或者exit;
3,显示数据库:
show databases;
4,在使用某个数据库时,一定要先切换的该数据库,命令为:
use databasename;
5,查看某个数据库里面的有哪些表时:
show tables;
6,查看某个表的结构:
desc tablename;
7,查看当前时间和数据库版本:
select now(),version();
8,创建删除数据库:
create database student; drop database student;
9,创建删除表:
create table falcatys(falcaty_id int not null auto_increment primary key,falcaty_name char(30) not null); drop table falcatys;
10,显示创建表的信息:
show create table falcatys;
11,修改表中某一列的信息:
alter table falcatys modify column falcaty_name char(30) CHARACTER SET utf8 not null;
12, 修改表的创建信息:
alter table falcatys DEFAULT CHARSET=utf8;
13,插入删除数据(一次可以插入一条或多条数据):
insert into falcatys(falcaty_name,falcaty_students_num) values('资源与环境学院',0); delete * from falcatys where fallacy_id = 1;
14,查询表中数据:
select * from falcatys; --查询表中的所有数据 select fallacy_id,fallacy_name from falcatys; --查询给定的列
15,添加列删除列:
alter table professions add column falcaty_id int; alter table professions drop column falcaty_id;
16,添加删除主键约束:
alter table professions add constraint profession_id primary key professions(profession_id); alter table professions drop primary key;
17,添加外键约束:
alter table professions add constraint falcaty_profession_class foreign key(falcaty_id) references falcatys(falcaty_id); alter table professions drop foreign key fallacy_profession_class;
18,添加删除唯一约束:
alter table t_stu add constraint uk_stucode unique(stucode); alter table t_stu drop index uk_stucode;
19, 重命名表:
rename table t_stu to t_user;
20,导入数据库:
21,更新表中的数据:
update t_stu set stuname='jack'[where id=1] ;--修改id为1的名字为jack, 如果不写中括号里面的where条件,则会把所有的姓名都改为jack update t_stu set stuage=stuage+1; --将表中stuage这一列的数都加一 update t_stu set stuage=23 where id id(1,2,4,5); --将id号为1,2,4,5的 stuage改为23 update t_stu set stuage=27 where id between 1 and 4;--将id号在1和4之间的stuage改为27,相当于where id>=1 and id<=4; update t_stu set stuage=24 where stuage is null; update t_stu set stuage=21 where stuage is not null;
22,删除表中所有数据:
truncate table t_stu; --删除t_stu表中的所有数据
23,去除重复的查询:
select distinct vend_id from products;
24,分页查询:
select id,stuname,stuage,stuaddress from t_stu limit 0,5;--第一页从0开始往后数5个显示出来 select id,stuname,stuage,stuaddress from t_stu limit 5,5;--第二页从5开始往后数5个显示出来
25,排序查询:
select prod_id,prod_name,vend_id,prod_price from products order by prod_price asc,prod_name asc;--先按prod_price升序排列,当prod_price相同时再按prod_name排序
相关推荐
MySql常用命令总结MySql常用命令总结MySql常用命令总结MySql常用命令总结MySql常用命令总结MySql常用命令总结
MySQL常用命令总结 MySQL常用命令总结
mysql 特殊命令总结
mysql中常用的命令讲解 mysql中常用的命令讲解 mysql中常用的命令讲解 mysql中常用的命令讲解 mysql中常用的命令讲解 mysql中常用的命令讲解 mysql中常用的命令讲解 mysql中常用的命令讲解 mysql中常用的命令讲解 ...
常见mysql命令总结
该资源详细的描述了如何在dos窗口中运用命令来操作数据库
mysql命令总结.docx 对mysql常用命令的总结,挺不错的。
MySQL基础命令总结
mysql常用命令总结适用于mysql8.0
珍藏!!非常非常实用的MySQL常用命令总结!
MySQL常用命令总结集合了所有的Mysql里面的命令
这是我总结的平时常用的一些Mysql命令,来下载吧,相信你也有用。
Mysql常用命令总结,可以让你快速熟悉基本命令的使用
MySql常用命令总结.pdf
操作MySQL数据库的常用命令,连接MYSQL、修改密码、增加新用户、显示命令、 将文本数据转到数据库中、使用SHOW语句找出在服务器上当前存在什么数据库、创建一个数据库MYSQLDATA等等。
常用mysql命令,简单易懂。 可用于简单操作。收藏于本地。