sudo apt-get install mysql-server
pa aux | grep mysql
sudo service mysql start
sudo service mysql status
./start_navicat
CRUD
create database db1;
create database db2 charset=utf8;
create database db3 character set utf8;
show create database db2;
alter database db1 charset=utf8;
show databases;
use db3;
select database();
drop database db2;
use db3;
show tables;
create table mv(id int, name char(), yr year);
show create table mv;
alter table mv add dct_name char();
alter table mv drop dct_name; alter table mv modify name varchar();
alter table mv change id id_num smallint; select * from mv;
insert into mv (id, name) values(,"Fast and Furious");
insert into mv values(,"The Zootopia",),(,"The Gifts",);
update mv set yr='';
truncate mv;
delete from mv;
delete from mv where yr=;
create table t_pk(id int primary key, name char());
create table t_atp(id int atuo_increment primary key, name char());
create table t_un(id int unique, name char());
create table t_nn(id int, name varchar() not null);
create table t_dft(id int, name varchar() default "WW"); create table t_f(id int primary key, name char());
create table t_s(id int primary ket auto_increment, name char(), fid int, foreign key(fid) references t_f(id));
drop table t_s;
drop table t_f; create table t_chk(id int, age int check(age > and age < ), gender char() check('boy' or 'girl')); alter table t_pk add constraint PK_id primary key(id);
alter table t_pk drop primary key;
alter table t_fk add constraint FK_id foreign key(id) references t_pk;
desc table t_fk;
alter table t_fk drop foreign key FK_id mysqldump -uroot -p OriginS > bakp.sql
mysqldump -uroot -p OriginS t_s1, t_s2 > s1s2.sql
create database OSdb;
exit;
mysql -uroot -p OSdb < bakp.sql select * from t_s1;
select c_id, c_name, c_addr from t_s1;
select c_id as 学号, c_name as 姓名,c_addr 地址 from t_s1;
select distinct c_addr from t_s1;
select * from t_s1 where c_age < ;
select * from t_s1 where c_age = and c_gender = 'girl';
select * from t_s1 where c_name like ''D";
select * from t_ s1 where c_id in range();×
select * from t_s1 where c_id in (,,,)
select * from t_s1 where c_age is not null;
select * from goods order by c_price asc;
select * from goods order by c_time desc;
select * from goods order by c_price asc, c_time desc;
select * from t_s1 limit ;
select * from t_s1 limit , ; select c_gender from t_s1 group by c_gender;
select c_gender, c_addr from t_s1 group by c_gender, c_addr;
select c_gender ,group_concat(name) from t_s1 group by c_gender;
select gender, max(age), min(age), avg(age), sum(age), count(age) from t_s1 group by gender;
select gender, group_concat(name) from t_s1 group by gender having gender ='girl';
select gender, group_concat(name) from t_s1 where age < group by gender having gender = "girl";
select gender from t_s1 group by gender with rollup select t_s.name, t_c.name from t_s, t_c where t_s.c_id = t_c.id;
select s.name 学生姓名, c.name 班级名称 from t_s s, t_c c where s.c_id = c.id;
select s.name 学生姓名, c.name 班级名称 from t_s as s inner join t_c c on s.c_id = c.id;
select s.name 学生姓名, c.name 班级名称 from t_s s left join t_c c on s.c_id = c.id;
select s.name 学生姓名, c.name 班级名称 from t_c c right join t_s s on s.c_id = c.id; select * from t_s1 where age > (select avg(age) from t_s1);
select * from t_c where id in (select c_id from t_s1);
select * from t_s1 where (age, class_id) = (select max(age), min(class_id) from t_s1);
create table areas(id int primary key, atitle varchar(), pid(int));
source ./areas.sql;
select count(*) from areas where pid is null;
select c.* from areas as c inner join areas p on c.pid = p.id where p.atitle ='湖南省'