MySQL 学习笔记 《一》

sql命令

DDL 数据定义

黑窗口登陆SQL服务: mysql -u<用户名> -p<密码>

退出SQL服务 : exit

查询该用户下所有的数据库 : show databases;

新建数据库 : create database <数据库名称>;

删除数据库 : drop database <数据库名称>;

进入/切换 数据库 : use <数据库名称>


查看该数据库下的 各种表 : show tables;

新建表结构 : create table <表名称>(item1 类型1,item2 类型2,,,,);

删除表结构 : drop table <表名称>;

查看表的数据 : desc <表名>;

增加表的数据:alter table <表名> add (item1 类型1,,,,);

修改表的数据:alter table <表名> modify item1 类型1 ;

删除表的数据:alter table <表名> drop item1;

表的重命名 : alter table <旧表名> rename to <新表名》;

SQL查询语句 :select * from <表名>;

 


DML 数据操作语言

SQL添加数据语句 :

          法一:insert into <表名> (item1 ,item2,,,,) value (type1,type2,,,,);

          法二:insert into <表名> (item1[部分]) value (type1[部分]);

          法三:insert into <表名> value (type1,type2,,,,);

SQL修改数据语句 :update <表名> set [条件] [where <条件>];

常用的条件:

          or 或者

          and 和

          is 是 注意:如果数据库中有NULL,这需要 is 进行限制

          = 等于

          != ,<> 不等于

          >= ,< = 大于(小于)等于

               between ,,, and ,,,     在,,,之间

               egg : update stu set age = 10 where age between 10 and 15

               解释:修改stu表中age在10-15之间的age 为10

          in (x,y) 包含x,y的集合

               egg : update stu set age = 10 where name in ('code','pchesscode')

               解释:修改stu表中name为code和pchesscode的age 为10


DCl 数据控制语句

增加用户: create user 用户名@IP identified by 密码;

ip 可以设置 localhost 如果为’%‘,则改用户默认全部ip

增加用户权限 ;grant all on 用户名@IP;

all 为全部权限

修改用户权限: revoke delete on 用户名@IP;

移除删除权限

查询用户权限: show grants for 用户名@IP;

删除用户 ; drop user 用户名@IP;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值