mysql 命令行操作

1.查询所有数据库

SHOW DATABASES;

2.进入数据库

USE USER;(进入的数据库名称)

3.查看所有表

SHOW TABLES;

4.查看表里面的字段

DESC bbs_user;(查看的表名称)

5.往数据库里面添加数据

INSERT INTO bbs_user(id,username,password,address,sex,age) VALUES(1,'李四','123456','泉州',1,20);

6.删除数据库数据

DELETE FROM bbs_user WHERE id = 1;  (WHERE:删除条件)

7.修改数据库数据

UPDATE bbs_user SET username='张三',password='888888' WHERE id=1;

8.查询数据库数据

SELECT * FROM bbs_user;(查询所有数据)

SELECT DISTINCT address FROM bbs_user;(DISTINCT:去除重复数据)

SELECT * FROM bbs_user WHERE id=1;(根据条件查询)

SELECT * FROM bbs_user WHERE address LIKE '%文字%';(模糊查询)

SELECT * FROM bbs_user WHERE age BETWEEN 30 AND 40;(取区间的值)

SELECT * FROM bbs_user WHERE age=20 OR age=40;(取多个值)

SELECT * FROM bbs_user WHERE age IN(18,19,20);(取多个值)

SELECT * FROM bbs_user ORDER BY age ASC;(升序)

SELECT * FROM bbs_user ORDER BY age DESC;(降序)

SELECT * FROM bbs_user LIMIT 0 , 5;(从第0条开始取5条数据)

SELECT * FROM bbs_user GROUP BY age;(分组)

SELECT COUNT(*) FROM bbs_user;(查询总条数)

9.内联表

SELECT username , gname FROM shop_user INNER JOIN shop_goods ON shop_user.gid = shop_goods.gid;(username , gname:字段名 shop_user ,shop_goods:表名称 shop_user.gid = shop_goods.gid:关联条件)

10.左连接

SELECT shop_user.username FROM shop_user LEFT JOIN shop_goods ON shop_user.gid = shop_goods.gid;

11.右连接 

SELECT shop_user.username FROM shop_user RIGHT JOIN shop_goods ON shop_user.gid = shop_goods.gid;

 

posted @ 2020-07-22 10:45  PromiseOne  阅读(165)  评论(0编辑  收藏  举报