MySQL的一些指令操作[简版]

sudo apt-get install mysql-server pa aux | grep mysql sudo service mysql start sudo service mysql st

<div class=”cnblogs_code”>

 apt-get  mysql-| /==( ,name ( add  dct_name (alter table <span style="color: #0000ff">mv modify name varchar(<span style="color: #800080">20<span style="color: #000000">);
alter table <span style="color: #0000ff">mv change <span style="color: #0000ff">id<span style="color: #000000"> id_num smallint;

<span style="color: #0000ff">select * from <span style="color: #0000ff">mv<span style="color: #000000">;
insert into <span style="color: #0000ff">mv (<span style="color: #0000ff">id,name) values(<span style="color: #800080">1,<span style="color: #800000">"<span style="color: #800000">Fast and Furious<span style="color: #800000">"<span style="color: #000000">);
insert into <span style="color: #0000ff">mv values(<span style="color: #800080">2,<span style="color: #800000">"<span style="color: #800000">The Zootopia<span style="color: #800000">",<span style="color: #800080">2018),(<span style="color: #800080">3,<span style="color: #800000">"<span style="color: #800000">The Gifts<span style="color: #800000">",<span style="color: #800080">2019<span style="color: #000000">);
update <span style="color: #0000ff">mv set yr=<span style="color: #800000">'<span style="color: #800000">2018<span style="color: #800000">'<span style="color: #000000">;
truncate <span style="color: #0000ff">mv<span style="color: #000000">;
delete from <span style="color: #0000ff">mv<span style="color: #000000">;
delete from <span style="color: #0000ff">mv where yr=<span style="color: #800080">2017<span style="color: #000000">;
create table t_pk(<span style="color: #0000ff">id <span style="color: #0000ff">int primary key,name <span style="color: #0000ff">char(<span style="color: #800080">10<span style="color: #000000">));
create table t_atp(<span style="color: #0000ff">id <span style="color: #0000ff">int atuo_increment primary key,name <span style="color: #0000ff">char(<span style="color: #800080">10<span style="color: #000000">));
create table t_un(<span style="color: #0000ff">id <span style="color: #0000ff">int unique,name <span style="color: #0000ff">char(<span style="color: #800080">10<span style="color: #000000">));
create table t_nn(<span style="color: #0000ff">id <span style="color: #0000ff">int,name varchar(<span style="color: #800080">10) not <span style="color: #0000ff">null<span style="color: #000000">);
create table t_dft(<span style="color: #0000ff">id <span style="color: #0000ff">int,name varchar(<span style="color: #800080">10) default <span style="color: #800000">"<span style="color: #800000">WW<span style="color: #800000">"<span style="color: #000000">);

create table t_f(<span style="color: #0000ff">id <span style="color: #0000ff">int primary key,name <span style="color: #0000ff">char(<span style="color: #800080">10<span style="color: #000000">));
create table t_s(<span style="color: #0000ff">id <span style="color: #0000ff">int primary ket auto_increment,name <span style="color: #0000ff">char(<span style="color: #800080">10),fid <span style="color: #0000ff">int,foreign key(fid) references t_f(<span style="color: #0000ff">id<span style="color: #000000">));
drop table t_s;
drop table t_f;

create table t_chk(<span style="color: #0000ff">id <span style="color: #0000ff">int,age <span style="color: #0000ff">int check(age > <span style="color: #800080">0 and age < <span style="color: #800080">150),gender <span style="color: #0000ff">char(<span style="color: #800080">10) check(<span style="color: #800000">'<span style="color: #800000">boy<span style="color: #800000">' or <span style="color: #800000">'<span style="color: #800000">girl<span style="color: #800000">'<span style="color: #000000">));

alter table t_pk add constraint PK_id primary key(<span style="color: #0000ff">id<span style="color: #000000">);
alter table t_pk drop primary key;
alter table t_fk add constraint FK_id foreign key(<span style="color: #0000ff">id<span style="color: #000000">) references t_pk;
desc table t_fk;
alter table t_fk drop foreign key FK_id

mysqldump -uroot -p OriginS ><span style="color: #000000"> bakp.sql
mysqldump -uroot -p OriginS t_s1,t_s2 ><span style="color: #000000"> s1s2.sql
create database OSdb;
exit;
mysql -uroot -p OSdb <<span style="color: #000000"> bakp.sql

<span style="color: #0000ff">select <span style="color: #000000"> from t_s1;
<span style="color: #0000ff">select<span style="color: #000000"> c_id,c_name,c_addr from t_s1;
<span style="color: #0000ff">select<span style="color: #000000"> c_id as 学号,c_name as 姓名,c_addr 地址 from t_s1;
<span style="color: #0000ff">select<span style="color: #000000"> distinct c_addr from t_s1;
<span style="color: #0000ff">select
from t_s1 where c_age < <span style="color: #800080">18<span style="color: #000000">;
<span style="color: #0000ff">select from t_s1 where c_age = <span style="color: #800080">23 and c_gender = <span style="color: #800000">'<span style="color: #800000">girl<span style="color: #800000">'<span style="color: #000000">;
<span style="color: #0000ff">select
from t_s1 where cname like <span style="color: #800000">''D<span style="color: #800000">"<span style="color: #800000">;
<span style="color: #0000ff">select * from t
s1 where c_id <span style="color: #0000ff">in range(<span style="color: #800080">5<span style="color: #000000">);×
<span style="color: #0000ff">select from t_s1 where c_id <span style="color: #0000ff">in (<span style="color: #800080">1,<span style="color: #800080">3,<span style="color: #800080">8,<span style="color: #800080">9<span style="color: #000000">)
<span style="color: #0000ff">select
from t_s1 where c_age is not <span style="color: #0000ff">null<span style="color: #000000">;
<span style="color: #0000ff">select <span style="color: #000000"> from goods order by c_price asc;
<span style="color: #0000ff">select
<span style="color: #000000"> from goods order by c_time desc;
<span style="color: #0000ff">select <span style="color: #000000"> from goods order by c_price asc,c_time desc;
<span style="color: #0000ff">select
from t_s1 limit <span style="color: #800080">3<span style="color: #000000">;
<span style="color: #0000ff">select * from t_s1 limit <span style="color: #800080">2,<span style="color: #800080">10<span style="color: #000000">;

<span style="color: #0000ff">select<span style="color: #000000"> c_gender from t_s1 group by c_gender;
<span style="color: #0000ff">select<span style="color: #000000"> c_gender,c_addr from t_s1 group by c_gender,c_addr;
<span style="color: #0000ff">select<span style="color: #000000"> c_gender,group_concat(name) from t_s1 group by c_gender;
<span style="color: #0000ff">select gender,max(age),min(age),avg(age),<span style="color: #0000ff">sum<span style="color: #000000">(age),count(age) from t_s1 group by gender;
<span style="color: #0000ff">select gender,group_concat(name) from t_s1 group by gender having gender =<span style="color: #800000">'<span style="color: #800000">girl<span style="color: #800000">'<span style="color: #000000">;
<span style="color: #0000ff">select gender,group_concat(name) from t_s1 where age <<span style="color: #800080">25 group by gender having gender = <span style="color: #800000">"<span style="color: #800000">girl<span style="color: #800000">"<span style="color: #000000">;
<span style="color: #0000ff">select<span style="color: #000000"> gender from t_s1 group by gender with rollup

作者: dawei

【声明】:永州站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

联系我们

联系我们

0577-28828765

在线咨询: QQ交谈

邮箱: xwei067@foxmail.com

工作时间:周一至周五,9:00-17:30,节假日休息

返回顶部