找回密码
 立即注册

推荐阅读

  • 便民服务
  • 关注我们
  • 社区新手
mysql -uroot -p(去访问mysql)
service mysqld start(启动mysql服务)
service mysqld restart(重启)
service mysqld stop(关闭)
service mysqld status(查询)
show databases;(查询有多少数据库)
create database A;(创建数据库)
drop databaseA(删除数据库)
use A;(进入数据库的指令)
show tables;(只能进入数据库使用)
desc wuhan;(查看当前表的结构)
select * from wuhan;(查看表中数据)
insert into wuhan()values();(插入语句)
insert into wuhan values();(插入语句)
insert into wuhan15(time)values(“1990-01-03”);(插入指定字段)
create table wuhan(id int(4)primary key auto_increment,name varchar(20),class float(20,2)not null,phone bigint(20)default 15927892370,time date);
int (整数)
bigint(长数字)
float(浮点数)
varchar(字母符)
date(时间类型)
not null(非空约束,不能为空)
default(默认值约束)
primary key(主键约束,可以变动)
auto_increment(自增长约束)
drop table A;(删除表)
create table(创建一个表)
alter table A rename B;(修改表名称)
alter table A add age int(4);(增加表字段)
alter table A change class age int(8);(change修改字段结构)
alter table A change id id int(4)auto_increment;
alter table A drop name,drop phone;(删除字段drop)
alter table A drop primary key;(删除主建)
alter table wuhan15 change id id int(4)primary key(增加主键)
alter table A modify name varchar(20)first;(modify(按顺序) 把name字段放在第一个first)
alter table A modify age int(4)after id;(age放id后面 after)
(alter table 只针对表结构)A add age int(4)first;
select * from A where id = 6;(where条件运算)
select name,time from A where id != 6;
= != > >= < <=
select * from wuhan where id=3 or id=4;(or与)
select * from wuhan where class=15 and age=24;(and且)
select * from wuhan where id>=2 and id <=5;
select (name) from wuhan where id=3 and phone=15827628206(查找出id=3phone为name的字段)
is null is not null
select * from wuhan where name is null;(查询nmll的属性)
select * from wuhan where id not in(1,3,5,7);(b不是1357都显示)
select * from wuhan where 1 in(id);(只显示1)
select *from wuhan where name in或者not in("niuyi","niuer");
where "niuyi" in (name);
where name like "y%"或者“%y"
where id limit 2,5;(查询3-7行的内容)
order by id desc降序排序(从大到小,order by排序的字段 排序规则)
order by time asc(按照时间升序排序从小到大)
group by age(分组)、
select count(*) from wuhan;(分组,统计小组人数,多少条数据)
max()(求最大值)(select max(age)from wuhan15)
min()(最小值)
sum()(求和)
avg()  平均值 (select avg(age)from wuhan group by class having avg(age)>19
distinct()(删除重复数据)
having(group by后面接条件where换having)
update wuhan set class=2 where class=0.00(修改class语句)(name=2,time="2022.1.2"全部修改)
delete wuhan;(delete删除语句)(例:delete from wuhan where id=5orid=6;)
truncate wuhan;(直接删除表中内容)
mqsqldump -uroot -p wuhan15> /wuhan15.sql(备份以及存储的位置)
create database dcs(新建数据库,和还原数据库文件)
select database
分享至 : QQ空间
收藏

0 个回复

您需要登录后才可以回帖 登录 | 立即注册