\c:结束当前mysql命令
\g:== go 执行 ==
cls:清空界面
cd:进去目录
dir:查看文件
C:\Users\fwhf-pc>mysqldump -uroot -p test > e:\a.sql
C:\Users\fwhf-pc>mysql -h localhost -uroot -p test < e:\a.sql
source e:\a.sql
C:\Users\fwhf-pc>mysqldump -uroot -p test user > e:\d.sql
C:\Users\fwhf-pc>mysqldump -uroot -p -d --add-drop-table test > e:e.sql
C:\Users\fwhf-pc>mysqldump -uroot -p -d test user > e:\f.sql
show databases
create database 库名
drop database 库名
use 库名
select database()
show tables
create table 表名(id int(8) , username varchar(45) , password char(32));
drop table 表名
desc 表名
show create table 表名
show engines
alter table 原来的表名字 rename 新的表名字
alter table 表名 change 原来的字段 新的字段(数据类型)
alter table 表名 modify 原来的字段(新的数据类型)
alter table 表名 add 新的字段(数据类型)
alter table 表名 drop 你要删除的字段
alter table 表名 add 新字段(数据类型) after 字段名
alter table 表名 add 新字段(数据类型) first
alter table user add index(money)
普通索引
alter table user add unique(province)
唯一索引
alter table user add primary key(id)
主键索引
alter table user add fulltext(username)
全文索引
show index from user \G
create table newuser select * from user
不仅仅复制表结构还有数据
create table newuser like user
复制表结构
alter table user auto_increment=起始值
insert into user(id,name,money,province,age,sex)values(1,'名字',20,'中国',12,1);
insert into user values(2,'名字',12,'山东',56,0);
insert into user(name,money,province,age,sex)values('名字',23,'山西',45,1),('名字2',34,'河南',32,0),('名字3',23,'河北',12,0);
delete from user where id = 7;
delete from user where money=34 or age=12;
update user set name='new名字' where id = 2;
update user set name='new名字',money=99,province='哪里' where id = 2;
update user set money=money-9 where name = 'new名字';
select * from user;
select name , age from user;
select distinct name from user;
select * from user where age = 32;
select * from user where age between 20 and 40;
select * from user where age > 32 and age < 50;
select * from user where age=32 or age=12;
select * from user where age != 40;
select * from user where age <> 40;
select * from user where age in(12,32);
select * from user where province like '河%';
select * from user where province like '%河%';
select * from user where province like '河_';
select * from user where province like '_河_';
select * from user order by id asc;(默认的排序,升序)
select * from user order by age desc;(降序)
select * from user limit 0 , 2;
select * from user order by age asc limit 0 , 2;
select * from user where > 20 order by age asc limit 0 , 2;
select count(*) , name from user group by name;
分组
select count(*) as total , name from user group by name;
起别名
select count(*) as total , name from user group by name having total > 2;
对结果进行再次过滤 having
mysql> select * from shop_user join shop_goods;
mysql> select shop_user.username,shop_goods.gname from shop_user,shop_goods where shop_user.gid = shop_goods.gid;
mysql> select username as uname , gname as name from shop_user inner join shop_goods on shop_user.gid = shop_goods.gid;
mysql> select username , gname from shop_user left join shop_goods on shop_user.gid = shop_goods.gid;
mysql> select username , gname from shop_user right join shop_goods on shop_user
mysql> select username from shop_user where gid in(select gid from shop_goods);
mysql> select * from shop_user left join shop_goods on shop_goods.gid = shop_user.gid union select * from shop_user right join shop_goods on shop_user.gid = shop_goods.gid;
mysql> update shop_user as u , shop_goods as g set u.username='qwq' , g.gname='rtr' where u.gid = g.gid and u.gid=1;
mysql> select * from shop_goods order by price , gid desc;
sum 求和
count 求总条数
max 求最大值
min 求最小值
avg 求平均值
select count(shop_user.gid) as count , shop_goods.gname ,avg(shop_goods.price) from shop_user inner join shop_goods on shop_user.gid = shop_goods.gid group by shop_goods.gname order by count desc limit 0 , 1;
select count(shop_user.gid) as ugid , shop_goods.gname as name from shop_user right join shop_goods on shop_user.gid = shop_goods.gid group by shop_goods.gname order by ugid desc limit 0 , 1;
select count(shop_user.gid) as ugid , shop_goods.gname from shop_user left join shop_goods on shop_user.gid = shop_goods.gid group by shop_goods.gname order by ugid desc limit 0 , 1 ;
revoke grant
mysql> create user 'whj'@'localhost' identified by 'love';
创建用户
mysql> drop user 'whj'@'localhost';
删除用户
mysql> grant select on *.* to 'whj'@'localhost';
赋予权限
mysql> revoke select on *.* from 'whj'@'localhost';
剥夺权限
mysql> select user from mysql.user;